Hands-On with Long-Horizon LLM Agents: 10 Million Tokens, 3 Surprises, and 1 Unexpected Failure

    This article reports on a hands-on evaluation of long-horizon AI agents that consumed more than 10 million tokens across agentic coding, complex logical reasoning, lightweight Q&A, and cost observation. It shares three positive findings—more mature autonomous planning and execution, a usable tool-calling and self-correction loop, and lower effective costs thanks to prompt caching—plus one unexpected failure mode where "overthinking" hurt accuracy on simple tasks. It also outlines reusable evaluation practices and engineering recommendations for plan externalization, structured failure feedback, model routing, deterministic validation, and cost monitoring. The discussion is vendor-neutral and focuses on common technical issues and practical mitigations.

    1. Why Token-Scale Testing Matters

    Single-turn Q&A benchmarks mostly capture how a model performs under short context and single-step reasoning. Real agentic workloads are long chains: planning, coding, execution, verification, and rollback, each step depending on the previous one. Measuring those capabilities requires an order of magnitude more calls. This evaluation consumed over 10 million tokens in total and covered four dimensions: agentic coding, complex logical reasoning, lightweight Q&A, and cost observation.

    This article is not about any specific vendor or product. It discusses common technical problems that mainstream large models expose in long-horizon agent scenarios, along with mitigations available on the engineering side. Terms such as “an open-source LLM,” “an AI coding tool,” and “a code execution sandbox” are used as generic technical categories.

    2. Surprise 1: Long-Horizon Planning and Execution Have Matured

    For two tasks—database design and building a device-side simulator—we provided only the goal, with no detailed constraints, to test the model’s ability to decompose work autonomously.

    The behavior broke down into three phases:

    1. Planning: the model produced a structured plan covering core module breakdown, table design, and development step ordering.
    2. Execution: it generated code continuously according to the plan, without stalling, looping, or skipping key steps.
    3. Verification: at the end, it produced its own acceptance checklist and self-checked item by item.

    The checklist design is worth borrowing. Example (illustrative, not a specific API):

    1. Acceptance checklist (example)
    2. 1. Table structures initialize successfully
    3. 2. Aggregations are correct after inserting records
    4. 3. Deleting records leaves no orphan data
    5. 4. Money fields follow consistent precision and rounding rules
    6. 5. No duplicate entries under concurrent writes
    7. 6. Invalid input is rejected with a clear error

    Engineering takeaway: whether a long-horizon task completes reliably depends less on the model getting it right in one shot and more on whether it maintains plan consistency. In practice, the plan should be externalized as readable and writable state (for example, a task list file) so that every turn advances against the same plan instead of relying on context memory.

    3. Surprise 2: Tool Calling and Self-Correction Now Form a Usable Loop

    When working with an AI coding tool, the model showed three relatively mature capabilities: recognizing points that require execution-based verification, locating and rewriting code after errors, and changing strategy after repeated failures instead of retrying the same approach.

    A practical loop structure looks like this:

    1. # Pseudocode: agent execution loop
    2. plan = load_plan() # externalized plan for consistency
    3. for step in plan.pending():
    4. patch = model.generate(step) # generate the change
    5. result = sandbox.run(patch) # run and test in the sandbox
    6. if result.passed:
    7. plan.mark_done(step)
    8. else:
    9. # feed failure details back in structured form to avoid repeating mistakes
    10. step.attach(result.stderr, result.failed_cases)
    11. if step.retry > MAX_RETRY:
    12. plan.escalate(step) # escalate to a human or switch strategy

    The key point is that failure information must be fed back in structured form. Pasting only the raw error tends to make the model repeatedly tweak the same spot; supplying the failing cases along with the diff between expected and actual output noticeably improves correction efficiency.

    4. Surprise 3: Caching Substantially Dilutes Cost Growth on Long Tasks

    Compared with the previous generation, API unit prices for this generation are somewhat higher, yet on long tasks the total bill grew far less than the unit price did. The reason is that long-horizon agent contexts are highly repetitive: the same system prompt, the same plan, and the same set of already-read files are carried in again and again.

    Optimizations available on the engineering side:

    • Stable prefix: place invariant content at the very front of the context and keep it byte-for-byte identical to avoid cache misses.
    • Append-only updates: add new information at the end rather than rewriting history.
    • Structured logging and monitoring: build dashboards and alerts for token consumption and cache hit rates, with cost attributed per task.

    Note that specific billing and caching rules should follow the official documentation of the cloud platform in use; this article only discusses general cost-structure patterns.

    5. The Unexpected: “Overthinking” Failures on Lightweight Tasks

    On minimal logic questions (for example, common-sense items such as “a car wash cleans cars, and the owner pays the employees”), the Pro-tier model sometimes reached wrong conclusions after repeated deliberation and self-doubt, while the Flash-tier lightweight model was direct and efficient. In addition, on International Mathematical Olympiad-level problems and in some lightweight tests, reasoning loops and wrong answers appeared.

    Root cause: a mismatch between reasoning budget and task complexity. When reasoning length is unconstrained, the model tends to “keep thinking” and lacks a signal for judging that it has already done enough.

    The mitigation is tiered routing:

    1. if task_complexity == low: use a lightweight model with a low reasoning budget
    2. elif task_complexity == medium: standard model + structured prompting
    3. else: high reasoning budget + external verifier + multi-sample voting

    Two hard constraints should accompany this: set a maximum reasoning or iteration limit, and introduce external validation for the final answer (unit tests, type checks, rule engines) instead of letting the model grade itself.

    6. A Reusable Evaluation Methodology

    1. Design the task set in layers: allocate a share each to long-horizon engineering, complex reasoning, lightweight Q&A, and cost-sensitive cases.
    2. Record process metrics, not just final answers: plan consistency, retry counts, tool-call success rate, and number of human interventions.
    3. Standardize the sandbox and dependency versions to keep runs reproducible.
    4. Attribute cost per task, separating input, output, and cache-hit portions.
    5. State the applicable boundaries of conclusions and avoid extrapolating findings from one scenario to all workloads.

    7. Implementation Checklist

    • Externalize the plan and make state recoverable, so long tasks can resume from a checkpoint.
    • Feed failure information back in structured form, with retry limits and an escalation path.
    • Route across model tiers, allocating reasoning budget by complexity.
    • Add a deterministic validation layer that assigns “is it correct?” to tests rather than to the model’s own account.
    • Build a token and cost monitoring and alerting system, and keep improving prefix stability.

    Overall conclusion: long-horizon agent capability has crossed the usability threshold, and the real engineering difficulty has shifted from “can the model write it” to “how to constrain, verify, and control cost.” Getting the plan, verification, and budget right is what turns model capability into stable business output.