# yashkasare21/auto-swe-agent architecture

> Architecture diagram of the GitHub repository yashkasare21/auto-swe-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yashkasare21/auto-swe-agent
- Repository: https://github.com/yashkasare21/auto-swe-agent

## Overview

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`](https://github.com/yashkasare21/auto-swe-agent/blob/main/agent.py) (Agent loop), [`ui/app.py`](https://github.com/yashkasare21/auto-swe-agent/blob/main/ui/app.py) (UI app), [`agents/manager.py`](https://github.com/yashkasare21/auto-swe-agent/blob/main/agents/manager.py) (Manager), [`eval/run_eval.py`](https://github.com/yashkasare21/auto-swe-agent/blob/main/eval/run_eval.py) (Eval runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_agent["Agent core"]
  node_agent_py["Agent loop<br/>orchestrator<br/>[agent.py]"]
  node_agents_base["Agent base<br/>abstract agent<br/>[base.py]"]
  node_agents_planner["Planner<br/>reasoning agent<br/>[planner.py]"]
  node_agents_coder["Coder<br/>edit agent<br/>[coder.py]"]
  node_agents_reviewer["Reviewer<br/>review agent<br/>[reviewer.py]"]
  node_agents_manager["Manager<br/>coordination agent<br/>[manager.py]"]
end

subgraph group_group_tools["Execution tools"]
  node_tools_semantic_search["Semantic search<br/>retrieval tool<br/>[semantic_search.py]"]
  node_tools_git_tools["Git tools<br/>workspace tool<br/>[git_tools.py]"]
end

subgraph group_group_runtime["Runtime safety"]
  node_resilience_retry["Retry<br/>fault tolerance<br/>[retry.py]"]
  node_resilience_cb["Circuit breaker<br/>fault tolerance<br/>[circuit_breaker.py]"]
end

subgraph group_group_index["Retrieval"]
  node_index_build["Build index<br/>index pipeline<br/>[build_index.py]"]
  node_index_parser["Parser<br/>[parser.py]"]
  node_index_embedder["Embedder<br/>[embedder.py]"]
  node_index_store["Vector store<br/>retrieval store<br/>[vector_store.py]"]
end

subgraph group_group_eval["Evaluation"]
  node_eval_run["Eval runner<br/>evaluation pipeline<br/>[run_eval.py]"]
end

subgraph group_group_targets["Target workloads"]
  node_docstream_core["Docstream core<br/>target library<br/>[generator.py]"]
  node_main_app["Sample app<br/>target app<br/>[main.py]"]
end

subgraph group_group_ui["UI"]
  node_ui_app["UI app<br/>visualization<br/>[app.py]"]
  node_ui_state["State manager<br/>ui state<br/>[state_manager.py]"]
  node_ui_graph["Agent graph<br/>ui component<br/>[agent_graph.py]"]
  node_ui_diff["Diff viewer<br/>ui component<br/>[diff_viewer.py]"]
  node_ui_cost["Cost chart<br/>ui component<br/>[cost_chart.py]"]
end

subgraph group_group_obs["Observability"]
  node_tracking_cost["Cost tracker<br/>telemetry<br/>[cost_tracker.py]"]
end

node_agent_py -->|"runs"| node_agents_manager
node_agents_manager -->|"plans"| node_agents_planner
node_agents_manager -->|"edits"| node_agents_coder
node_agents_manager -->|"reviews"| node_agents_reviewer
node_agents_planner -->|"extends"| node_agents_base
node_agents_coder -->|"extends"| node_agents_base
node_agents_reviewer -->|"extends"| node_agents_base
node_agent_py -->|"retrieves"| node_tools_semantic_search
node_agent_py -->|"acts"| node_tools_git_tools
node_tools_semantic_search -->|"queries"| node_index_store
node_index_build -->|"parses"| node_index_parser
node_index_build -->|"embeds"| node_index_embedder
node_index_build -->|"stores"| node_index_store
node_index_embedder -->|"indexes"| node_index_store
node_agent_py -->|"wraps"| node_resilience_retry
node_agent_py -->|"guards"| node_resilience_cb
node_agent_py -->|"evaluated by"| node_eval_run
node_eval_run -->|"targets"| node_main_app
node_eval_run -->|"targets"| node_docstream_core
node_eval_run -->|"records"| node_tracking_cost
node_ui_app -->|"consumes"| node_ui_state
node_ui_state -->|"reads"| node_tracking_cost
node_ui_app -->|"renders"| node_ui_graph
node_ui_app -->|"renders"| node_ui_diff
node_ui_app -->|"renders"| node_ui_cost
node_tracking_cost -->|"feeds"| node_ui_cost
node_agent_py -->|"logs"| node_tracking_cost

click node_agent_py "https://github.com/yashkasare21/auto-swe-agent/blob/main/agent.py"
click node_agents_base "https://github.com/yashkasare21/auto-swe-agent/blob/main/agents/base.py"
click node_agents_planner "https://github.com/yashkasare21/auto-swe-agent/blob/main/agents/planner.py"
click node_agents_coder "https://github.com/yashkasare21/auto-swe-agent/blob/main/agents/coder.py"
click node_agents_reviewer "https://github.com/yashkasare21/auto-swe-agent/blob/main/agents/reviewer.py"
click node_agents_manager "https://github.com/yashkasare21/auto-swe-agent/blob/main/agents/manager.py"
click node_tools_semantic_search "https://github.com/yashkasare21/auto-swe-agent/blob/main/tools/semantic_search.py"
click node_tools_git_tools "https://github.com/yashkasare21/auto-swe-agent/blob/main/tools/git_tools.py"
click node_resilience_retry "https://github.com/yashkasare21/auto-swe-agent/blob/main/resilience/retry.py"
click node_resilience_cb "https://github.com/yashkasare21/auto-swe-agent/blob/main/resilience/circuit_breaker.py"
click node_index_build "https://github.com/yashkasare21/auto-swe-agent/blob/main/indexing/build_index.py"
click node_index_parser "https://github.com/yashkasare21/auto-swe-agent/blob/main/indexing/parser.py"
click node_index_embedder "https://github.com/yashkasare21/auto-swe-agent/blob/main/indexing/embedder.py"
click node_index_store "https://github.com/yashkasare21/auto-swe-agent/blob/main/indexing/vector_store.py"
click node_eval_run "https://github.com/yashkasare21/auto-swe-agent/blob/main/eval/run_eval.py"
click node_docstream_core "https://github.com/yashkasare21/auto-swe-agent/blob/main/docstream/core/generator.py"
click node_main_app "https://github.com/yashkasare21/auto-swe-agent/blob/main/main.py"
click node_tracking_cost "https://github.com/yashkasare21/auto-swe-agent/blob/main/tracking/cost_tracker.py"
click node_ui_app "https://github.com/yashkasare21/auto-swe-agent/blob/main/ui/app.py"
click node_ui_state "https://github.com/yashkasare21/auto-swe-agent/blob/main/ui/state_manager.py"
click node_ui_graph "https://github.com/yashkasare21/auto-swe-agent/blob/main/ui/components/agent_graph.py"
click node_ui_diff "https://github.com/yashkasare21/auto-swe-agent/blob/main/ui/components/diff_viewer.py"
click node_ui_cost "https://github.com/yashkasare21/auto-swe-agent/blob/main/ui/components/cost_chart.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_agent_py,node_agents_base,node_agents_planner,node_agents_coder,node_agents_reviewer,node_agents_manager,node_ui_app,node_ui_state,node_ui_graph,node_ui_diff,node_ui_cost toneBlue
class node_tools_semantic_search,node_tools_git_tools,node_tracking_cost toneAmber
class node_resilience_retry,node_resilience_cb toneMint
class node_index_build,node_index_parser,node_index_embedder,node_index_store toneRose
class node_eval_run toneIndigo
class node_docstream_core,node_main_app toneTeal
```

