The system is a multi-agent LLM pipeline that probes websites for security flaws. We run it only against systems we own or are authorised to test. A master 'thinking' agent coordinates specialised sub-agents. Tasks are routed to a cheap or an expensive model, and the system fails over between AI providers. After a long autonomous run with that many moving parts, the useful question is rarely whether it finished. It is which agent did what. A trace written for each sub-agent run is how we keep that question answerable.

What does each sub-agent trace record?

When a sub-agent run completes, its trace captures three things:

Traces are JSON files. Each file is named for the agent and stored under the scan it belongs to. A reviewer can open the record for a specific agent instead of searching one interleaved log.

Why persist the full system prompt alongside the transcript?

Keeping the full system prompt in the same file as the conversation means a reviewer reading a transcript also has the prompt that run started from, without leaving the trace. That pairing is the point. A transcript is harder to interpret if you have to reconstruct the instructions behind it separately.

If you adopt this pattern, decide exactly what the prompt field captures. It could be a template, or it could be the text after any runtime assembly. The two can differ, and a trace is most useful when you know which one you have.

Why keep the complete message history?

For an autonomous security probe, the path to a finding matters as much as the finding. The complete message history lets a reviewer read the steps a sub-agent took and what it saw before it reached its conclusion. In general, the detail an audit question needs is often the detail a summarised or truncated log has dropped. Storing the complete history keeps that detail available.

What does the token count tell you, and what doesn't it?

The total token count is a usage figure stored next to the transcript that produced it. It makes it possible to compare token usage across sub-agent runs and to read the conversation behind any total that looks unusual.

A token count is not a cost figure on its own. Tasks go to cheaper or more expensive models, and the system can fail over between providers, so the same token count can represent very different spend. If you want to attribute spend per agent, also record the model and provider that served each run.

When is the trace written?

The trace is written when the sub-agent run completes. Each file is therefore a finished record: prompt, conversation and final token total together. If you copy this pattern, decide early how to handle runs that are interrupted before completion. Make that choice during design, not during an incident.

Because files are named for the agent, also decide what happens if the same agent runs more than once in a scan. The options are to overwrite, append or write separate files. Each choice changes what a reviewer can reconstruct later, so it should be deliberate.

How does a per-agent trace help review a long autonomous run?

A long run involves many contributing steps. A questionable output at the end may trace back to an earlier decision by a different sub-agent. Splitting the record by agent lets a reviewer go straight to the sub-agent responsible for a finding. From there they can read the prompt it ran with, what it did and how many tokens it used.

'Replay record' here means a reviewer can read through what happened step by step. It does not mean the run can be re-executed with the same result. Model outputs and responses from the target site can change between runs. The trace documents the run. It does not reproduce it.

How should you adopt this pattern in your own agent system?

When something goes wrong in a long autonomous run, a per-agent record of prompt, transcript and token count gives you evidence instead of anecdote.