Skip to main content
This page builds on the concepts in Agentex Tracing Overview and Span Hierarchy & Best Practices. Make sure you’re familiar with creating spans and setting parent_id before diving into multi-agent propagation.

The Problem

In a multi-agent system, each agent creates its own trace by default (trace_id = task_id, and each agent has its own task). The result is fragmented observability: the orchestrator’s trace shows only its own spans, and each sub-agent’s work lives in a separate, disconnected trace. With the three child agents used in the example below, you end up with four separate traces instead of one unified view of the entire workflow.

The Solution: Trace ID Propagation

Pass the orchestrator’s trace_id to every sub-agent so all spans land in a single trace tree. You also thread parent_span_id through each dispatch so the hierarchy forms correctly. Two things make this work:
  1. Same trace_id everywhere: the orchestrator’s task_id is used as the trace_id for all sub-agent spans
  2. Threaded parent_span_id: each dispatch passes the current span’s ID so sub-agent work nests correctly

Context Propagation in Temporal

For Temporal-based agents, trace context flows automatically through the interceptor system: Set self._task_id, self._trace_id, and self._parent_span_id on the workflow instance. Once all three are set, ContextInterceptor passes them to each activity the workflow starts, and the model in that activity uses them as the trace and parent span of its auto-traced span.

Setting Up Context in Your Workflow

Use this method inside your existing workflow class after configuring the worker’s ContextInterceptor and TemporalStreamingModelProvider as described in Built-in Tracing Providers. Store the turn span’s ID before running the agent:
ContextInterceptor reads self._task_id, self._trace_id, and self._parent_span_id from the workflow instance. With the interceptor registered in the worker, these attributes propagate to its Temporal activities. Cross-agent ACP requests need explicit application-level propagation, as shown below.

Multi-Agent Code Example

Orchestrator Agent

Use adk.acp.create_task to create each child task. The trace_id and parent_span_id arguments on create_task trace only the orchestrator’s outbound call. Put the shared context in task params so the child can read it from params.task.params, then send its user input with adk.acp.send_event. This example stores the context under a trace_context key in the task params. Use the same keys in both agents:
Call this helper from the orchestrator’s event handler with its task ID, the input message, and the deployed child-agent names. It creates fresh tasks by omitting name; supplying an existing task name would reuse that task and its history.

Sub-Agent (Child)

Add this handler to the child agent’s acp.py (an async agent using the base ACP type), alongside the SGP processor initialization. It reads the context stored with its task, uses the child’s own task ID for message routing, and uses the orchestrator’s ID for span grouping:
The auto-send method already delivers the response to the child task’s chat UI. If the orchestrator must collect child results, implement that separately in your agent coordination logic; sending an event does not wait for a child’s final response.

Resulting Unified Trace Tree

With trace propagation, the research, analysis, and synthesis agents appear under the orchestrator’s trace, with the outbound ACP operations and one LiteLLM provider span under each child’s turn:

Verification

1

Run your orchestrator agent

Start the orchestrator: agentex agents run --manifest manifest.yaml
2

Trigger sub-agent dispatch

Send a task or message that causes the orchestrator to dispatch work to sub-agents.
3

Check spans via Agentex API

Spans reach the Agentex API only if your agents register the Agentex processor (AgentexTracingProcessorConfig()) in each agent process, as in the Quick Start. Query for all spans in the trace:
Verify that sub-agent spans share the orchestrator’s trace_id.
4

Verify hierarchy

Check that each span’s parent_id references an existing span’s id. Sub-agent spans should nest under the orchestrator’s dispatch spans.
5

Confirm in the SGP UI

Open the Trace Detail View, filter by the orchestrator’s task_id, and confirm the unified tree shows orchestrator and sub-agent spans together.

Troubleshooting

The sub-agent is using its own task_id as trace_id instead of the orchestrator’s. Check that:
  • The orchestrator stores its task ID in params.trace_context.trace_id when creating the child task
  • The sub-agent reads the context from params.task.params["trace_context"] and uses its trace_id, falling back to its own task ID only for standalone use
  • All adk.tracing.span() calls in the sub-agent use the propagated trace_id
Parent-child relationships are missing. Check that:
  • parent_span_id is stored in the child task’s trace_context configuration along with trace_id
  • Sub-agent spans set parent_id to the received parent_span_id
  • Inside the sub-agent, child operations (LLM calls, tools) receive parent_span_id=span.id from the enclosing turn span
The workflow’s self._parent_span_id was not set before executing the activity. Ensure:
  • self._parent_span_id = span.id is set before calling workflow.execute_activity()
  • The turn span is created and its id is captured before any activity execution
  • For Temporal workflows, the ContextInterceptor is registered in the worker’s interceptor list