Multi-Agent Traces
Instrument multi-agent systems, see the agent topology, and catch ping-pong loops, reasoning-action mismatches, and task derailment.
Multi-Agent Traces
When several agents collaborate in one run, Retrace records which agent produced each span, draws the agent topology, and runs detectors built for the failure modes unique to multi-agent systems. Single-agent traces are completely unaffected — these fields are optional and the topology graph only appears when a trace has 2 or more distinct agents.
Every span can carry three optional fields:
| Field | Meaning |
|---|---|
agent_id | Stable id of the agent that produced the span |
parent_agent_id | The agent that delegated to it (the hand-off edge) |
agent_role | Human-readable role/persona, e.g. Planner |
Instrumentation
Python
Wrap a sub-agent's work in retrace.agent(...); every span recorded inside it (including auto-instrumented LLM calls) inherits the agent fields. Nesting expresses delegation — the inner agent's parent_agent_id is set to the outer one automatically.
import retrace
with retrace.agent("planner", role="Planner"):
plan = make_plan(task)
with retrace.agent("researcher", role="Researcher"):
facts = research(plan) # parent_agent_id = "planner"TypeScript
withAgent uses AsyncLocalStorage, so concurrent agents never clobber each other's context.
import { withAgent } from "retrace-sdk";
await withAgent({ id: "planner", role: "Planner" }, async () => {
const plan = await makePlan(task);
await withAgent({ id: "researcher", role: "Researcher" }, async () => {
await research(plan); // parentAgentId = "planner"
});
});Or set the fields on a single span directly: spanBuilder.setAgent({ id, parentId, role }).
Frameworks
- LangGraph — use the node name as the
agent_id. - CrewAI — use the agent's role as the
agent_idandrole.
OpenTelemetry
Retrace maps the OTel GenAI agent semantic-convention attributes automatically:
| OTel attribute | Maps to |
|---|---|
gen_ai.agent.id (or gen_ai.agent.name) | agent_id |
gen_ai.agent.description (or gen_ai.agent.name) | agent_role |
retrace.agent_id / retrace.parent_agent_id / retrace.agent_role | explicit overrides (win over gen_ai.*) |
The same fields are accepted identically over HTTP batch ingest, the WebSocket stream, and OTel — instrument once, send anywhere.
Topology view
Open any multi-agent trace and you'll see the Agent topology graph above the detections panel: each agent is a node (sized by span count), and arrows are control hand-offs with thickness proportional to frequency. Single-agent traces don't render the graph at all.
Detectors
| Detector | MAST mode | Plan | How |
|---|---|---|---|
| Agent ping-pong | Loop | All plans | Deterministic — two agents bouncing the same work back and forth (the shape of the classic runaway-cost incident). No LLM. |
| Reasoning–action mismatch | FM-2.6 | Pro+ | An LLM judge flags when an agent's stated plan contradicts the action it then took. Metered, idempotent. |
| Task derailment | FM-2.3 | Pro+ | Embedding distance between the task spec and the late-run steps — the agents drifted off the objective. Embedding-only, no judge spend. |
The two AI-powered detectors require the Inter-agent detectors feature (Pro and above) and only run on multi-agent traces. The ping-pong loop detector and the topology view are available on every plan. All three surface as standard detections in the trace's detections panel and the Insights → Failure Taxonomy breakdown.