Observability for AI Agents at Scale: From Event Streams to Structured Traces

    As AI agents move from occasional trials to hundreds of daily runs across a team, the questions change: where is time spent, where are tokens consumed, and where do failures happen. This article examines why the local, single-session views bundled with open-source coding agent frameworks are no longer enough, how a microkernel plus plugin architecture and the ReAct loop make execution structure unknowable before runtime, and how to rebuild raw event streams into a unified trace model of tasks, inference rounds, model calls, and tool calls. It then outlines a platform-side approach built on Baidu AI Cloud's OneSuite Agent observability capabilities, covering collection, storage, analysis, and alerting, along with practical pitfalls around attribute design, sampling, redaction, and cost definitions.

    1. Introduction: What Changes at Scale

    AI agents have become part of the daily development workflow for many teams. When usage grows from “a few people running it occasionally” to “dozens of people running it hundreds of times a day,” the focus of the people relying on it shifts noticeably. The question is no longer just whether a single run produced the right result, but three things: whether time is spent on model inference or tool execution; which sessions and models token consumption is concentrated in; and at which step failures and interruptions occur, and whether the process can be replayed.

    All three are fundamentally observability problems. Most teams first encounter agents through the local views bundled with the framework: single-session, on one machine, in real time. That is good enough for a trial, but it falls short the moment someone asks “how did this batch of tasks perform overall,” “what did the cost distribution look like last week,” or “can that failure from three days ago be reproduced.”

    This article uses a typical class of open-source coding agent frameworks (command-line in form, referred to below as “coding agent frameworks”) as its technical background. It abstracts how they run and what data they produce, discusses why call relationships need to be added on top of the raw event stream, and how Baidu AI Cloud’s observability capabilities can complete the picture.

    2. How Coding Agent Frameworks Run

    The role of these frameworks is to let a large model autonomously complete a full task in a controlled environment: reading and writing files, executing commands, calling external services, and deciding the next action based on the result of each step. Understanding that structure is a prerequisite for understanding where observability gets hard.

    2.1 Microkernel Plus Full Plugin Architecture

    Organizationally, they generally adopt a “microkernel plus full plugin” design. The kernel only assembles plugins according to a profile and manages their lifecycle; model adapters, tool sets, sandbox policies, session persistence, and the rest are all pluggable plugins. The command line, terminal interaction, and headless batch modes share the same kernel. Observability is mounted at this same layer, which is the fundamental reason it can collect full process data without intruding into business code.

    2.2 The ReAct Loop: Execution Structure Is Unknown Before Runtime

    The execution model is a ReAct loop. One user task is called a turn, and each round of “reason, call a tool, observe the result” inside a turn is called a step. The key conclusion: the number of loop rounds and which tools get called are decided by the model at runtime, so the execution structure cannot be determined in advance.

    This directly shapes the design direction of any observability approach: fixed stage divisions based on predefined instrumentation will not work, and the only option is post-hoc reconstruction from a complete event stream.

    2.3 What the Framework Provides Out of the Box

    Based on the event stream and on-disk data, these frameworks typically offer three ready-to-use capabilities:

    • Session trajectory: an execution record table organized by round inside the browser, where a single record shows token usage and elapsed time;
    • Session event stream persisted to disk: the complete event stream stored as compressed JSONL in a local session directory, with no data loss;
    • Tool call search: tool call arguments and return results are recorded in the event stream and can be searched in full text within a session.

    2.4 Why Call Relationships Still Need to Be Built on Top of This Data

    The raw data is a time-ordered sequence of session events stored on the local machine. It answers “what happened,” but not “who is slow, who is expensive, and why it broke.” As scale grows and the number of machines increases, three problems become prominent:

    1. Elapsed time cannot be attributed: there is only a total duration, no split between model inference and tool execution, so there is no basis for deciding what to optimize;
    2. Cost cannot be aggregated: token consumption is scattered across local files on each machine and cannot be rolled up by session, model, or task type;
    3. Failures cannot be traced back: the interruption point is buried in a long event stream, and without parent-child call relationships, cross-machine reproduction is nearly impossible.

    3. Structured Traces: Rebuilding the Event Stream as a Tree

    The approach is to perform a “structured reconstruction” on top of the raw event stream and produce a unified trace model:

    1. Task (one user task / turn)
    2. └── Inference Round (reasoning round / step)
    3. ├── Model Call (model name, input/output tokens, elapsed time, status)
    4. └── Tool Call (tool name, argument summary, return summary, elapsed time, status)

    Four levels — task and inference round, model call, tool call, and session association — form the basis for all subsequent analysis. With parent-child relationships in place, elapsed time can be decomposed into self time (total duration minus the sum of child call durations gives the layer’s own overhead), failures can be located at a specific node, and cost can be rolled up along any dimension.

    4. The Platform-Side Approach: Collection, Storage, Analysis, Alerting

    On top of Baidu AI Cloud’s Agent observability capabilities (the OneSuite Agent observability system), a collection extension in native plugin form is provided for coding agent frameworks: mounted as a plugin, it requires no changes to the framework kernel or business code, reconstructs the execution process into the structured trace described above, and combines trace search, aggregated analysis, and the platform’s own alerting dashboards into a full-picture observability solution.

    • Collection layer: the plugin subscribes to the event stream and converts it into standard spans reported in real time, buffering locally and retrying under weak network conditions to avoid data loss;
    • Storage layer: trace data goes into log/trace storage built for long-term retention rather than local files;
    • Analysis layer: multi-dimensional aggregation by session, model, tool, and time window;
    • Alerting layer: threshold-based alerts on failure rate, per-task elapsed time, and token usage.

    5. Implementation Notes and Common Pitfalls

    1. Design attributes first: model name, tool name, and task labels must be standard attributes, or aggregation becomes impossible later;
    2. Layer sampling and retention: full collection for troubleshooting, downsampled data for long-term trends;
    3. Redact sensitive information: tool arguments and returns may contain keys or code snippets and must be trimmed on the collection side;
    4. Align semantic conventions: unless the team agrees on definitions of “failure,” “interruption,” and “timeout,” alerts are meaningless;
    5. Align the cost definition: token counts must state whether cache hits are included, to avoid conflicting with billing figures.

    6. Conclusion

    Observability at scale is not “storing one more copy of the logs.” It is rebuilding an event stream with an unpredictable execution structure into a trace that can be decomposed, aggregated, and replayed. Integrating with Baidu AI Cloud’s observability system in plugin form turns the three problems of elapsed time, cost, and failure from “someone digging through files” into “drawing conclusions from data.”