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’strace_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:
- Same
trace_ideverywhere: the orchestrator’stask_idis used as thetrace_idfor all sub-agent spans - 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: Setself._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’sContextInterceptor 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
Useadk.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:
name; supplying an existing task name would reuse that task and its history.
Sub-Agent (Child)
Add this handler to the child agent’sacp.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:
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.yaml2
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 (Verify that sub-agent spans share the orchestrator’s
AgentexTracingProcessorConfig()) in each agent process, as in the Quick Start. Query for all spans in the trace: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
Sub-agent spans appear in a separate trace
Sub-agent spans appear in a separate trace
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_idwhen creating the child task - The sub-agent reads the context from
params.task.params["trace_context"]and uses itstrace_id, falling back to its own task ID only for standalone use - All
adk.tracing.span()calls in the sub-agent use the propagatedtrace_id
Spans are flat instead of nested
Spans are flat instead of nested
Parent-child relationships are missing. Check that:
parent_span_idis stored in the child task’strace_contextconfiguration along withtrace_id- Sub-agent spans set
parent_idto the receivedparent_span_id - Inside the sub-agent, child operations (LLM calls, tools) receive
parent_span_id=span.idfrom the enclosing turn span
Auto-traced LLM spans are orphaned (no parent)
Auto-traced LLM spans are orphaned (no parent)
The workflow’s
self._parent_span_id was not set before executing the activity. Ensure:self._parent_span_id = span.idis set before callingworkflow.execute_activity()- The turn span is created and its
idis captured before any activity execution - For Temporal workflows, the
ContextInterceptoris registered in the worker’s interceptor list