When a Multi-Agent Run Fails, How Much Does It Matter to Locate the Exact Agent and Step?
Project: https://github.com/atliliw/langchainrust
A task is handed to a multi-agent system. In the end, all the caller gets is:
Report generation failed If the task passed through several agents, that message alone tells you very little:
User request ↓ Supervisor assigns the work ↓ Researcher collects material ↓ Writer drafts the report ↓ Report generation failed ❌ Did Researcher return nothing? Did a handoff drop a field? Or did Writer read its context incorrectly?
This article uses the LangChainRust 0.33.0 implementation to describe the debugging problem we ran into, and how a decision ledger records and queries the key steps.
The failure scenario and query results below are illustrative, used to explain the debugging method.
The short answer: how much does it matter?
A single multi-agent run can fail at any decision point: the wrong worker was chosen, the wrong context was passed, a handoff dropped a field, an output was overwritten, or one round simply went off track. If a run has N tool calls and R routing rounds, there are N+R candidate causes; an API that returns only the final string collapses them into one “it failed”.
Locating the responsible step directly affects three costs:
| Cost | Without a ledger |
|---|---|
| Mean time to repair | You can only re-run the whole chain and add logs until it reproduces |
| Re-run expense | With many rounds and long contexts, tokens and time are multiplied |
| Side-effect safety | With write operations, you cannot tell which step ran twice or should have been blocked |
The reverse is also true: for a single agent, a linear chain, and no tool side effects, ordinary tracing is usually enough. A ledger is not mandatory there.
1. What goes wrong when there is no unified record
Multi-agent systems rarely have no records. They have different records for different orchestration styles:
| Orchestration | Existing record | What goes wrong during debugging |
|---|---|---|
| Supervisor | worker execution history | no unified persisted exit for the run |
| Swarm | a list of handoffs | details are unavailable if the caller did not receive or store them |
| GroupChat | a conversation transcript | the speeches are visible; the reason for choosing a speaker may not be |
| LangGraph | graph state and checkpoints | good for saving and resuming state, not a complete decision chain |
For the report task above, suppose the caller only stored the final result:
Final output: Report generation failed But we still want to know: Who did the Supervisor hand the task to? Did Researcher finish? In which call did Writer fail? That information may be scattered across different records, or never saved at all. With parallel or nested calls, log order alone is often not enough to tell which route an error belongs to.
If your existing logs and traces already record this completely and can be correlated by step, use them. The problem here is the case where existing records are not sufficient for a unified query and for correlating decision steps.
2. The solution: a decision ledger for each run
A “ledger” here means a record of the key actions in one task run.
It is not a new agent, and it is not one ledger per agent. One task has one run_id, and the orchestrators involved can write their key actions under that run.
For example, when Supervisor calls Writer, two records may be produced:
Record 1: Supervisor decided to hand the task to Writer Record 2: Writer failed (or finished) The important part is not the number of records, but that they share:
- one
run_id; - a monotonic
seq, so order is deterministic; -
step_id/parent_step_id, so nested calls form a tree.
That is what makes “which step caused the error” answerable.
3. Walkthrough: from the error to the handoff
Assume the run ID is run-123. Querying the ledger shows (simplified for readability; the real CLI also prints alignment, reasons, and output hashes):
run run-123 [ 1] Supervisor route Supervisor -> Researcher [ 2] Supervisor stage Researcher -> - [ 3] Supervisor route Supervisor -> Writer [ 4] Supervisor error Writer -> - error: missing research_summary These four records tell us:
| Step | What happened |
|---|---|
| ① | Supervisor handed the task to Researcher |
| ② | Researcher finished |
| ③ | Supervisor handed the task to Writer |
| ④ | Writer failed because research_summary was missing |
At this point the search space is narrowed to Writer's input and the handoff immediately before it.
Step 1: find the failing agent
Start with the error record:
[4] Supervisor error Writer -> - error: missing research_summary Supervisor means who wrote the event; Writer means which worker failed. The error message says Writer was missing research_summary.
Note that record ② (stage) only says Researcher's execution completed. It does not prove that the content Researcher produced was correct.
Step 2: find the route that triggered Writer
Event order alone is not enough. In a real system, several tasks may interleave.
So we look at the parent-child relation in addition to seq. lc ledger show does not print parent_step_id; open ./runs/run-123.jsonl for the full event.
With jq installed:
jq -c 'select(.seq == 3 or .seq == 4) | {seq, kind, step_id, parent_step_id, from, to, task, error}' ./runs/run-123.jsonl For readability, here are the relevant fields expanded. Suppose the events recorded:
{ "seq": 3, "kind": "route", "step_id": "run-123#3", "from": "Supervisor", "to": "Writer", "task": "write the report from the collected material" } { "seq": 4, "kind": "error", "step_id": "run-123#4", "parent_step_id": "run-123#3", "from": "Writer", "error": "missing research_summary" } They line up as:
Supervisor → Writer record 3: Route └── Writer error record 4: Error The lookup is direct: take the parent_step_id of record ④ and match it against another event's step_id.
Once it matches record ③, we know the error was recorded inside the execution that Supervisor routed to Writer. Even if other agents' events are interleaved, we do not have to guess from “the previous line”.
That said, task in record ③ is only the task text. It does not by itself prove which fields Writer's full context contained.
Step 3: find where the field was lost
Suppose the business system separately stored sanitized debug logs for this run, retrievable by run_id=run-123:
Researcher output: {"research_summary": "comparison of product A and product B"} Context Writer actually received: {"task": "write the report from the collected material"} Put them side by side:
Researcher output Writer's actual input ┌───────────────────────┐ ┌──────────────────────┐ │ research_summary: yes │ → │ research_summary: no │ └───────────────────────┘ └──────────────────────┘ the field was lost between the two observation points Now we can rule out “Researcher never produced the field” and narrow the problem to after the output and before Writer reads it. Next, inspect the code that processes the result in Supervisor and assembles Writer's input.
Suppose the code indeed passes only task to Writer and does not put Researcher's result into the research_summary field Writer expects. The fix is to map the research result into Writer's input contract at the handoff, and verify the field exists before Writer runs. Re-run the same kind of task afterward and check both that Writer receives the field and that the error no longer appears in the ledger.
Those two business logs and the code inspection are also illustrative; they are not generated automatically by the decision ledger, and they are not a conclusion about a real defect in the repository. In a real investigation, find the evidence first.
Different findings lead to different directions:
| What to check | Where to look if it is wrong |
|---|---|
| Did Researcher produce the field? | collection step and output format |
| Was the field passed to Writer? | routing task and context assembly |
| Did Writer read it correctly? | Writer's input handling |
If neither Researcher's output nor Writer's input was stored, you can only establish “Writer reported a missing field”; you cannot tell where it was lost. Add sanitized observation at the right points and reproduce the issue.
The whole loop:
ledger finds the error → find the route that triggered it → compare upstream/downstream data → fix the handoff → re-verify 4. What is in a decision event?
Still using the Writer error, the most commonly used fields are:
run_id run-123 which run seq 4 which event in the run kind error what happened from Writer which agent error missing research_summary error content parent_step_id run-123#3 which enclosing step Different actions use different event types:
| Event | Meaning | Example |
|---|---|---|
Route | assign work | Supervisor chooses Writer |
Handoff | transfer control | Swarm switches from one agent to another |
Select / Speak | choose / speak | GroupChat picks a member to speak |
Stage | execution stage | a worker completes one execution |
Error / Finish | fail / end | record the run status |
Events also carry round, task, reason, input/output hashes, and more. Which fields an orchestrator actually fills depends on its implementation.
5. How the code records and links steps
Using Supervisor as an example: after choosing a worker, it writes Route before executing the worker.
choose worker ↓ write Route ↓ execute worker ├── success → write Stage └── failure → write Error The routing record, excerpted from the source:
let route_step = ctx.record_with(|| { DecisionEvent::new(DecisionKind::Route) .orchestrator("Supervisor") .round(round + 1) .from("Supervisor") .to(worker.clone()) .task(task.clone()) .reason(decision_text.clone()) .input_hash(envelope_hash.clone().unwrap_or_default()) }).await; let worker_ctx = ctx.clone().with_parent_step(route_step); Two key actions:
- Record the route before executing the worker.
record_withreturns the route event'sstep_id. If the worker later fails, the already-written route can still be queried. - Pass the route step into the child context.
with_parent_step(route_step)carries that ID into the worker's context. Errors later recorded through that context fill inparent_step_id.
So finding the route through parent_step_id is not the CLI guessing from event order; the association is written at execution time.
Common fields such as run_id, seq, and step_id are filled by RunContext; each orchestrator does not assemble them by hand.
Source: crates/lc-agents/src/orchestrator/supervisor.rs.
6. Enabling and querying it in a project
Attach the ledger
The example uses JSONL storage. Create the ledger and attach it to the run context in async code:
use std::sync::Arc; use lc_agents::orchestrator::{Orchestrator, RunContext}; use lc_observability::JsonLinesLedger; let ledger = Arc::new(JsonLinesLedger::new("./runs").await?); let ctx = RunContext::new("trace-123") .with_run_id("run-123") .with_ledger(ledger); Then pass this ctx to an orchestrator that has ledger support:
let result = orchestrator.run_with_context(input, &ctx).await; If you only depend on the facade crate, the equivalent paths are langchainrust::agents::RunContext and langchainrust::JsonLinesLedger (enable the observability feature).
orchestrator and input stand for the orchestrator and input your project already has; the snippet is an integration fragment, not a standalone program.
Events are written to ./runs/run-123.jsonl. If you create the ctx but never pass it to an orchestrator, no events are recorded through it.
Give each independent run its own run_id and write that ID into your application logs. When something goes wrong, you can go from the business request to the ledger file and correlate the two by the same ID.
Query the events
After installing the project's lc CLI, use the same run ID and directory:
lc ledger show run-123 --dir ./runs For a template-generated text summary:
lc ledger explain run-123 --dir ./runs The two commands serve different purposes:
| Command | What it shows |
|---|---|
show | event type, participants, reasons, errors, and other selected fields |
explain | a text summary generated from the events; no model call |
Note: show does not print parent_step_id. To verify parent-child relations as in the walkthrough, inspect the JSONL file or read the events through RunLedger::load.
Both CLI commands read a JSONL directory today; they do not connect to SQLite or Postgres automatically.
7. How other patterns record
Different orchestrators perform different actions, but they map onto the same event model:
Supervisor Route → Stage / Error Swarm Handoff → Handoff → ... GroupChat Select → Speak → Select → Speak PlanExecute Plan → Stage → Stage / Error Reflexion Attempt → Attempt → ... The goal is a uniform query format, not identical content for every pattern.
For example, TreeOfThoughts and LATS may explore a large number of nodes. The implementation records summary events to bound the volume, so the ledger cannot reconstruct every search node.
LangGraph nodes can also record stage, error, or interrupt events. To let graphs and agents share event types, the model and interface live in the low-level lc-shared; lc-core re-exports them.
But sharing an event model does not mean sharing a sequence counter automatically. LangGraph and agents each maintain their own counters; if they interleave writes under the same run_id, resolve sequence conflicts and cross-component parent links first.
8. Boundaries before adopting it
8.1 The ledger is optional
With no ledger attached, record_with never executes the event-building closure, so the hashes inside it are never computed.
Built-in orchestrators are best-effort: if a ledger write fails, they log a warning and keep going. The ledger may therefore be incomplete.
Use record_checked when the caller must handle write errors; strict auditing also needs to confirm that a ledger is actually attached.
8.2 Payloads are off by default, but that does not mean no user content
The default policy does not store input/output payloads, but task, reason, and error may still contain user content.
Before going live, inspect what is actually recorded and apply the redaction, access control, and retention your business requires.
The current hash is FNV-1a: useful for comparing content, not encryption, and not a guarantee that the original text is safe.
8.3 Storage is selectable, with different boundaries
| Storage | Suitable for | Caveat |
|---|---|---|
| Memory | debugging | records disappear when the process ends |
| JSONL | file-based storage and query | do not have multiple processes write the same directory concurrently |
| SQLite / Postgres | database storage | enable the corresponding feature and configure the database |
They share the RunLedger interface and deduplicate on (run_id, seq), but concurrency and durability boundaries differ.
If a JSONL file ends with a partial line, the next append separates it; loading skips unparsable lines. The already-corrupted event is not recovered.
Final
Back to the opening example:
record 4 error → find Writer ↓ parent_step_id → find record 3 (the route) ↓ compare upstream/downstream data → narrow where the field was lost ↓ inspect and fix the handoff code → re-run and verify A decision ledger connects the key steps that were recorded, giving debugging a clearer starting point. It does not replace business logs, and it does not determine the root cause automatically.
Verification note: the relevant test code was compile-checked but not run. The failure, events, and output in this article are illustrative.

