Judgment is now publicly available.Get started

TrajectoryStore: Agent data has a new form

Agents resend the same chat history on every call. Here's how we store each message once, using 63× less data to store our internal coding agent's trajectories and running searches over them 10× faster.

Alan Zhang, Abhishek Govindarasu, Andrew Li10 min read

Agent data has outgrown traditional tracing

As long-horizon agents and agent swarms take on more and more of the world's work, they're creating a huge amount of valuable trajectory data. AI teams want to store, search and analyze these trajectories at scale to build better products, whether that means uncovering insights, finding and fixing issues, curating datasets for post-training or improving their agents with feedback from production.

Today, most teams store this data with tracing standards such as OpenTelemetry (OTel). These standards were designed for traditional software, such as cloud apps and microservices, where each step in a trace, like an HTTP request or a database query, records mostly unique data. Agents don't work this way: each LLM call builds on the ones before it and resends much of the same chat history, so the trace stores a new copy every time. The longer an agent runs, the more copies pile up, and the harder the data becomes to search.

That's why agents need new data infrastructure. We built TrajectoryStore, a new data model and storage layer, around how agents actually work. It follows two principles:

  • Stored once: Each distinct message, tool call and tool result is hashed and stored once, instead of being saved again with every call.
  • Easy to search: Each message, tool call and tool result is its own item, so a search reads each one once instead of scanning every copy of the chat history.

The same chat history, nested and stored over and over

In OTel, each trace is made up of spans, and each span records one operation, such as an HTTP request. Details about that operation, such as the request method, URL and response status, are saved as key-value pairs called attributes.

According to OTel's conventions, when you trace an AI agent, each request to the LLM provider becomes a span, and the chat history sent with it is saved as a span attribute. So as the agent runs, each request creates a new span with its own copy of the chat history. Most chat APIs don't remember earlier requests, so each request has to include the whole chat history so far.

while agent_is_running:
    with tracer.start_as_current_span("chat") as span:
        span.set_attribute("gen_ai.input.messages", json.dumps(messages))  # full chat history
        reply = llm.chat(messages)
    messages += [reply, *run_tools(reply)]  # history grows, next span saves it all again
Simplified instrumentation: each LLM call gets its own span, and the whole chat history is saved on it again.

These spans are then exported to storage, such as files in S3 with OTel's S3 exporter, or one row per span in a database with its ClickHouse exporter. That works for HTTP requests, where each span mostly has its own data. But with LLM calls, the same messages get stored over and over, and each one is buried inside a span, so you have to unpack it before you can search it.

Let's look at an example. A developer asks a coding agent: "The login test is failing. Can you fix it?" The agent reads the auth file, then runs the tests and checks recent changes at the same time, calling the LLM again after each step. Here's how those calls are stored:

Incoming1 event in this turn10UserYes, go ahead.LLM call NSends the accumulated historyS3s3://traces/2026/12/01/batch-0042.jsonSpans are batched into JSON files.{"spans": [span "chat" · call 1gen_ai.input.messages: "[12]"span "chat" · call 2gen_ai.input.messages: "[1234]"span "chat" · call 3gen_ai.input.messages: "[12345678]"span "chat" · call 4gen_ai.input.messages: "[12345678910]"span "chat" · call Ngen_ai.input.messages: "[12……]"]}ClickHousetracesOne row per span.SpanIdSpanAttributes7f3a9c21{'gen_ai.input.messages':'[12]'}b04e6d18{'gen_ai.input.messages':'[1234]'}2c95f3a7{'gen_ai.input.messages':'[12345678]'}9e07d4b2{'gen_ai.input.messages':'[12345678910]'}518fd03e{'gen_ai.input.messages':'[12……]'}24input messages stored per destination10distinct input messagesnew messagecopy an earlier span already storedEach new call stores the whole chat history again.

This run shows two problems with storing agent data this way:

1. The same chat history is stored again and again.

