Cut Token Costs Without Changing Models: Agent Scheduling-Layer Optimization
As AI coding and automation agents take on more multi-step work, token consumption and invocation bills can rise quickly even when tasks run faster. This article explains why traditional agents burn tokens through repeated tool definitions and full intermediate results, then introduces a scripted scheduling approach that keeps the model focused on planning, judgment, and exceptions while scripts and the execution environment handle mechanical tool orchestration, filtering, and summarization. It also covers where the gains come from, practical boundaries, and an implementation checklist for teams.
In AI coding and automation scenarios, developers often notice “efficiency” and “cost” at the same time: tasks do execute faster, but background context size and invocation bills also rise quickly. In the past, there were only two common paths to reduce cost: wait for a cheaper new model, or downgrade the main model to a smaller one. The former is uncontrollable, while the latter may cause fluctuations in delivery quality. A more practical third path is to move the optimization point from the “model layer” down to the “scheduling layer”: instead of changing the model, change the way the agent organizes tool calls, passes intermediate results, and returns context.
1. Why Traditional Agents Burn Tokens Easily
In the normal mode, the model usually directly organizes multi-step tool calls: first retrieve files, then read content, then modify code or query external records. If a later step depends on the result of an earlier step, the tool output must also return to the model so that the model can decide the next action. A single task may look simple, but the request payload keeps expanding with each round.
The first cost comes from repeated transmission of “fixed tool instructions.” Each round of requests often includes system prompts, available tool definitions, historical messages, and tool results. Tool definitions are relatively static, large blocks of content. As long as the session continues, they may be carried into every round of requests. Even if only one tool is used in the current round, the instructions for other tools may still occupy context.
The second cost comes from “full intermediate results.” Many tool return values only need a small number of key lines after filtering, but under the round-by-round invocation mechanism, entire logs, full batches of raw records, and complete retrieval results may all be written into the conversation history. The more rounds there are, the longer the history becomes; the longer the history is, the larger the next request becomes, ultimately creating snowballing growth.
This can be understood with a simplified formula:
Single-round request size ≈ system prompt + tool definitions + historical messages + tool resultsTotal consumption ≈ Σ request size per round
When a task involves troubleshooting across multiple files, batch retrieval of external records, repeated log queries, or cross-tool collaboration, the model frequently participates in intermediate judgment, and token consumption naturally rises quickly. The problem is not entirely that the model is “expensive”; rather, the scheduling architecture makes the model take on too many mechanical steps that scripts could have completed.
2. Scheduling-Layer Surgery: Making Code the Protocol Between Agents and Tools
The core of the so-called “scripted scheduling mode” is not to change the model, but to change “the model leading tool calls round by round” into “the model handles planning, scripts handle execution, the execution environment handles filtering and summarization, and the model receives only key evidence and anomalies.” Here, code is no longer just an object being generated; it becomes an efficient communication protocol between the agent and tools.
Its basic flow can be summarized as follows:
- The model generates a task plan or orchestration script based on the goal.
- The script loads tools on demand and invokes tools in batches within a controlled environment.
- Intermediate results remain in the execution environment for filtering, aggregation, statistics, and summarization.
- Only key evidence, statistical results, anomaly information, and next-step suggestions are returned to the model.
- The model intervenes only when semantic judgment, exception decisions, or final confirmation are needed.
For comparison:
| Dimension | Model-led round-by-round scheduling | Scripted scheduling |
|---|---|---|
| Tool definitions | May be repeated every round | Injected sparingly at the start and loaded on demand |
| Intermediate results | Fully enter conversation history | Filtered and summarized in the execution environment before return |
| Multi-step execution | Model repeatedly decides the next step | Script orchestrates multiple steps in one run |
| Parallelism | Depends on model organization | Scripts can naturally parallelize and batch |
| Reproducibility | Depends on conversation trace | Scripts and execution records are auditable |
| Cost structure | Obvious context expansion | Leaner context and controllable execution cost |
An example scheduling strategy is as follows:
# Pseudocode: load tools on demand and return summarized resultsInitially injected tools: task planning, retrieval entry pointTools loaded on demand: file reading, log query, batch record retrieval, code editingExecution rules:1. Retrieve and filter candidate objects first2. Read detailed content only for candidate objects3. Complete aggregation, statistics, and summarization inside the execution environment4. Return: key evidence, statistical results, anomalies, and next-step suggestions
Furthermore, script orchestration can collapse the chain of “search first, then read, then filter, then calculate statistics” into a single execution:
function handle_task(goal):plan = model.plan(goal, tools=[search, summarize])candidates = search(plan.query)selected = filter(candidates, plan.conditions)[:N]evidence = []for item in selected:raw = read(item)evidence.append(summarize(raw, max_lines=K))if needs_model_judgement(evidence):return model.decide(evidence, plan)return execute(plan.actions)
The key change here is that raw logs and batch records are no longer all stuffed into the model context; instead, they are compressed into evidence fragments on the execution side. Tool instructions also do not need to be exposed to the model all at once; they can be dynamically loaded according to the task stage. The model still retains planning and decision-making authority, but it no longer pays repeatedly for every mechanical step.
3. Where the Gains Come From and Where the Boundaries Are
From public discussions, similar scheduling-layer optimizations can reduce real invocation bills by about 20% in multi-step development tasks. In high-frequency external tool invocation scenarios, the total volume of processed tokens can drop by 60% to more than 70%. The specific magnitude depends on task shape, tool return size, script hit rate, and anomaly ratio, and cannot simply be treated as a fixed promise.
The gains mainly come from three places: first, reducing repeated transmission of tool definitions; second, preventing full intermediate results from entering history; third, separating parallelizable batch operations from multi-round model judgment. For tasks such as “finding problems across multiple files,” “batch retrieving and calculating statistics on external records,” and “frequently querying and summarizing logs,” the gains are usually more obvious. For tasks that require only one or two simple calls and are dominated by semantic judgment, the gains may be limited.
However, scheduling-layer optimization also has boundaries. Script generation requires quality assurance, and complex scripts may introduce debugging costs. Summarization may lose long-tail information, so a traceable index of raw evidence needs to be retained. The execution environment must have permission isolation, timeout control, retry, and idempotency mechanisms. Exception paths must be able to return control to the model in a timely manner. Otherwise, the tokens saved may be offset by rework and troubleshooting costs.
4. Implementation Checklist
When introducing scripted scheduling, teams can proceed according to the following steps:
- Identify high-frequency multi-step tasks: prioritize scenarios with many tool-call rounds, large return sizes, and relatively stable steps.
- Classify tools and load them on demand: divide tools into initial entry points, stage tools, and low-frequency tools to avoid injecting all instructions at once.
- Design a summarization contract: define returned fields, evidence format, maximum length, statistical definitions, and anomaly markers so that the model can make judgments.
- Establish a controlled execution environment: limit access to files and external records, and set timeouts, retries, idempotency, and audit logs.
- Roll out gradually and evaluate: compare token consumption, invocation bills, end-to-end latency, task success rate, manual rework rate, and quality scores.
- Build rollback mechanisms: retain traditional round-by-round scheduling as a fallback path, and automatically fall back when script execution fails or evidence is insufficient.
- Improve observability: record script versions, tool invocation traces, summary hit rates, exception types, and the number of model interventions.
In short, reducing costs does not necessarily mean waiting only for cheaper models. Moving the optimization focus to the scheduling layer—letting scripts handle mechanical orchestration, letting the execution environment handle filtering and summarization, and letting the model focus on planning, judgment, and exception handling—is a viable path to reducing token consumption without sacrificing model capability. What really matters is not a single feature, but the engineered division of labor among “model capability, script execution, and context governance.”
