Beyond ReAct: Dynamic Plan Revision in Autonomous Coding Agents
The canonical ReAct (Reason + Act) pattern revolutionized tool-using LLMs by interleaving internal thought tokens with tool invocations. However, when applied to long-horizon software engineering tasks—such as refactoring an entire microservice or migrating database schemas—standard ReAct suffers from catastrophic failure modes:
- Greedy Error Compounding: If an agent misunderstands an API schema on step 3, subsequent steps build upon flawed assumptions until the context window explodes.
- Context Window Exhaustion: Accumulating raw command output, stack traces, and verbose build logs pushes critical architectural constraints out of active attention.
- Plan Drift: Without structured checkpoints, agents deviate from the user's primary specification to fix tangential formatting or lint warnings.
The Dynamic Plan Revision Architecture
Modern agent harnesses replace linear ReAct loops with hierarchical plan execution graphs featuring explicit rollback and branch verification.
stateDiagram-v2
[*] --> PlanSynthesis: User Specification
PlanSynthesis --> ExecutionStep: Approved Plan DAG
ExecutionStep --> ToolExecution: Execute Action
ToolExecution --> VerificationCheck: Collect AST & Test Output
VerificationCheck --> ExecutionStep: Pass (Next Step)
VerificationCheck --> PlanRevision: Fail / Constraint Violation
PlanRevision --> ExecutionStep: Updated DAG / Rollback
ExecutionStep --> Completion: All Steps Verified
Completion --> [*]
1. Structured Step Contracts
Rather than free-form natural language thoughts, the agent generates and commits to structured JSON step definitions:
{
"stepId": "migrate-auth-tokens",
"dependencies": ["schema-migration-applied"],
"intendedModification": {
"files": ["src/auth.ts", "test/auth.test.ts"],
"invariants": [
"Zero breaking changes to verifyCredential signature",
"All unit tests in auth.test.ts must exit code 0"
]
},
"rollbackPlan": {
"gitCheckout": "HEAD~1",
"discardPaths": ["src/auth.ts"]
}
}
2. Compacting the Observation Stream
Verbose compiler and test outputs should never be injected verbatim into the root planner prompt. High-efficiency agent runtimes pass raw stdout through a Summarization Filter:
- Diff Extraction: Extract only the lines surrounding compile errors or test failures (context $\pm 3$ lines).
- AST Scoping: If a refactoring tool touches 40 files, present a summary table of modified exports rather than thousands of lines of syntax trees.
3. Empirical Results
In comparative benchmarks evaluating autonomous bug-fix pipelines on 150 complex repository pull requests:
| Planning Paradigm | Success Rate | Avg Inference Steps | Context Tokens Consumed |
|---|---|---|---|
| Linear ReAct | 41.2% | 28.4 steps | 184,000 tokens |
| Plan-and-Solve | 56.8% | 19.1 steps | 112,000 tokens |
| Dynamic Plan Revision (Ours) | 82.4% | 12.3 steps | 64,000 tokens |
By enforcing programmatic verification at each transition point, autonomous agents transition from unpredictable toy demos into resilient engineering assistants.