Neither exporter checks whether a span's input was already stored in an earlier span, so every file or row gets its own copy of the conversation so far. That takes up more storage, and every search has to read through the copies too. Here's what each call sends:

Call 1: the system prompt 1 and the user request 2. The LLM asks to read the auth file.

Call 2: the system prompt 1 and user request 2 again, plus the tool call 3 and the file's contents 4. The LLM asks to run the tests and check recent changes at the same time.

Call 3: everything from call 2 1 2 3 4 again, plus the two tool calls 5 6 and both results 7 8.

…

Call n: everything from every earlier call again, plus whatever is new.

By the third call, the user request has been stored three times and the auth file twice. Each call adds only a few new messages but stores the whole history again, so the total stored grows with the square of the number of calls, or O(n²), while new messages grow linearly. An agent that makes hundreds of calls stores the same messages hundreds of times.

Why not just store the newest messages in each span?

This breaks in a few common cases: parallel tool calls, and when the agent edits its own chat history, for example by compaction or rewriting a message. If you store only the last message, you can miss messages. When the agent asks for two tools at once, the next call adds both results, so one of them would never be recorded.

To store every new message instead, you have to know which ones are new. Each span is recorded on its own, so its message list doesn't mark where the previous call's messages end and the new ones begin. You'd have to look up the previous span's message list and compare it with the current one.

Storing only the newest messages breaks in other cases too. If the agent edits its own chat history, for example by compaction or rewriting a message, comparing lists can't tell you exactly what the LLM was given. We explain why comparing lists isn't a reliable way to remove the copies in What about compaction and edits? below.

2. Searching means reading every copy.

As the animation shows, each span stores its chat history as one JSON string: inside the span's JSON in S3, and inside its attributes column in ClickHouse. To find one message, a search has to read every span's full chat history, so it scans the same messages once per call. Then it gets each match back once per call and has to sort out which ones are copies. In S3, a trajectory's spans can also be spread across many files, since the exporter writes spans in batches as they arrive. So you first have to find and read every file that holds part of the trajectory.

What TrajectoryStore does

TrajectoryStore fixes both problems by storing chat history as items instead of inside spans. Each distinct message, tool call and tool result is stored once, as its own item, and each LLM call keeps an ordered list of the hashes of the items it was given.


Note: You can keep sending traces through OTel or Judgment's SDK, and the conversion happens when they're stored.

Stored once

When a call comes in, we split its chat history into items: each message, tool call and tool result. We hash each item, so the same item always gets the same hash and ends up stored once, no matter how many calls resend it. Then we save the call with an ordered list of the hashes it was given.

Incoming1 event in this turn10UserYes, go ahead.LLM call NSends the accumulated historyItems, each stored onceEvery item is hashed. A resent item is already stored.Each call: hashes given → hashes producedA call keeps only the ordered list of hashes, not copies.10+items stored28+hashes referenced by calls19f2c…“You are a coding agent…”type: messagerole: system241ab…“The login test is failing. Can you fix it?”type: messagerole: user3c07e…read_file("auth.py")type: tool_calltool: read_file45d19…def login(user, token): …type: tool_result5e8a3…run_tests()type: tool_calltool: run_tests62b6f…git_log()type: tool_calltool: git_log7a74d…FAILED test_login: token not checkedtype: tool_result80c5e…yesterday: "remove token check"type: tool_result973f1…“Should I restore the token check?”type: messagerole: assistant10b29a…“Yes, go ahead.”type: messagerole: user…call 1[12][3]call 2[1234][56]call 3[12345678][9]call N[12…10…][…]Each distinct item is stored once.Each call adds its ordered list of references.

Here's the same coding agent run. Each number stands for an item's hash:

Call 1: is given the system prompt 1 and the user request 2. The LLM replies with a tool call to read auth.py 3. All three are new, so all three are stored. The call saves input [ 1 2 ] and output [ 3 ].

Call 2: is given items 1–4. Only the file's contents 4 are new. The LLM asks for two tools at once 5 6. The call saves input [ 1 2 3 4 ] and output [ 5 6 ].

