Picture a research task split four ways. The orchestrator agent spawns one sub-agent per sub-job, and each sub-agent calls a different model provider. Synthesis goes through GPT-4o. Sub-agent A handles extraction on Claude 3.5 Sonnet. Sub-agent B classifies with Gemini Flash. Sub-agent C runs an internal fine-tuned model hosted on AWS. One customer's account covers it all inside a 90-second wall-clock window. When the pipeline finishes, events have arrived from four providers, each carrying its own token count and its own cost rate, and no shared identifier naturally joins them.

The total is straightforward. Attribution is the difficult part: which customer paid for the run, which workflow launched it, which sub-agent produced each slice of cost. Skip that granularity and the invoice stops meaning much, per-feature cost reporting has no foundation, and the question every AI founder hears sooner or later—"Why did my bill jump this month?"—has no good answer.

Three Things Every Event Must Answer

A useful multi-agent event answers three questions. Whose account does the usage belong to? Which orchestrated workflow, among everything that customer is running at once, launched this particular sub-agent? And inside that workflow, which agent in the execution tree emitted the event?

The smallest useful payload for this setup looks roughly like the block below:

{
  "idempotency_key": "evt_run_8821_subB_call_002",
  "customer_id":    "cust_acme_corp",
  "workflow_id":    "wf_research_20260903_0940",
  "trace_id":       "trc_8821",
  "parent_agent_id": "agt_orchestrator_01",
  "agent_id":       "agt_classify_B",
  "event_type":     "model.completion",
  "quantity":       1,
  "metadata": {
    "model":         "gemini-flash-1.5",
    "input_tokens":  1240,
    "output_tokens": 88,
    "cost_usd":      0.00031
  }
}

The idempotency_key protects the count when the pipeline retries on a transient error. Every event from one pipeline execution shares the workflow_id, which groups them. The trace_id is the correlation handle for rebuilding the full execution tree. parent_agent_id carries the relationship: because the orchestrator spawned this sub-agent, its cost rolls up into the orchestrator's run.

Rebuilding the Tree from Raw Events

Tree reconstruction rests on parent_agent_id. Take the events sharing one trace_id and you can assemble a directed graph: agents as nodes, spawning relationships as edges. Sum event costs along the graph and rollups appear at each level—sub-agent, branch, workflow, customer.

Cost inside a workflow is rarely spread evenly, which is why this matters. In a research pipeline the synthesis step can absorb 70 percent of total tokens, simply because it reads the combined output of every sub-agent. With only a total, the customer learns the bill but not which part of their workflow runs expensive. With the tree, you can point at the step worth optimizing first.

The tree doubles as the data model for any per-feature cost dashboard a product wants to hand its own customers. "How much did my research pipeline cost versus my summarization pipeline?" is an aggregation by workflow_id. "Which agent in my pipeline burns the most tokens?" is an aggregation by agent_id inside a trace. Events carrying the right fields make both queries trivial. Events missing them make both impossible.

Four Ways Attribution Slips

Wrapping model calls at the infrastructure layer instead of the workflow layer is the usual mistake. Instrument at the SDK level, catching every OpenAI completion, and token counts come out accurate while workflow and agent context disappear. The event knows the model and the token total. It has no idea which customer workflow made the call or which agent inside that workflow is responsible.

Billing data like that is right at the macro level and useless at the detail level. The invoice total exists. Breaking it down by feature, workflow, or agent does not. When a customer disputes a line or wants cost mapped to their own product features, nothing is available to show.

Trace context that propagates unevenly is another failure. The orchestrator mints a trace_id, sub-agents fail to inherit it, and their events land as unrelated top-level items. The execution tree cannot be rebuilt; what remains is a pile of isolated events instead of a structured record of the run.

Opaque identifiers round out the list. "user_8821" works if a mapping table is always at hand. "cust_acme_corp" lets the event describe itself. At 11 PM, chasing a billing discrepancy, self-describing identifiers earn their keep.

Making Context Explicit at Every Hop

Context propagation looks different in each framework. LangChain and LangGraph keep trace context in a callback handler. CrewAI can carry it as task metadata. Custom queue-based orchestrators tend to pass it as a header in the task payload. Mechanics vary; the principle does not. Each agent needs context as an explicit, first-class input rather than something inferred from whatever called it.

Our implementation uses a small propagation contract. The orchestrator fires its first event, generating a trace_id and embedding it in the payload. When it spawns a sub-agent, it hands over the trace_id along with its own agent_id as the sub-agent's parent_agent_id, inside the initialization context. The sub-agent includes both on every event it emits. Deeper nesting extends the same chain.

Two extra fields per event is the instrumentation cost. The return is that every event in the execution links back to its triggering workflow and its spawning agent, however deep the tree runs.

What Attribution Buys Beyond the Invoice

Detailed attribution is not needed for token totals to be correct. What it opens up is a different category of product decision.

Attribute cost to workflows and a cost efficiency report becomes possible: which of a customer's workflows has the best output-to-token ratio? Attribute cost to agents and optimization opportunities surface: the summarization sub-agent runs on a model that costs 8x a smaller one that performs identically on this task class. These are product insights as much as billing lines. They depend entirely on event data rich enough to support the analysis.

Baking attribution into the schema at the start costs far less than adding it later. Once production traffic is live, adding trace_id and parent_agent_id means coordinated changes across instrumentation, metering configuration, and existing invoice data. At the beginning it is one decision and two fields per event. Afterward it is a migration.

Billing notes for multi-agent systems

Event design, attribution mechanics, and billing infrastructure from the team behind the product. One email a month.