Agentic Coding: How to Schedule Context and Compute for AI Agents
This article breaks down the three capabilities that make agentic coding practical: long-context handling, tiered reasoning effort, and execution/state management. It explains why a million-token window is only useful when you control what goes into it, how reasoning effort tiers and adaptive reasoning keep compute focused on hard tasks, and why context compression matters more than truncation in long-running agents. It closes with an engineering checklist covering sandboxed tool execution, cost quotas, observability and evaluation, data compliance, and integration with existing development workflows.
Agentic Coding: How to Schedule Context and Compute for AI Agents
1. Why Agentic Coding Became a Requirement After the “Chat-Style AI” Phase
Over the past two years, most development teams have used large models in a purely “question-and-answer” mode: paste an error message, ask for a snippet, request a copy edit, then move on once the result arrives. This pattern treats the model as a stateless text transformation function — one prompt in, one completion out, with task boundaries drawn manually by a human.
Real software engineering, however, is never closed by a single question and answer. Shipping one requirement usually involves breaking down the requirement, searching the codebase, editing across files, installing dependencies, writing tests, retrying failures, and comparing logs — a long chain of actions. Push all of those actions back onto a human, and the efficiency gains from the model are largely eaten by context-switching overhead.
Agentic coding exists to solve exactly this: instead of merely answering questions, the model plans steps autonomously, calls tools, observes results, and keeps iterating around a goal until the task succeeds or fails explicitly.
From an engineering standpoint, a usable agentic coding system depends on at least three layers of capability:
- A long-context layer: the codebase, conversation history, tool outputs, and intermediate reasoning chains all have to fit into the model’s input window. Not enough context, and the model “loses its memory.”
- A reasoning-effort control layer: different tasks differ enormously in how much thinking they need. Using the same compute budget for every request means simple tasks are over-provisioned and complex tasks are under-thought.
- An execution and state management layer: task decomposition, tool invocation, failure fallback, and context compaction all need mechanisms on the system side; you cannot count on the model to “do it on its own.”
The “1M context,” “agentic coding,” and “adaptive reasoning control” mentioned in the source material are, in essence, a concentrated expression of these three capabilities in one generation of models. The sections below unpack each layer and outline practical paths.
2. Million-Token Context: Not “Can Fit,” but “Dare to Use”
2.1 What the Context Window Means for Engineering
“1 million tokens” is often reduced to “how many books it holds,” but that analogy is useless for engineers. What matters is: once the window grows, which previously compromised designs can be redone.
Typical wins:
- Whole-repo code understanding: a mid-sized project (tens of thousands to hundreds of thousands of lines) can enter the context in full. Cross-file refactoring, dependency analysis, and interface alignment no longer require the repeated “retrieve a fragment → assemble a prompt → retrieve again” loop.
- Long-horizon task memory: observations, intermediate artifacts, and failure reasons produced across dozens of tool calls can be retained continuously, without frequent summarization that drops information.
- Direct reading of long documents and logs: feed in a complete requirements document, design spec, historical tickets, and runtime logs at once and reason about causality, rather than chunking first and stitching back together.
2.2 But Long Context Is Not Free
A cold shower is in order: a bigger window does not equal better results. The industry commonly observes that the effective context length is usually far smaller than the nominal window. The reasons include:
- Attention dilution: with very long inputs, the model’s ability to locate key information degrades — commonly called “lost in the middle.”
- Linear or superlinear cost growth: the more input tokens, the higher the cost and latency per call. Stuffing a 200k-token repo into the window to ask a “what’s the weather like” level question is pure waste.
- Rising engineering complexity: the longer the context, the more you need careful trimming, ordering, and compaction strategies; otherwise the model gets pulled off course by irrelevant information.
So the right way to use long context is not “stuff in whatever fits,” but precisely controlling what gets sent, according to task needs. That leads to the core topic of the next section: coordinated scheduling of reasoning effort and context budget.
3. Tiered Reasoning Effort: Spend Compute Where It Counts
3.1 Why Tiering Is Necessary
Large-model inference has an easily overlooked property: thinking depth does not correspond linearly to task difficulty. Asking the model to “reason deeply” about a simple query does not produce a better answer — it produces higher latency, higher cost, and sometimes unnecessary uncertainty from overthinking.
Conversely, for architecture tradeoffs, tricky bug localization, or comparing multiple constrained options, shallow reasoning tends to yield answers that “look right” but do not hold up to scrutiny.
What is needed is a mechanism that lets the caller explicitly declare task difficulty, or lets the system automatically judge difficulty and allocate compute accordingly.
3.2 Common Tiering Approaches
A common industry practice is to abstract reasoning effort into a few levels, controlled through parameters or configuration. Naming differs across vendors, but the thinking is highly consistent:
- Low (fast tier): for formatting, simple lookups, low-risk generation. Characterized by low latency, low cost, and low thinking overhead.
- Medium (balanced tier): the default for everyday coding and routine Q&A, balancing quality and cost.
- High (deep tier): enhanced reasoning, on by default or on demand, for tasks requiring multi-step deduction.
- Max (extreme tier): complex architecture design, hard bug hunts, long-horizon agent tasks. The model does more internal deliberation, at the cost of significantly higher latency and cost.
Illustrative call shape (not any specific product’s API, only expressing the general idea of “parameterized tiers”):
request {task: "Design a message queue consumer that supports millions of concurrent connections",reasoning_effort: "high", // low | medium | high | maxcontext_budget: 800k // maximum context size allowed in the request}
3.3 Adaptive Reasoning: From Manual to Automatic
A step further is adaptive thinking: rather than a human specifying the tier, the system decides how much reasoning resource to invest based on input complexity, task type, and historical success rates.
This is especially valuable in agent scenarios. A long-horizon task might have ten steps: seven are simple tool calls, three are genuine hard points. Using the top tier throughout blows up the cost; using the low tier throughout guarantees the three hard points fail. The goal of an adaptive mechanism is to concentrate compute where it is genuinely needed.
In practice, adaptive strategies typically rely on:
- Heuristic rules: coarse-grained routing based on task type, input length, whether tool calls are involved, and similar signals.
- A lightweight classifier: a smaller model or rule-based model predicts difficulty, then determines the main model’s reasoning tier.
- A feedback loop: dynamically adjusting the trigger conditions for each tier based on historical success rates and elapsed time.
4. Context Compression: A Required Course for Long-Horizon Agents
4.1 Root of the Problem
The longer an agent task runs, the faster context accumulates. Tool-returned logs, retrieved code snippets, and intermediate reasoning chains can easily blow past the window after a few dozen turns. The traditional approach is truncation: keep the most recent N turns and drop earlier content.
But truncation is costly — the agent may “forget” the original goal of the task, or repeat failed attempts it already made in later steps.
4.2 Compress, Don’t Truncate
A more mature approach is context compression, whose core ideas are:
- When context approaches a threshold, summarize earlier content, keeping key conclusions and decision points while discarding redundant detail.
- The summary is injected as a new “long-term memory,” coexisting with recent verbatim content.
- Some systems introduce layered memory: verbatim text in the short-term window, summaries in the mid-term, and only structured key facts in the long term.
Illustrative pseudocode:
def manage_context(history, current_input, max_tokens):if estimate_tokens(history) + estimate_tokens(current_input) < max_tokens:return history + current_input# Trigger compression: summarize older turns, keep key decisionssummary = summarize(history, keep=["goals", "decisions", "failed_attempts"])recent = tail(history, keep_turns=3)return ({"role": "system", "content": f"[History summary] {summary}"}+ recent+ current_input)
4.3 Engineering Considerations
- Summarization itself loses information, so you must define which categories are “must keep” (task goals, hard constraints, confirmed interface contracts) and which are disposable (intermediate debugging output).
- Compression must be observable. When something goes wrong, engineers need to trace back “what the model saw at the time,” so summaries and compression logs should be part of monitoring and auditing.
- Compression strategy should be configurable. Different businesses have different requirements for context completeness; one size cannot fit all.
5. Putting the Capabilities into an Engineering System: A Delivery Checklist
However strong the capabilities, if they never enter the engineering system, they remain a demo. To make agentic coding truly production-ready, at least the following pieces are needed:
5.1 Tool Invocation and Sandboxed Execution
- Agents that execute code, run tests, and read or write files all need a controlled execution environment. Containerized sandboxes are the common industry approach; combined with resource quotas and network isolation, they prevent damage from mistakes or malicious input.
- Tool results must be structured, so the model can understand them and downstream parsing is easier. Pushing raw stdout straight back into the context wastes tokens and introduces noise.
5.2 Cost Control and Quotas
- Reasoning tier and context size directly determine cost, so you need multi-level quotas at the call, session, and tenant levels.
- Allocate budget by task value: simple tasks go to the low tier; only high-value tasks unlock the high tier and long context.
- Set hard caps on long-context calls to prevent a single call from running out of control.
5.3 Observability and Evaluation
- Record each call’s tier, context size, token consumption, latency, and success rate, forming an analyzable data asset.
- Build an offline evaluation set covering typical task types, used to verify whether tiering and compression strategies actually deliver gains.
- Focus on “effective context utilization” rather than raw window size.
5.4 Data Compliance and Regional Policy
- Enterprise scenarios often require data to be processed in a specific region. The common approach is to offer regional deployment and data residency options, reflected in differentiated pricing.
- Sensitive data should support redaction, isolation, and auditing; the code and logs agents touch often contain internal information and must not be sent out by default.
5.5 Integration with the Existing Development Ecosystem
- Agentic coding should not be an isolated tool; it should be embedded into existing code hosting, CI/CD, monitoring and alerting, and logging services.
- Common integration points include read/write permission control on repositories, automated pipeline triggering, reading back test results, and searching and analyzing production logs.
- In engineering practice on cloud platforms such as Baidu AI Cloud, these capabilities are typically delivered by combining general-purpose cloud products — container platforms, object storage, logging services, monitoring and alerting — rather than relying on a single model’s “do-everything” ability.
6. Conclusion: From “Works” to “Dare to Use in Production”
The leap in this generation of model capabilities lies not in any single parameter, but in placing “context length,” “reasoning depth,” and “tool execution” — three things that used to be separate — into the same schedulable framework for the first time.
For developers, the real challenge has shifted accordingly:
- Not “can the model do it,” but “how to make reasonable tradeoffs among cost, latency, and quality.”
- Not “should we use long context,” but “is this task worth long context.”
- Not “can it execute automatically,” but “how to ensure automatic execution is safe, traceable, and rollback-capable.”
Only when the pieces — tiered reasoning effort, context compression, tool sandboxes, quotas, and observability — are all in place does agentic coding truly turn from “impressive in a demo” into “reliable in production.” There is no shortcut on this path, but the direction is clear enough.
