AI Agent Token Costs: On-Demand Execution vs. Self-Improving Learning Loops

    This article explains why high token consumption is not automatically a sign of poor architecture. It breaks down the main cost categories for AI agents, compares on-demand execution with self-improving learning loops, and offers practical guidance on evaluation, observability, cost governance, and architecture selection.

    High token consumption is often treated as evidence of architectural failure. For AI agents, that judgment is too crude. The consumption curve first reflects the design goal: is the system meant to complete a task when invoked and then stop immediately, or is it meant to keep turning completed work into reusable capability for next time? The cost of the first model grows roughly linearly with the number of tasks. The second continues to pay for learning, packaging, and memory maintenance beyond the cost of the task itself. These two approaches solve different problems and cannot be judged with the same ruler.

    Break Down the Consumption First

    The tokens consumed by a single model call usually include input context, tool descriptions, intermediate reasoning, tool returns, and the final answer. When an agent chains these calls into a multi-step loop, total cost is no longer just “one question, one answer.” At least four categories of spending should be distinguished.

    The first is task execution cost: understanding the goal, planning steps, calling tools, and validating results. It is strongly correlated with task complexity, context length, and the number of failed retries.

    The second is trajectory replay cost: after the task ends, the steps, tool parameters, and reasons for success or failure are sent back to the model to extract repeatable patterns. This does not directly deliver a user-visible result, but it determines whether the system becomes faster on similar tasks.

    The third is skill generation cost: turning high-frequency, stable operation sequences into reusable workflows, prompt templates, or tool combinations, followed by small-scale validation. Generation itself consumes tokens, and incorrect skills can amplify waste in later tasks.

    The fourth is memory maintenance cost: writing, deduplication, expiration, conflict resolution, and on-demand retrieval. Memory is not a free cache. Retrieval puts historical fragments back into the context, while writing and organizing may require additional model calls or rule-engine processing.

    Therefore, the cost of an agent that only performs routing and execution is close to:

    Usage duration or number of tasks × cost per task.

    The cost of an agent with a learning loop is close to:

    Task cost + replay cost + skill generation and validation cost + memory maintenance cost.

    When tasks are few, the last three items look like fixed overhead and can appear disproportionately high. As similar tasks become more frequent, these costs are amortized and may reduce the cost of each subsequent task.

    Two Philosophies, Not Two Slogans

    The core of an on-demand design is the gateway and router. The user provides a goal, and the system selects channels, tools, and permissions, then stops after completion. Its advantages are clear boundaries, predictable behavior, and almost no token burn while idle. If the same task is repeated one hundred times, it does not automatically become smarter; each time feels like a new problem. This approach suits scenarios with stable workflows, strict compliance requirements, high error costs, and no desire for the system to rewrite its own behavior while unattended.

    The core of a continuously improving design is the iteration of “execute, reflect, rewrite.” It assumes that many tasks will recur and that stable patterns in trajectories are worth preserving. After completing a set of tasks, the system does not simply archive logs. Instead, it asks: which steps always appear together, which parameters can be parameterized, and which failures can be avoided in advance. When a harder but similar task appears next time, it prioritizes reusing validated fragments rather than planning from scratch.

    This is similar to a hybrid vehicle versus a machine running continuously at high power: the former tries to shut down while waiting, while the latter pays idle costs to maintain high capability at all times. Higher fuel consumption alone does not prove the machine is worse; it only shows that resources are spent on different capabilities. Evaluation must consider task success rate, number of human interventions, time spent on repeated tasks, and tokens per effective result, not just total consumption.

    Why “Not Using It” Can Still Feel Expensive

    The overhead of a learning loop does not drop to zero perfectly based on whether you asked a question today. Trajectory analysis, merging skill candidates, and organizing memory indexes often run in batches. When usage is low, these batches are large relative to task volume, so users may feel the system is spending money even while idle. As usage increases and task distribution becomes concentrated, the same skills are hit repeatedly, per-task context can be shortened, retries decrease, and the share of fixed overhead falls.

    But the opposite case also exists. If tasks are highly divergent and the goal, data, and tools differ every time, the accumulated skills will rarely be reused. In that case, learning cost is a pure add-on, total consumption is higher than in an execution-only architecture, and quality may not improve. So “more usage makes it more worthwhile” has prerequisites: tasks must have reusable structure, evaluation must identify ineffective skills, and memory must be able to forget.

    In the industry, total token consumption of agents often rises sharply with deeper usage, but this trend alone says nothing about who is leading. The reason daily consumption at leading systems has shifted from “newsworthy” to “routine scale” is mainly that loop steps, tool returns, and long-term context are all becoming heavier. When comparing two systems, if user scale, task types, and whether background learning is enabled are inconsistent, total-volume rankings have little explanatory power. More meaningful metrics are per-user effective task cost and the success-rate improvement gained from learning spend.

    How to Make the Learning Loop Avoid Spinning in Place

    Trajectories should be replayable, but that does not mean stuffing all raw logs into the next prompt. A practical approach is to record the goal, key decisions, tool names and parameter summaries, result validation, and failure points, and to tag each step so it can be retrieved. During replay, only fragments related to the current failure mode should be selected.

    A skill should not be just another vague prompt. A reusable skill should at least include: applicable conditions, inputs and outputs, steps or tool sequences, stop conditions, and known failure modes. After generation, it should be validated with a small regression sample set. If it fails, it should be marked as a candidate and must not automatically enter the default path.

    Memory should be layered. Short-term session state serves the current task. Mid-term experience should retain only preferences and pitfalls that have been validated multiple times. Long-term knowledge should be expirable and traceable to its source. When conflicts occur, preserve evidence rather than overwriting it with a smoother summary. Retrieval should limit the number of items and the token budget to avoid “blowing up the context just to remember things.”

    A sample flow can be written as:

    1. Complete task -> compress trajectory -> check whether it matches an existing skill
    2. -> match: update statistics and failure notes
    3. -> threshold reached: generate skill candidate -> regression validation -> publish or discard
    4. Periodic: merge duplicate memories, delete expired items, track hit rate and saved steps

    Hit rate, validation pass rate, replay token share, and step-count changes after a skill goes live are more informative than “how many tokens were burned today” when judging whether learning is paying off.

    Cost Governance and Observability

    Regardless of the philosophy, there must be budgets and circuit breakers. Maximum steps per task, maximum context length, and retry limits for tool failures can stop runaway loops. Learning tasks should use separate quotas to prevent background replay from crowding out online requests and to prevent online traffic from triggering unlimited replay.

    For observability, it is recommended to label data as “online execution / replay / skill validation / memory organization” and separately track tokens, latency, and failure rate. Then examine cost per successful result by task type. If replay share for a task type keeps rising but success rate does not, automatic learning for that type should be disabled and the system should fall back to a fixed workflow.

    Logs, metrics, and object storage are suitable for storing trajectories and versioned skills. Message queues are suitable for separating “task completed” from “asynchronous replay,” avoiding making users wait for the learning process. Model inference services should only handle explicitly triggered calls. These are general capabilities and do not need to be tied to a proprietary interface. If a team already uses model invocation, logging, and monitoring services on Baidu AI Cloud, it can apply the above labels and quotas to the existing observability stack for cost attribution without inventing additional product features.

    How to Choose

    Choose an on-demand architecture when tasks are mostly one-off, compliance audits require frozen behavior, tools have significant side effects, and the team does not yet have an evaluation set. Making routing, permissions, and stop conditions solid is more important than building self-rewriting too early.

    Choose a learning architecture when similar tasks recur weekly, failure modes can be categorized, someone can review skill candidates, and the team can accept a higher token curve in the early stage. The rollout order should be: first record trajectories, then have humans confirm skills, and only then allow automatic publishing of high-confidence skills.

    Hybrid designs are also common. The entry point remains on-demand and strongly constrained, with replay enabled only for whitelisted task types. Learning results appear as “optional skills,” and policy decides whether to inject them into context. This preserves low consumption while idle and gradually shortens high-frequency paths.

    Conclusion

    Being first in total token consumption only shows that a certain working style spends more computation on the agent loop. It does not directly mean more users or a better product. The cost of an on-demand system is a linear function of tasks; a self-improving system pays extra for replay, skills, and memory. The former saves by waiting; the latter bets on compounding. The investment is worthwhile only when tasks are repeatable, skills are verifiable, memory is forgettable, and spending can be accounted for separately. Once these four things are measured clearly, high consumption becomes a manageable engineering trade-off rather than an emotional topic.