Agent Architecture Beyond Patch-Style Debugging: Small Models for Strategy, Large Models for Code

    When LLM-based agents get stuck in endless patch-fix loops, the root cause is often path dependency rather than coding ability. This article explains an agent architecture that separates strategy generation from code implementation: a small, low-cost model proposes directions while a larger coding model implements them. It covers shared search state, online policy learning with UCB-style bandits and memory-based experience, a propose-execute-evaluate-feedback loop, skill management, and evaluation practices—plus practical advice for adopting the architecture incrementally.

    Agent Architecture Beyond Patch-Style Debugging: Small Models for Strategy, Large Models for Code

    1. Why Patching Code Alone Rarely Breaks Through

    When large models are used to write code autonomously or complete research-style tasks, a common failure mode appears. After hitting an error, the model keeps patching the current approach—fixing one issue, then another—until local errors disappear, yet the overall solution still doesn’t work. The problem is that the model rarely steps back to check whether the original approach was sound in the first place. This phenomenon can be called path dependency. It causes the system to pour compute into local optimization without making structural progress.

    To escape this trap, the system needs a dedicated decision-making stage. This stage judges whether the current direction is worth pursuing and, when necessary, proposes an entirely different algorithm or architecture.

    2. Role Separation: Strategy Generation vs. Code Implementation

    A practical approach is to split the agent into two roles.

    The strategy role analyzes task goals, the current implementation, and historical experiment results, identifies capability gaps, and proposes candidate plans for the next step. The implementation role turns plans into code, handles debugging and testing, and produces quantifiable execution results.

    This division offers three benefits. First, the strategy role doesn’t need to wade through code details, so it can run on a smaller, cheaper model—high-frequency calls stay affordable. Second, the implementation role focuses purely on code correctness, so it can use a larger model that excels at programming. Third, the two roles are connected through structured feedback, so each round of experiments informs the next round of decisions.

    This division depends on clean interfaces. The strategy role’s output should be structured—for example, including a method description, expected benefits, dependencies, and risks. If the output is just free text, the implementation role struggles to interpret intent accurately, and feedback can’t be reused in later rounds.

    3. Shared Search State: A Unified Experiment Archive

    The biggest risk in multi-round experimentation is scattered information. If every call starts from scratch, the system will repeatedly retry directions that already failed. The solution is to maintain a shared search state so all decisions are based on the same record.

    A practical search state typically includes:

    1. Candidate versions already tried, with code summaries;
    2. Evolutionary relationships between versions—i.e., which parent version each version was modified from;
    3. Metrics, success/failure flags, and failure reasons for each experiment;
    4. A list of unexplored directions;
    5. Remaining compute or time budget.

    With this archive, the system can answer several key questions: Which historical version should we continue optimizing from? Should we deepen the current method or pivot to a new direction? How many more attempts can the remaining budget support?

    An illustrative data structure:

    1. state = {
    2. "candidates": [{"id": "v3", "parent": "v1", "score": 0.72, "status": "ok"}],
    3. "frontier": ["replace search strategy", "introduce caching"],
    4. "budget_left": 14
    5. }

    4. Online Policy Learning: Adjusting Decisions from Historical Results

    The policy shouldn’t be a fixed set of rules. As experiments accumulate, the system should gradually learn which directions are worth the investment. This can combine two complementary methods.

    The first is confidence-interval-based selection. UCB-style algorithms represent the multi-armed bandit approach: they consider both an action’s average reward and its uncertainty. Directions tried fewer times have higher uncertainty and get more exploration opportunities; directions repeatedly validated with stable results are preferentially exploited. KL-UCB is a variant that uses KL divergence to characterize distributional differences, providing tighter confidence bounds in certain settings. These methods give a computable basis for the question “is this worth another try?”

    The second is memory-based policy learning. The system distills successful or failed experiments into experience entries. Each entry records not only whether a method worked, but also its applicable conditions and concrete recommendations. For example, an entry might state: when data volume is small and latency sensitivity is high, this method works; if concurrency exceeds a certain threshold, abandon it. As new experiments complete, entries can be reinforced, revised, or retired when their conditions no longer hold. The experience base thus stays aligned with reality.

    The two mechanisms can be combined. Statistical methods quantify uncertainty; memory methods inject domain knowledge. Together they constrain the candidate set available to the strategy role.

    5. Research Workflow: A Closed Loop of Proposal, Execution, and Feedback

    When local patching can’t deliver a breakthrough, the system needs to enter a structural improvement process. A typical loop has four stages:

    1. Proposal: the strategy role examines bottlenecks in the current implementation and generates a concrete, verifiable new plan;
    2. Execution: the implementation role writes code according to the plan and runs unit tests and benchmark tasks;
    3. Evaluation: metric changes are recorded to determine whether the new plan outperforms its parent version;
    4. Feedback: success factors and failure reasons are written back to the shared state and experience base.

    In pseudocode:

    1. while budget_left > 0:
    2. parent = select_parent(state, bandit)
    3. idea = proposer.propose(state, parent, memory)
    4. code, result = worker.implement_and_test(idea, parent)
    5. state.record(idea, code, result)
    6. memory.update(idea, result)
    7. budget_left -= cost(result)

    Two engineering points matter here. First, selecting the parent version and selecting the improvement direction are two independent decisions; designing them separately makes problems easier to locate. Second, every round must write back to the state—otherwise the feedback chain breaks and the system degenerates into one-shot calls.

    6. Experience and Skill Management

    What accumulates during implementation goes beyond experiment data. Reusable code modules, troubleshooting steps for common errors, and configuration notes for specific frameworks are all worth distilling into skill entries. When managing these assets, three things matter.

    First, annotate the applicable scope. Code that works on one type of data may not work elsewhere. Every skill should carry its preconditions.

    Second, keep failure records. Failed attempts help the system avoid repeating mistakes. Delete them, and the same detours will reappear.

    Third, validate periodically. After the environment changes, old experience may become invalid. Set expiration rules, or run small-scale verification before reuse.

    7. Evaluation: Is the System Actually Improving?

    The biggest risk for self-improving systems is superficial progress. Evaluation should answer one clear question: does performance on the same tasks steadily improve across iterations?

    Recommended practices:

    • Fix a set of benchmark tasks so every round is compared against the same standard;
    • Record both final metrics and compute cost, to avoid buying metric gains with excessive compute;
    • Maintain a holdout set to check whether the system is overfitting to training tasks;
    • Compare versions with and without the memory mechanism to isolate its contribution.

    8. Practical Adoption Advice

    To introduce this architecture into a real project, start with a minimal viable version. Implement the shared state and a single-round propose–implement–evaluate flow first, then gradually add statistical selection and experience memory. Every time a module is added, check whether it delivers measurable gains.

    The core of this architecture is giving the system the ability to look back and correct itself. It doesn’t rely on any single clever fix; it relies on continuous recording, comparison, and adjustment to progressively find better solutions.