Hierarchical Map Reduce for Trace Science
November 25, 2026
TL;DR. I built
tracepress, an open source tool that lets you extract information from gigabytes of agent traces at once by layering language model map and reduce operations into a hierarchy. You can write the hierarchy code yourself with the tracepress python package, or you can simply tell your coding agent to use the skill:npx skills add Ziems/tracepress.
Traces are the new oil [1]. They’re ripe with useful information about model behaviors, alignment, harness issues, user frustration, etc. But much of this information is subjective and “fuzzy” making it hard to accurately measure. A straightforward solution is to spend lots of time looking at the raw trace data, but even one long horizon trace is often too long for any individual to read, so understanding all of them in bulk is practically intractable.
Plenty of issues bubble up as a result. When designing a harness or training/evaluating a model, things often silently fail or misbehave (e.g. reward hacking or doom loops) despite all the surface level WandB metrics looking reasonable. It is often only after training has finished when significant issues are discovered (see FelonyBench [2]).
Similarly, in production settings it’s difficult to find out what issues users are encountering, what production domains and situations aren’t captured in the offline evals if there’s no effective way to dig through traces and measure relevant properties in bulk. If the relevant “fuzzy” properties aren’t measured, it is also difficult to do data science-y experiments such as testing whether one approach (harness, model, or other) leads to more favorable user satisfaction than some other approach, whether the latest open source model is reliable enough for production, whether the latest harness change is causing regressions and users are getting frustrated, etc. Without understanding and measuring what is going on under the hood in the first place, quality evals for complex AI systems become incredibly difficult. Since there’s so much overlap between data science and the work people need to do with traces, I’ve started calling this kind of work “trace science”.
After one gives up on reading the traces directly, the most common approach used for trace science right now is simply pointing coding agents like Claude or Codex at a large json dump of traces and asking some vague question like “What is causing my model to fail”. The agents see the large file and decide to dig through it by throwing around some narrow regex calls instead of looking at the actual data. As a result, almost all the important information is missed, lots of expensive reasoning tokens are burned, and time is wasted. So what would a better solution look like?
I’ve tinkered with a few different approaches for trace science over the past few weeks and boiled it all down to the following set of desirable qualities for such a tool. The ideal solution likely:
- Doesn’t presuppose what information a user is looking for. It must be flexible enough that a user is constrained not by the tool they’re using, but instead by the questions they think to ask.
- Analyzes every part of every trace completely, but features mechanism which allow the most important information to bubble up from the noise.
- Uses language models to do the heavy lifting as it will rely almost entirely on semantic judgement
- Needs to be fast and relatively inexpensive, so it likely processes lots of information in parallel rather than sequentially, and is simple enough that it doesn’t require frontier models for everything
The most effective solution I’ve found is a hierarchical map reduce which uses language models for both the map and reduce operations. Given a long horizon agentic trajectory, it is first broken into separate steps before a single query is used to “process” the selected items from each step such as the message, reasoning, tool_use, environment_feedback, etc. This lm_map operation is done on each step in the trace in parallel with each one using the same query. For instance, a simple query for this level in the hierarchy might be “Summarize this step”. After running this, you get a concise summary of what happened at each step, significantly reducing the amount of time you have to spend reading your traces. Liana Patel’s LOTUS project pioneered many of the core ideas in this direction [3].
We’re just getting started, but before we get ahead of ourselves lets load up some raw data and see how it works in practice. Any kind of agent trace should work here, but I’ll use Terminal-Bench [4] tasks from the Harbor Hub [5] as my example. I’ve made a built in helper that loads local Harbor jobs traces into a few different DataFrames. To follow along, install Harbor and download the same job, Terminal-Bench’s own run of Opus 5 on Terminal-Bench 4.0 (66 tasks, 330 trials, about 4 GB):
uv tool install harbor
harbor jobs download 7595dfd2-22f0-4b03-81a9-c3c22b6ae047 -o jobs/opus-5
import tracepress as tp
# load traces from a local harbor job
job = tp.read.harbor(
"jobs/opus-5", tasks=["mvcc-lsm-compaction", "embedding-drift-monitor"]
)
steps = job.steps.to_pandas()
steps[["trial", "step", "source", "message", "tool_calls"]].head()
| trial | step | source | message | tool_calls | |
|---|---|---|---|---|---|
| 0 | embedding-drift-monitor__2862624b | 1 | user | The embedding drift monitor at `/app/drift_moni... | |
| 1 | embedding-drift-monitor__2862624b | 2 | agent | I'll start by exploring the codebase. | Bash: find /app -type f | grep -v '.git/' | hea... |
| 2 | embedding-drift-monitor__2862624b | 3 | agent | Bash: cd /app/drift_monitor && for f in *.py; d... | |
| 3 | embedding-drift-monitor__2862624b | 4 | agent | Bash: cd /app && python3 -c "\nimport numpy as n... | |
| 4 | embedding-drift-monitor__2862624b | 5 | agent | Now I'll fix each module. Starting with the lea... | Write: /app/drift_monitor/normalize.py |
Each row in the DataFrame is a separate step in a trace and has extra data to know which trial (or trace) it belongs to, which task it’s for, what role it came from (user, agent, system, etc.), its message, and any tool calls along with what they returned. Under the hood, the tables are lazy and no operations are actually run until the outputs are needed.
LM Map. Using this, we can run our first lm_map operation, which takes in the original Terminal-Bench task instruction, the source (user or agent), the message, and tool_calls from each step and has gpt-6-luna generate a summary of that step based on the given lm_map instruction (I often call this a query). It does this in parallel for every step in the entire trace.
# configure the language model used for analysis. Luna is cheap and works well.
tp.configure(lm="openrouter:openai/gpt-6-luna")
# adds each run's task instruction
steps = job.steps.join(job.trials, on="trial")
# map: summarize each step
step_summaries = steps.lm_map(
"instruction, source, message, tool_calls -> step_summary",
instructions=(
"This is one step of a coding agent working on the task in "
"`instruction`. In one short sentence (at most 20 words), say who did "
"what (the agent, the user or the harness) and what came of it, in "
"words a reader who hasn't seen the code can follow."
),
)
step_summaries.to_pandas()
The first argument to lm_map() is a DSPy-style signature [6] which controls the context the model sees and what it is meant to produce as output. The names left of the arrow are input columns, read from each row, and the names on the right are new columns the model fills in. Outputs are strings unless you give them a type, like frustrated: bool or kind: Literal['explore', 'edit', 'test'], in which case they come back as that type. Jev is supported for outputs with Jev friendly types [7].
Note we had to join two different information sources together so we could use an extra piece of information, instruction, as input to our map operation.
The output here is cast to a pandas DataFrame as well, but I’ve converted all the example outputs to be interactive so you can explore them easily.
The query and context given from each step can change depending on what you’re looking for. For example, if you’re looking for steps where a user was frustrated, it might be helpful to change the query to be “Is the user frustrated in this step?”. By default all outputs are strings, but in this case you may want a boolean flag to signal frustrated vs not frustrated and also generate an explanation. You can tab through the examples below to see how small changes let you ask wildly different questions.
LM Reduce. Of course, for some questions you may be trying to answer, the lm_map operation alone isn’t enough. For many kinds of questions, a language model needs to be able to look across all the steps at the same time to properly generate a good answer. For example, you may want a one or two sentence summary of what happened in an entire trace. This is where the lm_reduce operation comes in.
The language model is given all the summaries from the previous lm_map operation, which are now short enough that they can all be fit into a single context all at once. In this case, the instruction we use for the lm_reduce may be “summarize the whole run for a reader who hasn’t seen it. Start with what the agent was tasked with, then what it did, and say plainly whether it passed or failed. If it failed, use the failed checks and the steps to say why.” Besides the step summaries, the reduce also sees each run’s outcome and the hidden verifier tests it failed, data the agent itself never saw. When we run this on our step-level summaries, our hierarchy starts to grow and we get interesting data to dig into:
Growing the Hierarchy. You can add more operations to the map reduce hierarchy to ask broader questions. For instance, suppose you are looking at multiple trajectories/trials of the same task by the same model, as is found in Harbor/Terminal-Bench. You can get an overall summary of all the trials in the task by simply running a map->reduce operation on all 5 trials (as we did above), then run a final reduce on top. This lets you ask questions like:
- What failure modes are common between trials in this task for this model?
- What is the difference in behavior that causes some of these trials to succeed and some of these trials to fail?
- Here are all the traces from my Claude sessions. Where are the most tokens and time spent in these sessions?
For production systems that are deployed, one can build a similar map reduce hierarchy to ask:
- What common use cases are causing my users to get frustrated?
- What do users keep asking for that my product doesn’t support yet?
- What is going on right now in my agent swarm?
From here on, the examples run on a bigger slice of Terminal-Bench 4.1, using ten different tasks, with five trials each from five models’ public leaderboard runs. That’s ~200 trials and ~20k steps. Each task’s results now cover all five models.
Then lm_reduce the task-level results once more, for one answer across all models and all trials given.
Shaping the Hierarchy. So far the hierarchy has followed the straightforward shape of the data, with steps making up up trials, trials make up tasks, and tasks make up the job. But you can also reshape the same hierarchy to control the flow of information and ask more complicated questions too. For example, to compare models, group the same trace summaries by model instead of by task, reduce each model’s trials on their own, and only bring the groups together at the end in a final reduce that compares them. Nothing from one model reaches another’s summary until that last step, which lets you ask questions like:
- Between these five models, what differences in behavior make some of them perform significantly better than others across all the Terminal-Bench tasks?
- What is the difference in use cases between my power users, my average users, and the users that try my product once then never try it again?
DataFrames. These multi level hierarchies also have a nice property of interpretability. All the output layers can be cast as DataFrames, which makes them fantastic for trace science. Once a full hierarchical pipeline has finished running, the top level output may be some concerning conclusion, like “The agent is abusing some of its tool calls to hack into HuggingFace.” With multi level hierarchies, the attribution is built in so you can see exactly where this conclusion came from by simply looking at the inputs and outputs of each layer, conveniently represented in a DataFrame. If you want to dig into a reduce operation, you can look at each of the inputs it was provided to see where the conclusion came from. You can even “tweak” some of the inputs to see what the hypothetical outcome would be if circumstances had changed. The lm_map queries also have a convenient property of being entirely independent of each other, meaning you don’t have to worry about their outcomes affecting one another. Finally, representing the outcomes of each of these operations in the hierarchy as a DataFrame also makes it easy to connect with other sources of data to enrich it with additional relevant context (as we saw earlier with the join) or do cool data science-y things like generating data visualizations.
For example, to find which sources a deep research agent can trust, reduce each trace to where its final answer came from and whether it was right, then let pandas do the counting:
# one trace per research question
research = tp.read.otel("traces/deep-research/")
# reduce: where each trace's answer came from, and whether it was right
answers = research.steps.group_by("trace").lm_reduce(
"question, reference_answer, step -> answer_source: "
"Literal['internal docs', 'papers', 'wikipedia', "
"'news', 'blogs', 'forums'], "
"correct: bool",
instructions=(
"Which kind of source did the agent take its final answer from, "
"and does that answer match `reference_answer`?"
),
)
df = answers.to_pandas()
df.groupby("answer_source")["correct"].agg(["mean", "size"])
In about ten lines, that shows answers taken from forums were right less than half the time, even though forums were the agent’s third most common source.
Live Hierarchies. In many cases, you may have a map reduce hierarchy you want to keep continuously running so you can do real time observability (e.g. live dashboards, LLM-as-judge, reward hacking detection). Fortunately, this is quite easy to do. Each new piece of data gets folded in and triggers an update within the dependency graph, meaning only the parts of the hierarchy that depend on the new data will be re-run. In tracepress, this works by first starting a server via CLI and streaming trace data to it. The python sdk has handy helpers for both producers streaming traces and consumers who want to listen to the hierarchy pipelines. These hierarchy pipelines can be created, edited, and deleted as data streams in, meaning they can be tweaked in real time without causing major disruptions. Once you’re happy with your pipeline, you can register it to run continuously on the server. Any client you set up can then listen to the server for emitted information or events.
tracepress serve --port 7700
Optimization. In some cases you may have existing steps or traces which you’ve labeled as having some particular behavior, such as doom loops, reward hacking, or LLM-as-a-judge rubrics. Instead of trying to come up with a query hierarchy that properly matches these labels, you can instead use GEPA [8] to optimize the queries at each step in the hierarchy for you. Here it took under eight minutes, only a few cents, and gave a significant improvement with only ~150 labeled steps.
# trial, step, kind: what each step's tool calls actually did
labels = pd.read_csv("step_kinds.csv")
# map: classify what kind of step each one is
classify = step_summaries.lm_map(
"step_summary -> kind: Literal['explore', 'edit', 'test', 'other']",
instructions="What kind of step is this?",
)
tuned = classify.optimize(labels, metric="kind", optimizer="gepa")
tuned.optimize_report
Closing. I’ve only scratched the surface of what you can do with these hierarchical map reduce pipelines. It’s still in active development, but feel free to try it out yourself and see what interesting things you can find in your traces. You can install the library with uv add tracepress, but the easiest way is to just have your agent use the skill in the repo:
npx skills add Ziems/tracepress
If you find any interesting use cases, I’d love to hear about them.
- @samzliu. Traces are the new oil. X, September 2026. x.com/samzliu/article/2103613396625367437
- @Sauers_. FelonyBench. X, September 2026. x.com/Sauers_/status/2102878291111940537
- Liana Patel, Siddharth Jha, Melissa Pan, Harshit Gupta, Parth Asawa, Carlos Guestrin and Matei Zaharia. Semantic Operators: A Declarative Model for Rich, AI-based Data Processing (LOTUS). arXiv:2407.11418, 2024. arxiv.org/abs/2407.11418
- Mike A. Merrill, Alexander G. Shaw, Nicholas Carlini et al. Terminal-Bench: Benchmarking Agents on Hard, Realistic Tasks in Command Line Interfaces. ICLR 2026. arXiv:2601.11868. arxiv.org/abs/2601.11868
- Harbor: a framework for running and evaluating agents in containerized tasks. github.com/harbor-framework/harbor
- Omar Khattab et al. DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines. arXiv:2310.03714, 2023. arxiv.org/abs/2310.03714
- TypeSafe. Jev, TypeSafe’s first System One model, which answers typed decision outputs with probabilities instead of generating text. 2026. typesafe.ai
- Lakshya A. Agrawal et al. GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning. ICLR 2026. arXiv:2507.19457. arxiv.org/abs/2507.19457
Citation
If you find this useful, feel free to cite:
@article{ziems2026tracescience,
author = {Ziems, Noah},
title = {Hierarchical Map Reduce for Trace Science},
year = {2026},
note = {https://noahziems.com/trace-science},
}