Million-Token Agent Coding in Practice: Test Results and Engineering Lessons

    Large language models have moved into the agent coding era, and evaluation has shifted from "does a single response look good" to "can an agent plan, call tools, verify results, and control costs across long, multi-step tasks." This article presents engineering takeaways from a million-token-scale stress test under a general agent framework, covering delivery capability, reasoning stability, cost optimization, and a five-layer guardrail design for production systems.

    Introduction

    When large language models entered the agent coding stage, the focus of evaluation shifted from “does a single-turn response look decent” to “can the model continuously plan, call tools, verify results, and control costs over a long chain of work.” The point of a million-token-scale stress test is not simply to max out the context window, but to put planning, execution, verification, error correction, state management, and cost control into the same engineering pipeline and observe how they behave. Rather than reviewing a specific product, this article abstracts the engineering conclusions from a comprehensive round of testing: in a general agent framework, a deep-reasoning tier and a low-latency tier were assigned engineering coding tasks, complex reasoning tasks, lightweight Q&A, and cost-sensitive workloads, with successes, failures, and costs recorded throughout.

    1. Experiment Design: Turning Long Tasks into an Observable System

    A million-token test that only measures final accuracy can easily mask real problems. Actual consumption is typically composed of the system prompt, tool definitions, conversation history, code and logs, tool returns, retry outputs, and cache hits. Therefore, the evaluation should record at least the following metrics:

    • Task acceptance pass rate, rather than a subjective “looks done”;
    • Number of human takeovers and the reasons for them;
    • Duration of continuous autonomous execution;
    • Number of useless loops, repeated calls, and timeouts;
    • Consumption broken down by input, output, cache hits, and retries;
    • Composite cost per valid deliverable;
    • Whether the agent can self-correct based on logs and test results after a failure.

    The tasks were divided into four groups:

    1. Engineering task A: Starting from a natural-language requirement, build a data model, core business modules, and a basic interactive interface. The prompt only gives the business goal and acceptance boundaries—no step-by-step plan.
    2. Engineering task B: Build a cross-layer mobile prototype or a simulated runtime environment, to observe long-chain modification, dependency handling, and regression verification.
    3. Reasoning task group: Situational reasoning problems, high-level math competition problems, and constraint-satisfaction problems.
    4. Lightweight task group: Everyday conditional judgments, information extraction, format conversion, and simple calculations.

    The purpose of this design is to separate “can write code,” “can reason,” and “can control costs” for independent evaluation, then observe how they combine within the same agent framework.

    2. Finding 1: Long-Horizon Coding Has Crossed the “Deliverable” Threshold

    In the data model and business system tasks, one notable observation was that the model produced a fairly complete implementation plan on its first pass, including business module decomposition, data table design, development order, and a validation checklist. The agent then executed autonomously for nearly an hour with no obvious interruptions and no missed critical steps. The final result was not visually polished, but the core functionality ran, newly added data raised no errors, and operations such as category maintenance and record CRUD all worked.

    This shows that for engineering tasks with relatively clear boundaries and executable acceptance criteria, agent coding already has strong “deliverable” potential. The key capability is not just generating code, but forming a closed loop that can:

    • Break vague requirements into modules, data structures, and an implementation order;
    • Externalize the plan into files, task lists, or checklists to reduce context drift;
    • Obtain compile, test, or runtime feedback through tool calls;
    • Locate problems from failure information and re-execute;
    • Run a regression check against the acceptance checklist before finishing.

    A simplified long-task orchestration flow looks like this:

    1. function run_long_task(task, budget):
    2. plan = model.plan(task, acceptance_criteria)
    3. require plan.contains("artifacts", "validation_steps")
    4. context = init_context(task)
    5. for step in plan.steps:
    6. if budget.exceeded() or step.timeout():
    7. break
    8. result = model.act(step, context)
    9. ok = verifier.check(step, result)
    10. if not ok:
    11. if loop_detector.repeat(result) > 2:
    12. raise LoopDetected
    13. context = context.add_failure_feedback(result)
    14. continue
    15. context = summarize_and_store(step, result, context)
    16. return verifier.final_check(plan, context)

    This pseudocode emphasizes three points: the plan must be checkable, failures must be recorded in a structured way, and loops must be detected. The stability of agent coding often depends not on any single code generation, but on state management and the verification loop.

    3. Finding 2: Complex Reasoning Has Local Strengths, but Stability Remains the Bottleneck

    On situational reasoning problems, the model performed reasonably well. These problems typically require gradually absorbing conditions, ruling out contradictory hypotheses, and finding a consistent explanation under limited constraints. The deep-reasoning tier showed advantages in condition tracking and local hypothesis checking.

    However, on high-level math competition problems or tasks requiring long chains of abstract reasoning, problems emerged: sometimes the model got stuck in repeated verification, sometimes it kept deriving along a wrong branch, and sometimes it produced answers that were formally correct-looking but wrong. The reasons are not mysterious:

    • Coding tasks can rely on compilers, tests, and runtime logs for external feedback, while pure reasoning tasks lack a reliable “judge”;
    • Self-checking without external tools or formal verification may amplify existing errors;
    • In long-chain reasoning, an early deviation propagates downstream;
    • The model tends to turn “check again” into “repeat the same check,” creating useless loops.

    Therefore, complex reasoning is better handled with “segmented solving + external verification + budget caps” than by endlessly extending thinking. In practice you can set:

    • Separate the first-pass solution from independent review, to avoid self-reinforcement within the same context;
    • For formalizable problems, introduce symbolic computation, constraint solving, or programmatic verification;
    • For unverifiable problems, set a maximum retry count and a confidence threshold;
    • Trigger human review when results from multiple rounds diverge, instead of stacking more reasoning.

    4. Finding 3: Caching and Context Engineering Can Dilute the Cost of Long Tasks

    In long tasks, repeated context is the biggest cost driver. System prompts, tool descriptions, requirement documents, historical code, and test logs reappear across multiple calls. If the full history is resent every time, both cost and latency climb quickly. The value of caching is that a stable prefix is computed once, and subsequent requests reuse that state, reducing repeated input costs.

    A simplified cost model captures the idea:

    1. Total cost =
    2. uncached input × input price +
    3. cache-hit input × cached price +
    4. output × output price +
    5. retry and useless-loop overhead +
    6. tool call cost

    Four things matter most in engineering practice:

    1. Fix the system prompt, tool definitions, and acceptance rules to form a stable prefix as much as possible.
    2. Compress conversation history into module summaries, change logs, and open questions, rather than feeding everything back in.
    3. Build checkpoints for files, data, and task state, so retries only restore the necessary context.
    4. Monitor cache hit rate, retry rate, and cost per valid deliverable, rather than just the nominal price per token.

    This means that even if prices change, as long as the task structure is sound and cache reuse is thorough, the total bill for a long task may grow less than intuition suggests. Conversely, if prompts change frequently and history grows without bound, even a cheap price gets eaten up by useless retries.

    5. Counterintuitive Finding: Lightweight Tasks Suffer Most from “Overthinking”

    The most alarming phenomenon in this round of testing was “over-reasoning” on simple tasks. On some everyday conditional-judgment questions, the deep-reasoning tier actually failed to give a direct answer because it kept adding assumptions and re-checking itself, while the low-latency tier simply answered based on the given conditions and was more stable.

    There are usually three causes:

    • The question itself relies on common sense and direct conditions, requiring no complex planning;
    • The model introduces business assumptions that were never given, complicating a simple problem;
    • Too many verification passes cause oscillation among multiple candidate answers.

    The solution is not to simply disable deep reasoning, but to route by task tier:

    Task Type Recommended Strategy Key Guardrails
    Long-horizon coding Deep reasoning + tool loop Tests, schema validation, loop/timeout detection
    Situational reasoning Deep reasoning + limited self-checking Condition constraints, answer consistency
    Hard math Deep reasoning + external verification Symbolic checks, confidence threshold, human escalation
    Information extraction Low latency Structure validation, field completeness
    Everyday judgment Low latency + single check Forbid extending beyond given conditions

    A practical prompt constraint is: “Give a single answer first, then check at most once; do not introduce conditions not given in the problem.” For simple tasks, the reasoning budget should be treated as a configurable parameter, not something cranked to the maximum by default.

    6. Engineering Recommendations: Build Five Layers of Guardrails

    To put these lessons into a production system, we recommend five layers of guardrails.

    First, the routing layer. Choose different reasoning tiers based on task type, risk level, and verifiability, so that not every request takes the heaviest path.

    Second, the planning layer. Require the agent to produce a checkable plan first, including module decomposition, acceptance criteria, testing methods, and rollback conditions. The plan itself should be saved as a deliverable.

    Third, the execution layer. Set timeouts, maximum tool call counts, retry limits, and loop detection for each step. Keep operations like file modifications and data writes idempotent.

    Fourth, the verification layer. For coding tasks, prioritize automated tests and static checks; for data tasks, use structure validation; for reasoning tasks, introduce external judges wherever possible. Results that cannot be verified must be flagged as risky.

    Fifth, the cost observability layer. Record input, output, cache, retry, and tool call consumption per task, and establish a “cost per valid deliverable” metric. Only by observing quality, latency, and cost together can you judge whether an agent is truly production-ready.

    7. Conclusion

    The core lessons from the million-token stress test can be summarized as follows: long-horizon agent coding already has the ability to deliver continuously in controlled engineering scenarios; tool feedback and verification loops are the key to stability; caching and context engineering can significantly improve long-task costs; and on lightweight tasks, over-reasoning becomes a new failure source.

    A truly usable agent system should not pursue “deep thinking on everything,” but instead achieve task-matched routing, observable processes, recoverable failures, and controllable costs. For developers and enterprises, what matters more than a one-off benchmark score is building an engineering system that continuously evaluates long-task success rates, human takeover rates, and cost per valid deliverable.