Call 3: is given items 1–8. Only the two tool results 7 8 are new. The LLM asks the developer a question 9. The call saves input [ 1 2 3 4 5 6 7 8 ] and output [ 9 ].

…

Call n: adds only what's new, and saves the full list of everything it was given.

The user request is stored once, no matter how many calls reuse it. Each call still keeps its full ordered list, so you can rebuild exactly what the LLM was given. That's the simple case, where the chat history only grows.

What about compaction and edits?

The run above only adds messages, but agents also change their chat history between calls. Two common cases:

  • Compaction: the agent replaces earlier messages with a summary to stay within the context window.
  • Editing a message: the agent rewrites or shortens one message.

Compaction. Say that after call 3, the agent compacts items 3–8 into one summary, item 9, and the developer adds a follow-up, item 10. TrajectoryStore saves:

Call 3[ 1 2 3 4 5 6 7 8 ]Call 4[ 1 2 9 10 ]

Items 3–8 stay stored, so call 3 still points to them. Only 9 and 10 are new. A “new only” span can't capture this. It saves just 9 and 10, and adding those to call 3's input gives [ 1 … 10 ], which puts back the six items the agent removed. Each call's own ordered list is what keeps call 4 exact.

Editing a message. It works the same way, just with a smaller change. Say the agent shortens the file contents 4 before call 4. The shorter version is a new item, 11:

Call 3[ 1 2 3 4 5 6 7 8 ]Call 4[ 1 2 3 11 5 6 7 8 … ]

Item 4 stays stored, so call 3 still points to the full file. Only 11 is new.

Either way, anything new or changed becomes a new item with its own hash, nothing already stored is overwritten, and each call's list records exactly what it was given. We still recommend keeping earlier messages stable where you can, because LLM providers cache the unchanged beginning of a prompt.

Because each message, tool call and tool result is stored once as its own item, a search reads each one once. People and AI agents can filter on fields such as type, role and tool name directly, without reading every span's chat history or removing copies from the results.

Take “What were the last 10 user requests?” on the first two calls from the run above. In OTel, each span's chat history is one JSON string, so it has to be parsed before it can be searched. In TrajectoryStore, each item is stored once and its fields are stored separately, so the query filters on the role field directly.

