How yashkasare21/auto-swe-agent works
1. What this repo is:
auto-swe-agent is an autonomous software-engineering system that takes a natural-language issue, inspects a workspace, edits code, and verifies the fix by running tests. The architecture is centered around an iterative LLM-driven loop rather than a traditional request/response app.
2. Core control loop:
agent.py is the main orchestration entrypoint. It wires together the planner/executor cycle described in the README: the model plans the next step, calls tools, observes results, and repeats until the task is done or a limit is hit. The agents/ package suggests the loop is split into role-specific components such as planner, coder, reviewer, and manager, with shared abstractions in agents/base.py.
3. LLM and decision-making boundary:
The system uses LiteLLM as the model-routing layer, with fallback across multiple providers/models. This means the architecture is designed to tolerate API failures and rate limits while keeping the same agent interface. The planner is the main reasoning component; other modules appear to support decomposition, review, and coordination.
4. Tool execution boundary:
The agent does not directly manipulate the host environment. Instead, it uses tools for file reading, search, writing, and shell execution. That tool boundary is important for the diagram because it separates “reasoning” from “actions” and defines where side effects occur.
5. Sandbox and runtime isolation:
All bash commands run inside a Docker sandbox. The repo includes a top-level Dockerfile and a separate ui/Dockerfile, indicating containerized execution is a first-class architectural boundary. The sandbox is volume-mounted to the workspace, so the agent can change files and run tests without executing on the host machine.
6. Verification and feedback loop:
The agent’s work is validated through tests, typically pytest. The loop is explicitly closed by running tests after edits and feeding failures back into the planner. There is also a hallucination guard and context trimming, which are part of the control flow that keeps the agent grounded and within token limits.
7. Evaluation harness:
eval/run_eval.py is a separate subsystem for running golden tasks end-to-end. It resets the workspace to known buggy states, launches the agent as a subprocess, and records results. This makes evaluation an orchestrated pipeline: setup → agent run → test verification → JSON/report output.
8. Target codebases used in eval:
The main.py / test_main.py pair represents a small sample application, likely used as a simple bug-fix target. The docstream/ package is another embedded target project, with core PDF-extraction/generation logic and tests. One eval case specifically targets password-protected PDF handling in docstream, so this repo is not just the agent itself; it also bundles the workloads the agent is expected to repair.
9. Search and indexing subsystem:
The indexing/ package (parser.py, embedder.py, vector_store.py, build_index.py) forms a retrieval layer over code or documents. tools/semantic_search.py likely exposes that index to the agent. Architecturally, this is the repository’s retrieval path: parse content → embed it → store vectors → search when the agent needs relevant context.
10. Reliability and resilience helpers:
resilience/ contains retry and circuit-breaker logic, which matters because the system depends on external APIs and sandboxed execution. These wrappers likely protect model calls, tool calls, or both from transient failures, and they support the multi-model fallback behavior described in the README.
11. Observability and cost tracking:
tracking/cost_tracker.py and scripts like scripts/cost_report.py and scripts/resilience_report.py indicate that the repo measures runtime behavior, especially LLM usage and failure patterns. This is a supporting subsystem for operational visibility rather than core agent logic.
12. Optional UI layer:
The ui/ package is a separate visualization surface, not the execution engine. Components like agent_graph.py, diff_viewer.py, and cost_chart.py suggest it renders the agent state, code changes, and cost metrics. ui/state_manager.py likely bridges runtime data into the interface, making the UI a consumer of agent telemetry rather than a control plane.
13. Testing structure:
Tests exist at multiple layers: repository-level tests for the agent flow, docstream tests for the embedded target library, and eval-specific checks. That tells you the architecture validates both the agent infrastructure and the example codebases it is meant to repair.
14. High-level data flow to draw:
Natural-language issue enters the agent → planner selects next action → tools read/search/edit the workspace or run sandboxed commands → test feedback returns from Docker → planner iterates until success → evaluation/reporting/UI components consume logs, diffs, and cost data. The key boundaries are: model reasoning, tool execution, sandbox isolation, retrieval/indexing, and reporting/visualization.
Main entry points: agent.py Agent loop · app.py UI app · manager.py Manager · run_eval.py Eval runner
Components 23
Agent core
LLM-driven planning, role coordination, and action loop.
- Agent loop · Main entrypoint that runs the iterative plan-act-observe cycle.
agent.py - Agent base · Shared interfaces and common agent behaviors.
agents/base.py - Planner · Chooses the next step and drives the fix loop.
agents/planner.py - Coder · Produces code changes and workspace edits.
agents/coder.py - Reviewer · Checks proposed changes and likely failure modes.
agents/reviewer.py - Manager · Coordinates roles and closes the loop.
agents/manager.py
Execution tools
Workspace actions, search, and git operations exposed to the agent.
- Semantic search · Exposes indexed context to the agent.
tools/semantic_search.py - Git tools · Repository and diff operations for agent workflows.
tools/git_tools.py
Runtime safety
Sandboxing, retries, and failure-handling around external calls.
- Retry · Retries transient failures from APIs or tools.
resilience/retry.py - Circuit breaker · Stops repeated failing calls from cascading.
resilience/circuit_breaker.py
Retrieval
Indexing and semantic search over repository content.
- Build index · Coordinates indexing over repository content.
indexing/build_index.py - Parser · Extracts structured text from source files.
indexing/parser.py - Embedder · Converts parsed content into vectors.
indexing/embedder.py - Vector store · Persists and queries embeddings for search.
indexing/vector_store.py
Evaluation
End-to-end harness that runs tasks and captures results.
- Eval runner · Resets tasks, launches the agent, and records outcomes.
eval/run_eval.py
Target workloads
Embedded example applications and their tests.
- Docstream core · Embedded PDF extraction and generation workload.
docstream/core/generator.py - Sample app · Small bug-fix target used by tests and evals.
main.py
UI
Optional visualization layer for agent state and telemetry.
- UI app · Launches the agent dashboard and state views.
ui/app.py - State manager · Bridges runtime data into the UI.
ui/state_manager.py - Agent graph · Visualizes agent structure and execution state.
ui/components/agent_graph.py - Diff viewer · Displays code changes produced by the agent.
ui/components/diff_viewer.py - Cost chart · Renders cost and usage telemetry.
ui/components/cost_chart.py
Observability
Cost and resilience tracking plus reporting scripts.
- Cost tracker · Tracks LLM usage and runtime cost.
tracking/cost_tracker.py
Connections 27
- Agent loop → Manager: runs · Entrypoint delegates orchestration to the manager.
- Manager → Planner: plans · Manager asks planner for the next action.
- Manager → Coder: edits · Manager routes implementation work to coder.
- Manager → Reviewer: reviews · Manager requests critique and validation.
- Planner → Agent base: extends · Planner uses shared agent abstractions.
- Coder → Agent base: extends · Coder uses shared agent abstractions.
- Reviewer → Agent base: extends · Reviewer uses shared agent abstractions.
- Agent loop → Semantic search: retrieves · Agent consults semantic search for relevant context.
- Agent loop → Git tools: acts · Agent uses git/workspace tools to inspect or modify files.
- Semantic search → Vector store: queries · Search tool reads from the vector store.
- Build index → Parser: parses · Indexing starts by parsing repository content.
- Build index → Embedder: embeds · Parsed content is converted into embeddings.
- Build index → Vector store: stores · Built vectors are written to the store.
- Embedder → Vector store: indexes · Embeddings feed retrieval storage.
- Agent loop → Retry: wraps · External calls are retried on transient failure.
- Agent loop → Circuit breaker: guards · Repeated failures are isolated by circuit breaking.
- Agent loop → Eval runner: evaluated by · Evaluation harness launches the agent end to end.
- Eval runner → Sample app: targets · Eval can operate on the sample application.
- Eval runner → Docstream core: targets · Eval can operate on the embedded docstream workload.
- Eval runner → Cost tracker: records · Evaluation captures cost and runtime metrics.
- UI app → State manager: consumes · UI reads structured runtime state.
- State manager → Cost tracker: reads · UI state uses telemetry and cost data.
- UI app → Agent graph: renders · Dashboard shows agent topology and progress.
- UI app → Diff viewer: renders · Dashboard shows code diffs and edits.
- UI app → Cost chart: renders · Dashboard shows cost charts.
- Cost tracker → Cost chart: feeds · Telemetry powers cost visualization.
- Agent loop → Cost tracker: logs · Agent execution emits cost and usage data.