## Components

### Agent core

LLM-driven planning, role coordination, and action loop.

- [Agent loop](https://github.com/yashkasare21/auto-swe-agent/blob/main/agent.py): orchestrator · Main entrypoint that runs the iterative plan-act-observe cycle. · `agent.py`
- [Agent base](https://github.com/yashkasare21/auto-swe-agent/blob/main/agents/base.py): abstract agent · Shared interfaces and common agent behaviors. · `agents/base.py`
- [Planner](https://github.com/yashkasare21/auto-swe-agent/blob/main/agents/planner.py): reasoning agent · Chooses the next step and drives the fix loop. · `agents/planner.py`
- [Coder](https://github.com/yashkasare21/auto-swe-agent/blob/main/agents/coder.py): edit agent · Produces code changes and workspace edits. · `agents/coder.py`
- [Reviewer](https://github.com/yashkasare21/auto-swe-agent/blob/main/agents/reviewer.py): review agent · Checks proposed changes and likely failure modes. · `agents/reviewer.py`
- [Manager](https://github.com/yashkasare21/auto-swe-agent/blob/main/agents/manager.py): coordination agent · Coordinates roles and closes the loop. · `agents/manager.py`

### Execution tools

Workspace actions, search, and git operations exposed to the agent.

- [Semantic search](https://github.com/yashkasare21/auto-swe-agent/blob/main/tools/semantic_search.py): retrieval tool · Exposes indexed context to the agent. · `tools/semantic_search.py`
- [Git tools](https://github.com/yashkasare21/auto-swe-agent/blob/main/tools/git_tools.py): workspace tool · Repository and diff operations for agent workflows. · `tools/git_tools.py`

### Runtime safety

Sandboxing, retries, and failure-handling around external calls.

- [Retry](https://github.com/yashkasare21/auto-swe-agent/blob/main/resilience/retry.py): fault tolerance · Retries transient failures from APIs or tools. · `resilience/retry.py`
- [Circuit breaker](https://github.com/yashkasare21/auto-swe-agent/blob/main/resilience/circuit_breaker.py): fault tolerance · Stops repeated failing calls from cascading. · `resilience/circuit_breaker.py`

### Retrieval

Indexing and semantic search over repository content.

- [Build index](https://github.com/yashkasare21/auto-swe-agent/blob/main/indexing/build_index.py): index pipeline · Coordinates indexing over repository content. · `indexing/build_index.py`
- [Parser](https://github.com/yashkasare21/auto-swe-agent/blob/main/indexing/parser.py): content parser · Extracts structured text from source files. · `indexing/parser.py`
- [Embedder](https://github.com/yashkasare21/auto-swe-agent/blob/main/indexing/embedder.py): vector embedder · Converts parsed content into vectors. · `indexing/embedder.py`
- [Vector store](https://github.com/yashkasare21/auto-swe-agent/blob/main/indexing/vector_store.py): retrieval store · Persists and queries embeddings for search. · `indexing/vector_store.py`

### Evaluation

End-to-end harness that runs tasks and captures results.

- [Eval runner](https://github.com/yashkasare21/auto-swe-agent/blob/main/eval/run_eval.py): evaluation pipeline · Resets tasks, launches the agent, and records outcomes. · `eval/run_eval.py`

### Target workloads

Embedded example applications and their tests.

- [Docstream core](https://github.com/yashkasare21/auto-swe-agent/blob/main/docstream/core/generator.py): target library · Embedded PDF extraction and generation workload. · `docstream/core/generator.py`
- [Sample app](https://github.com/yashkasare21/auto-swe-agent/blob/main/main.py): target app · Small bug-fix target used by tests and evals. · `main.py`

### UI

Optional visualization layer for agent state and telemetry.

- [UI app](https://github.com/yashkasare21/auto-swe-agent/blob/main/ui/app.py): visualization · Launches the agent dashboard and state views. · `ui/app.py`
- [State manager](https://github.com/yashkasare21/auto-swe-agent/blob/main/ui/state_manager.py): ui state · Bridges runtime data into the UI. · `ui/state_manager.py`
- [Agent graph](https://github.com/yashkasare21/auto-swe-agent/blob/main/ui/components/agent_graph.py): ui component · Visualizes agent structure and execution state. · `ui/components/agent_graph.py`
- [Diff viewer](https://github.com/yashkasare21/auto-swe-agent/blob/main/ui/components/diff_viewer.py): ui component · Displays code changes produced by the agent. · `ui/components/diff_viewer.py`
- [Cost chart](https://github.com/yashkasare21/auto-swe-agent/blob/main/ui/components/cost_chart.py): ui component · Renders cost and usage telemetry. · `ui/components/cost_chart.py`

### Observability

Cost and resilience tracking plus reporting scripts.

- [Cost tracker](https://github.com/yashkasare21/auto-swe-agent/blob/main/tracking/cost_tracker.py): telemetry · Tracks LLM usage and runtime cost. · `tracking/cost_tracker.py`

## Connections

- 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.
