# logic-star-ai/swe-star architecture

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

- Interactive diagram: https://gitdiagram.com/logic-star-ai/swe-star
- Repository: https://github.com/logic-star-ai/swe-star

## Overview

1. **What this repo is**
   SWE-Star is an end-to-end pipeline for producing, training, and evaluating agentic coding models. The main artifact is a large dataset of coding trajectories, then fine-tuned Qwen2.5-Coder-based models, and finally benchmark evaluation on SWE-Bench Verified.

2. **Top-level pipeline**
   The core flow is: **task generation / rollouts → trajectory storage → dataset curation → supervised fine-tuning → benchmark evaluation**. The repository is organized around those stages rather than around a single app service.

3. **Agent runtime**
   `uac/agent` is the execution boundary for interactive code-editing episodes. It contains:
   - the agent loop (`agent.py`)
   - environment abstraction (`environment.py`)
   - tool definitions (`tools.py`)
   - message/model/schema handling (`model.py`)
   - persistence and logging (`save.py`, `log.py`)
   - prompt templates (`templates/`)
   
   This layer is the “runtime” that talks to a model, executes tools, and records trajectories.

4. **Tool-using coding scaffold**
   The README describes an OpenHands-like scaffold with XML tool calling and tools such as `think`, `str_replace_editor`, `execute_bash`, and `submit`. That means the agent layer is not just text generation; it is a controlled, multi-step executor that can inspect and modify repositories during benchmark-style tasks.

5. **Data generation**
   `uac/generate` and `uac/experiments/*/generate.py` are responsible for producing trajectories under different settings. The `generate` package appears to be the general entry point, while the experiment folders contain variants such as teacher strength, issue type, multiple unrolls, and train-on-sympy. This is where raw agent rollouts are created before training.

6. **Training subsystem**
   `uac/train` contains the model fine-tuning layer. The presence of `trl.py`, `torchtune.py`, `split.py`, and a `zero_stage_3_config.json` indicates support for multiple training backends and distributed training setups. This layer likely consumes curated trajectory data and outputs tuned checkpoints for the SWE-Star family.

7. **Evaluation subsystem**
   `uac/eval` contains benchmark-specific evaluation code, including SWE-Bench and SWE-Bench-related variants. This is the downstream scoring boundary that compares generated patches/solutions against benchmark instances, separate from the agent rollout system.

8. **MN5 / SLURM operations layer**
   `uac/mn5` is the infrastructure control plane for MareNostrum 5. It includes:
   - dataset and model coordination
   - inference orchestration
   - scheduling
   - monitoring for `sglang` and `vllm`
   - Podman integration
   - Slack notifications
   - statistics, usage, and W&B integration
   
   This suggests the repo is designed for batch and cluster execution rather than local development alone.

9. **Containerization and cluster setup**
   `setup/podman` packages Podman binaries, systemd units, and helper components, and `setup/setup_podman.sh` likely bootstraps that environment on MN5 nodes. This is an important architectural boundary: runtime isolation and reproducibility are handled with Podman rather than ad hoc host installation.

10. **Experiment matrix**
   `uac/experiments` is a collection of ablations and research variants around the same core pipeline. Examples include:
   - cheating
   - major
   - rejection_sampling
   - student_family
   - teacher_strength
   - number_of_repos
   - r2e
   - train_on_input
   - train_on_sympy
   
   These are not separate products; they are controlled entry points into the shared generation/training/eval stack.

11. **Analysis and reporting**
   `uac/analysis/analyze_by_repo.py` provides post-hoc analysis over generated data or evaluation outputs, likely to break results down by repository or task source. This is the analytics boundary after training/evaluation.

12. **Tests and CI**
   `tests/` covers agent behavior, environment behavior, and tools. `workflows/lint.yaml` indicates repo-level quality checks. These tests likely protect the agent/tool interface and environment contract, which are the most failure-sensitive parts of the system.

13. **External dependencies that shape architecture**
   The repo is built around Hugging Face model/dataset workflows, SWE-Bench Verified, SLURM on MN5, and optional W&B/Slack operational hooks. The README also notes offline agent rollouts on MN5 and internet-enabled benchmark evaluation elsewhere, so network policy is a real architectural constraint.