What were the last 10 user requests?The first two calls of a coding-agent runIncoming1 event in this turn4Tool resultContents of auth.pyLLM call 2 of N4 input events12343OTel removes the copyOTel spansTrajectoryStore123FROM tracesARRAY JOIN JSONExtract…WHERE …'role') = 'user'GROUP BY TraceId, request7f3a9c21 · SpanAttributes"role": "system" You are…"role": "user" The login…b04e6d18 · SpanAttributes"role": "system" You are…"role": "user" The login…"type": "tool_call""type": "tool_result"1 match, afterremoving the copy1FROM itemsWHERE type = 'message' AND role = 'user'9f2c… role: system"You are a coding…"41ab… role: user"The login test is…"c07e… tool: read_fileread_file("auth.py")5d19… type: tool_resultdef login(user, …call 1: 9f2c 41abcall 2: 9f2c 41ab c07e 5d191 matchSimplified example. Both queries are simplified.

In OTel, the query first splits every span's JSON string into separate messages, then keeps the ones where the role is user. The developer's request was sent with both calls, so it matches twice, once per span, and the query has to group the matches to remove the copy. In TrajectoryStore, the query checks the role field on each item. The request is stored once, so it matches once, with nothing to unpack or remove. With two calls that's one extra copy; with hundreds of calls, every user message comes back hundreds of times.

Here's how each setup handles the three cases:

QuestionOTel spansDeduplicated OTel (new messages only)TrajectoryStore
Chat history only grows: Where did the developer mention “login”?Each matching message comes back once for every call that resent it, so remove the copiesEach message, onceEach message, once
After compaction: What was the LLM given on call 40?Read call 40's chat history, a full copyAdding up the new messages from calls 1–39 puts back the messages the agent compacted awayLook up call 40's list of hashes
After an edit: Which version of a file did call 40 see?Read call 40's chat history, a full copyThe shortened file is saved as a new message, but nothing records that it replaced the originalCall 40's list of hashes points to the shortened version, and the original is still stored
Green: WorksYellow: Works, but stores or reads every copyRed: May not be able to reconstruct the exact input

Storing only new messages removes the copies, so it handles the first case. It breaks on the other two: once the agent compacts or edits its chat history, it can no longer tell you what each call was given.

This matters most when an AI agent is doing the searching. Data agents and MCP tools don't know how each team's trajectories are stored, so they spend their first steps figuring out where messages are, how to unpack them and which ones are copies. With TrajectoryStore, every trajectory is stored the same way, so they can go straight to the question. We cover how our data agent searches trajectories in our blog Searching a billion tokens of agent data.

Results

We tested TrajectoryStore on a week of traces from Luna, our internal coding agent: 1,494 sessions and 79,360 LLM calls from Nov 14–21. We stored the same trajectories three ways:

  1. Standard OTel: spans as OTel's default ClickHouse exporter stores them, with each call's full chat history.
  2. Deduplicated OTel*: each span keeps only the messages that weren't in the previous call. This is the "store only the new messages" approach from above.
  3. TrajectoryStore: each message, tool call and tool result is stored once, and each call keeps its ordered list of hashes.

We compared them on how much data each one stores, and on how well a data agent can search it.

Storage

Standard OTelDeduplicated OTel*TrajectoryStore
Test week (Nov 14–21)92 GB2.3 GB1.5 GB
All of November265 GB7.2 GB4.5 GB
Less than standard OTel—~40×~60×
Keeps each call's exact input after compaction or editsYesNoYes

Almost all of the gap is copies. Across the week, the chat histories sent with all 79,360 calls added up to 19 GB, but only 0.37 GB of that was messages being sent for the first time. The other 98% was the same messages, sent again with later calls. Deduplicated OTel* removes most of those copies too. On LLM calls alone, deduplicated OTel* is smaller than TrajectoryStore (0.76 GB vs 1.5 GB for the week), since TrajectoryStore also keeps a search copy and each call's list of hashes. The difference is what each one keeps.

The savings grow with trajectory length:

And the gap holds across a month:

A data agent using SQL answered 30 debugging and analysis questions against all three setups, twice each, with questions such as “Which sessions hit a provider error?” and “What were the first 10 tool calls in this session?” Each question comes down to full-text search over messages plus filters on metadata like session, time and tool name, so we measured how much data each search read and how long it spent in SQL.

Standard OTelDeduplicated OTel*TrajectoryStore
Data read406 GB70 GB41 GB
Time spent in SQL806 s127 s81 s

TrajectoryStore's searches read 10× less data than standard OTel's and spent 10× less time in SQL. Removing the copies does most of the work: deduplicated OTel* already reads about 6× less data than standard OTel. TrajectoryStore still read about 1.7× less data than deduplicated OTel* and spent about 1.6× less time in SQL, because span tables also hold tool and wrapper spans, and a span's attributes are read together.

Conclusion

Agent data has a new form. Most of it is the same chat history sent again with every LLM call, and tracing stores each of those copies inside a span without recording what each call was actually given.

As agents take on more work, these trajectories are becoming some of the most valuable data AI teams have. Teams use them to understand why an agent failed, to curate data for post-training and to improve their agents with feedback from production, and all of that gets harder when the same messages are stored hundreds of times and nested inside JSON. That's why we think agents need their own data infrastructure, and why we started with the data model.

TrajectoryStore stores each message, tool call and tool result once, keeps the exact list of what every call was given, and makes every trajectory fast to search for both people and agents.

This is the first step. Agents are quickly turning into larger multi-agent systems, with sub-agents, parallel agents and agent swarms. Recording how those pieces fit together, including which agent saw what and how its context was built, is the next problem we're working on.