SWE Agentic RL#
This recipe trains a policy to solve software-engineering tasks with mini-SWE-agent, Docker sandboxes, fresh-container grading, and PSRL’s asynchronous GRPO/DAPO training path.
This recipe treats mini-SWE-agent as a black-box agent: it uses its normal Python bindings and OpenAI-compatible model client, which talks to PSRL through a session-scoped OpenAI endpoint served by SessionRouter.
Current Runtime Path#
sequenceDiagram
participant ALW as AgentLoopWorker
participant MSL as MiniSWEAgentLoopV1
participant SR as SessionRouter
participant SMG as SMG TITO
participant V as vLLM
participant A as miniSWEagent
participant D as Docker sandbox
participant G as Fresh grader container
participant TQ as TransferQueue
ALW->>MSL: run(request)
MSL->>SR: create TITO session and routing headers
MSL->>A: run_agent(session-scoped API URL)
A->>D: inspect, edit, and test repository
A->>SR: OpenAI chat completion
SR->>SMG: session request
SMG->>V: route generation
V-->>A: assistant turn
Note over A,D: repeat until submit / max turns / timeout
MSL->>G: apply patch and execute F2P/P2P tests
MSL->>SR: fetch TITO session
SR-->>MSL: tokens, masks, logprobs, turn records
MSL->>TQ: finalized trajectory, patch, grader result
MSL->>SR: delete session
Per episode:
MiniSWEEnvironment.reset()validates dataset metadata and builds the per-problem sandbox configuration.MiniSWEAgentLoopV1creates one SessionRouter/TITO session containing request, prompt, trajectory, validation, and model-version metadata.examples/mini_swe/runner.pystarts mini-SWE-agent in a worker thread. The agent owns its Docker interaction loop and calls the session-scoped OpenAI endpoint.SessionRouter pins later turns to the selected rollout instance. SMG TITO records exact model-side training data while requests pass through vLLM.
After submission, the runner grades the patch in a fresh container when
swe_grader=swebench_fresh_container.The loop fetches TITO once, builds
prompt_ids,response_ids,response_mask, rollout log-probabilities, and optional routed-expert tensors, then writes the finalized trajectory to TransferQueue.
The environment’s command outputs are included in response_ids with mask 0, while
assistant-generated tokens use mask 1. This preserves the full multi-turn context
while training only on policy tokens.
Supported Data Paths#
Path |
Dataset |
Sandbox |
Grading |
|---|---|---|---|
SWE-smith-py |
|
Per-problem |
Fresh container, generated F2P/P2P test spec |
SWE-Gym |
|
Per-problem |
Fresh container, dataset-provided eval script |
SWE-bench Verified |
|
Per-problem SWE-bench image |
Fresh container, usually used for validation |
Warning
The current MiniSWEEnvironment requires swe_grader, swe_problem, and
swe_problem_image in every row. prepare_simple_data.py does not currently emit
that contract, so the toy launch path is not a valid end-to-end path until its
dataset schema or environment handling is updated.
Main Components#
Component |
Responsibility |
|---|---|
|
Owns SessionRouter/TITO lifecycle and converts the black-box run into a PSRL trajectory |
|
Parses parquet metadata, applies per-instance overrides, and performs safety-net Docker cleanup |
|
Runs mini-SWE-agent through standard Python bindings and invokes fresh grading |
|
Preserves PSRL headers, session affinity, and session close/drain semantics |
SMG TITO |
Captures canonical model-side tokens, log-probabilities, masks, and turn boundaries |
|
Adds patch, grader result, turn count, and resolve-rate metadata |
|
Converts grader output into binary or shaped training rewards |
Reward Semantics#
For SWE-smith, SWE-Gym, and Verified, grading uses a clean container created from the same per-problem image:
Apply the submitted patch.
Reject policy-violating changes when configured by the grader.
Run FAIL_TO_PASS and PASS_TO_PASS tests.
Attach the structured grader result to the trajectory.
compute_score supports binary, partial_credit, test_ratio, and shaped
reward modes. acc is always the binary resolve indicator and should be used as the
primary evaluation metric.