Main entry points: [`uac/agent/agent.py`](https://github.com/logic-star-ai/swe-star/blob/master/uac/agent/agent.py) (Agent loop), [`uac/train/trl.py`](https://github.com/logic-star-ai/swe-star/blob/master/uac/train/trl.py) (Train), [`uac/generate/generate.py`](https://github.com/logic-star-ai/swe-star/blob/master/uac/generate/generate.py) (Generate), [`uac/experiments/utils.py`](https://github.com/logic-star-ai/swe-star/blob/master/uac/experiments/utils.py) (Experiments)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pipeline["Core pipeline"]
  node_generate["Generate<br/>trajectory entrypoint<br/>[generate.py]"]
  node_traj_smith["R2E flows<br/>generation adapters<br/>[r2e.py]"]
  node_trainer["Train<br/>fine-tuning entrypoint<br/>[trl.py]"]
  node_torchtune["Torchtune<br/>training backend<br/>[torchtune.py]"]
  node_split["Split data<br/>dataset prep<br/>[split.py]"]
  node_eval_core["Evaluate<br/>benchmark runner<br/>[eval.py]"]
  node_swebench["SWE-Bench<br/>benchmark adapter<br/>[swebench.py]"]
end

subgraph group_runtime["Agent runtime"]
  node_agent_loop["Agent loop<br/>episode runner<br/>[agent.py]"]
  node_environment["Environment<br/>exec boundary<br/>[environment.py]"]
  node_tools["Tools<br/>tooling<br/>[tools.py]"]
  node_model["Model I/O<br/>schema + prompts<br/>[model.py]"]
  node_persistence["Logs & save<br/>trajectory storage<br/>[log.py]"]
end

subgraph group_infra["MN5 ops"]
  node_mn5_sched["Schedule<br/>cluster orchestration<br/>[schedule.py]"]
  node_mn5_infer["Inference<br/>cluster runtime<br/>[inference.py]"]
  node_mn5_monitor["Monitoring<br/>ops telemetry<br/>[monitor_sglang.py]"]
  node_podman_setup["Podman setup<br/>runtime packaging<br/>[setup_podman.sh]"]
end

subgraph group_research["Experiments"]
  node_experiments["Experiments<br/>research variants<br/>[utils.py]"]
  node_analysis["Analysis<br/>posthoc reporting<br/>[analyze_by_repo.py]"]
end

subgraph group_quality["Validation"]
  node_tests["Tests<br/>validation suite<br/>[test_agent.py]"]
end

node_generate -->|"launches"| node_agent_loop
node_traj_smith -->|"specializes"| node_generate
node_agent_loop -->|"uses"| node_environment
node_agent_loop -->|"calls"| node_tools
node_agent_loop -->|"queries"| node_model
node_agent_loop -->|"records"| node_persistence
node_persistence -->|"feeds"| node_split
node_split -->|"prepares"| node_trainer
node_trainer -->|"backends"| node_torchtune
node_trainer -->|"outputs"| node_eval_core
node_eval_core -->|"adapts"| node_swebench
node_mn5_sched -->|"orchestrates"| node_generate
node_mn5_sched -->|"orchestrates"| node_trainer
node_mn5_infer -->|"serves"| node_generate
node_mn5_monitor -->|"watches"| node_mn5_infer
node_podman_setup -->|"enables"| node_mn5_sched
node_experiments -->|"variants"| node_generate
node_experiments -->|"variants"| node_trainer
node_experiments -->|"studies"| node_analysis
node_tests -->|"covers"| node_agent_loop
node_tests -->|"covers"| node_environment
node_tests -->|"covers"| node_tools

click node_generate "https://github.com/logic-star-ai/swe-star/blob/master/uac/generate/generate.py"
click node_traj_smith "https://github.com/logic-star-ai/swe-star/blob/master/uac/generate/r2e.py"
click node_agent_loop "https://github.com/logic-star-ai/swe-star/blob/master/uac/agent/agent.py"
click node_environment "https://github.com/logic-star-ai/swe-star/blob/master/uac/agent/environment.py"
click node_tools "https://github.com/logic-star-ai/swe-star/blob/master/uac/agent/tools.py"
click node_model "https://github.com/logic-star-ai/swe-star/blob/master/uac/agent/model.py"
click node_persistence "https://github.com/logic-star-ai/swe-star/blob/master/uac/agent/log.py"
click node_trainer "https://github.com/logic-star-ai/swe-star/blob/master/uac/train/trl.py"
click node_torchtune "https://github.com/logic-star-ai/swe-star/blob/master/uac/train/torchtune.py"
click node_split "https://github.com/logic-star-ai/swe-star/blob/master/uac/train/split.py"
click node_eval_core "https://github.com/logic-star-ai/swe-star/blob/master/uac/eval/eval.py"
click node_swebench "https://github.com/logic-star-ai/swe-star/blob/master/uac/eval/swebench.py"
click node_mn5_sched "https://github.com/logic-star-ai/swe-star/blob/master/uac/mn5/schedule.py"
click node_mn5_infer "https://github.com/logic-star-ai/swe-star/blob/master/uac/mn5/inference.py"
click node_mn5_monitor "https://github.com/logic-star-ai/swe-star/blob/master/uac/mn5/monitor_sglang.py"
click node_podman_setup "https://github.com/logic-star-ai/swe-star/blob/master/setup/setup_podman.sh"
click node_experiments "https://github.com/logic-star-ai/swe-star/blob/master/uac/experiments/utils.py"
click node_analysis "https://github.com/logic-star-ai/swe-star/blob/master/uac/analysis/analyze_by_repo.py"
click node_tests "https://github.com/logic-star-ai/swe-star/blob/master/tests/test_agent.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_generate,node_traj_smith,node_trainer,node_torchtune,node_split,node_eval_core,node_swebench toneBlue
class node_agent_loop,node_environment,node_tools,node_model,node_persistence toneAmber
class node_mn5_sched,node_mn5_infer,node_mn5_monitor,node_podman_setup toneMint
class node_experiments,node_analysis toneRose
class node_tests toneIndigo
```

## Components

### Core pipeline

End-to-end flow from data generation through training and evaluation.

- [Generate](https://github.com/logic-star-ai/swe-star/blob/master/uac/generate/generate.py): trajectory entrypoint · General trajectory generation entrypoint. · `uac/generate/generate.py`
- [R2E flows](https://github.com/logic-star-ai/swe-star/blob/master/uac/generate/r2e.py): generation adapters · Specialized generation paths for rollout variants. · `uac/generate/r2e.py`
- [Train](https://github.com/logic-star-ai/swe-star/blob/master/uac/train/trl.py): fine-tuning entrypoint · Orchestrates model fine-tuning workflows for SWE-Star variants. · `uac/train/trl.py`
- [Torchtune](https://github.com/logic-star-ai/swe-star/blob/master/uac/train/torchtune.py): training backend · Training backend integration for checkpoint fine-tuning. · `uac/train/torchtune.py`
- [Split data](https://github.com/logic-star-ai/swe-star/blob/master/uac/train/split.py): dataset prep · Dataset splitting and preparation for training/evaluation. · `uac/train/split.py`
- [Evaluate](https://github.com/logic-star-ai/swe-star/blob/master/uac/eval/eval.py): benchmark runner · Evaluation entrypoint for benchmark scoring. · `uac/eval/eval.py`
- [SWE-Bench](https://github.com/logic-star-ai/swe-star/blob/master/uac/eval/swebench.py): benchmark adapter · SWE-Bench-specific evaluation logic. · `uac/eval/swebench.py`

### Agent runtime

Interactive coding episode execution, tools, and persistence.

- [Agent loop](https://github.com/logic-star-ai/swe-star/blob/master/uac/agent/agent.py): episode runner · Coordinates model turns, tool use, and environment interaction. · `uac/agent/agent.py`
- [Environment](https://github.com/logic-star-ai/swe-star/blob/master/uac/agent/environment.py): exec boundary · Abstraction over the editable repository and task environment. · `uac/agent/environment.py`
- [Tools](https://github.com/logic-star-ai/swe-star/blob/master/uac/agent/tools.py): tooling · Tool definitions such as edit, shell, think, and submit. · `uac/agent/tools.py`
- [Model I/O](https://github.com/logic-star-ai/swe-star/blob/master/uac/agent/model.py): schema + prompts · Message, schema, and prompt/template handling for agent calls. · `uac/agent/model.py`
- [Logs & save](https://github.com/logic-star-ai/swe-star/blob/master/uac/agent/log.py): trajectory storage · Logging and persistence of agent traces and artifacts. · `uac/agent/log.py`

### MN5 ops

Cluster execution, orchestration, and environment setup.

- [Schedule](https://github.com/logic-star-ai/swe-star/blob/master/uac/mn5/schedule.py): cluster orchestration · Batch scheduling and job coordination on MN5. · `uac/mn5/schedule.py`
- [Inference](https://github.com/logic-star-ai/swe-star/blob/master/uac/mn5/inference.py): cluster runtime · Inference orchestration for large-model serving and rollouts. · `uac/mn5/inference.py`
- [Monitoring](https://github.com/logic-star-ai/swe-star/blob/master/uac/mn5/monitor_sglang.py): ops telemetry · Monitoring for serving stacks and operational status. · `uac/mn5/monitor_sglang.py`
- [Podman setup](https://github.com/logic-star-ai/swe-star/blob/master/setup/setup_podman.sh): runtime packaging · Container runtime packaging and bootstrap for reproducible cluster execution. · `setup/setup_podman.sh`

### Experiments

Ablations and variants built on the shared pipeline.

- [Experiments](https://github.com/logic-star-ai/swe-star/blob/master/uac/experiments/utils.py): research variants · Shared entrypoint group for ablations and research variants. · `uac/experiments/utils.py`
- [Analysis](https://github.com/logic-star-ai/swe-star/blob/master/uac/analysis/analyze_by_repo.py): posthoc reporting · Repository-level analysis of generated data and outcomes. · `uac/analysis/analyze_by_repo.py`

### Validation

Tests and repository checks.

- [Tests](https://github.com/logic-star-ai/swe-star/blob/master/tests/test_agent.py): validation suite · Coverage for agent, environment, and tools contracts. · `tests/test_agent.py`

## Connections

- Generate → Agent loop: launches · Generation starts agent rollouts.
- R2E flows → Generate: specializes · Variant generation paths feed the shared generator.
- Agent loop → Environment: uses · The agent acts inside the environment boundary.
- Agent loop → Tools: calls · Agent decisions are executed through tools.
- Agent loop → Model I/O: queries · The loop formats prompts and model messages.
- Agent loop → Logs & save: records · Episodes are logged and saved as trajectories.
- Logs & save → Split data: feeds · Saved trajectories are curated and split for training.
- Split data → Train: prepares · Prepared datasets are consumed by training.
- Train → Torchtune: backends · Training can run through multiple backend implementations.
- Train → Evaluate: outputs · Tuned checkpoints proceed to evaluation.
- Evaluate → SWE-Bench: adapts · Benchmark-specific scoring is handled by SWE-Bench logic.
- Schedule → Generate: orchestrates · Cluster jobs run generation at scale.
- Schedule → Train: orchestrates · Cluster jobs run training at scale.
- Inference → Generate: serves · Inference serving supports rollout and rollout-like workflows.
- Monitoring → Inference: watches · Operational telemetry tracks serving health.
- Podman setup → Schedule: enables · Containerized runtime setup supports cluster execution.
- Experiments → Generate: variants · Research variants reuse the shared generation stack.
- Experiments → Train: variants · Research variants reuse the shared training stack.
- Experiments → Analysis: studies · Experiment code feeds post-hoc analysis.
- Tests → Agent loop: covers · Tests protect the agent loop contract.
- Tests → Environment: covers · Tests protect environment behavior.
- Tests → Tools: covers · Tests protect tool semantics.
