Localize where AI agents fork across repeated runs of the same task.
forkpoint is a deterministic, dependency-free (standard-library-only) analyzer for
agent execution traces. Give it several traces of the same task — as
OpenTelemetry gen_ai spans or a compact native format — and it builds a behavior
tree and pinpoints the primary fork step, the competing tool choices, per-step
divergence entropy, and argument volatility. It answers the question observability
dashboards don't: "My agent is flaky — at which decision does it actually split, and
into what?"
2026 research made agent non-determinism a first-class reliability metric.
When Agents Disagree With Themselves (arXiv:2602.11619) found ReAct-style agents
produce 2.0–4.2 distinct action sequences per 10 runs, that variance predicts failure
(consistent tasks hit 80–92% accuracy, inconsistent ones 25–60%), and — the key
insight — 69% of divergence lands on step 2, the first real query. Existing tools
(EvalView, AgentAssay) tell you that an agent is inconsistent via golden-snapshot
diffing or statistical pass/fail fingerprinting. None of them localize the split.
The smallest thing that proves the idea is a tool that ingests N same-task traces,
collapses them into a prefix tree, and reports the shallowest branch point with its
competing choices and information-theoretic weight — turning "it's flaky" into
"it forks at step 2 between web_search and wiki_lookup, 4 vs 2 runs." That is
forkpoint.
- Path consistency — fraction of runs on the single most common tool path.
- Primary fork — the shallowest step where runs first split, with the shared prefix, the competing continuations, their run counts, and normalized branch entropy.
- Divergence by step — runs-weighted normalized entropy at each depth, so you can see whether the agent forks once early or stays turbulent throughout.
- Argument volatility — for name-stable tools, which arguments actually vary (by
per-path value entropy), including partial-presence ("sometimes passes
limit"). - Stability score — a documented composite in
[0,1]for CI gating. - Behavior tree — an ASCII rendering of the whole fork structure with run shares.
No install needed — pure standard library, Python ≥ 3.11.
# Analyze the bundled example corpus (6 runs of one HotpotQA-style task)
python -m forkpoint analyze examples/
# Machine-readable output
python -m forkpoint analyze examples/ --json
# Treat differing tool arguments as forks (default branches on tool name only)
python -m forkpoint analyze examples/ --strict-args
# CI gate: fail the build if behavioral stability drops below a threshold
python -m forkpoint analyze examples/ --fail-under 0.8 # exit 1 if lower
# Or via make
make run # text report on examples/
make demo # text + JSON
make test # pytest suiteYou can pass individual trace files or a directory of *.json traces. To use it on
your own agent: run the agent N times on a fixed task, export each run's OTel gen_ai
spans to a JSON file, and point forkpoint at the folder.
OpenTelemetry gen_ai — a JSON object with a spans list (or a bare list of spans).
A span is a tool call when gen_ai.operation.name == "execute_tool" or it carries
gen_ai.tool.name. Arguments are read from gen_ai.tool.call.arguments (a JSON string,
per the convention). Non-tool spans (chat/LLM/retrieval) are ignored; spans are ordered
by start_time_unix_nano.
Native — for hand-written fixtures or non-OTel exporters:
{"task": "which-magazine-first",
"trajectory": [
{"tool": "web_search", "arguments": {"query": "Arthur's Magazine"}, "status": "ok"},
{"tool": "finish", "arguments": {"answer": "Arthur's Magazine"}}
]}$ python -m forkpoint analyze examples/
forkpoint — agent behavioral fork analysis
====================================================
runs analyzed : 6
distinct tool paths : 2
path consistency : 66.7% (4/6 on the modal path)
argument stability : 17.3%
STABILITY SCORE : 0.519 (highly non-deterministic)
PRIMARY FORK at step 2 (reached by 6/6 runs, norm. entropy 0.92)
runs agree through : web_search
competing choices :
• web_search 4 run(s)
• wiki_lookup 2 run(s)
divergence by step:
step 2 entropy 0.92 █████████· (6 runs, 2 continuations)
argument volatility (least stable first):
wiki_lookup stability 0% [2 calls] varies: title
web_search stability 10% [10 calls] varies: query
finish stability 35% [6 calls] varies: answer
behavior tree:
◆ root (6 runs)
└─ web_search [6] ████████████ 100%
├─ web_search [4] ████████···· 67% ⚠ FORK
│ └─ finish [4] ████████████ 100%
│ └─ ⟨end⟩ [4] ████████████ 100%
└─ wiki_lookup [2] ████········ 33%
└─ finish [2] ████████████ 100%
└─ ⟨end⟩ [2] ████████████ 100%
The corpus is six runs of "Which magazine started first, Arthur's Magazine or First for Women?" — deliberately built so all runs agree on the first call and then fork at step 2, exactly the pattern the research reports.
trace files ──► trace.py ──► [Trajectory] ──► tree.py ──► BehaviorNode (prefix trie)
(OTel / native) normalize ordered tool build │
calls ▼
analyze.py ──► Analysis (metrics)
│ │
▼ ▼
report.py ──► text + ASCII tree
cli.py ──► JSON / CI exit code
trace.pynormalizes either input format into a canonicalTrajectory(orderedStep(tool, arguments, status)). All parse failures raiseTraceErrorwith the file path — a malformed trace never silently degrades the analysis.tree.pyinserts every trajectory into a shared prefix trie. A node with >1 child is exactly a divergence point; end-of-run is a syntheticENDchild so "some runs stop early" counts as a fork too. Nodedepth= tool calls taken to reach it, so a branch at depthdis the human-facing "fork stepd+1".analyze.pycomputes the metrics with Shannon entropy over run-weighted branch distributions; the primary fork is the shallowest branch node (ties → most runs → most entropy), and argument volatility flattens nested args to dotted paths.report.py/cli.pyrender text + ASCII tree or JSON, and expose the--fail-underCI gate.
- Multiple Sequence Alignment (MSA). Progressive pairwise alignment of all trajectories (like bioinformatics MSA) to line up steps even after insertions/deletions, then score column-wise consensus. Trade-off: most information-rich, but O(n²·L²) progressive alignment, a heuristic guide tree, and fragile, hard-to-explain results — overkill for a prototype and slow on long traces.
- Prefix trie of trajectories (chosen). Insert each run as a root path; shared prefixes merge; branch nodes are the fork points. Trade-off: O(total steps) time and memory, trivially deterministic, and directly explainable ("the tree shows the forks"). It assumes divergence is prefix-anchored — which is precisely the observed reality (early forks dominate; 69% at step 2), so the cheap model captures the phenomenon that matters. Argument volatility is handled orthogonally (per-tool entropy) so the trie stays about shape.
We chose the trie: it is linear, deterministic, self-documenting via the rendered tree, and matches the empirical structure of agent non-determinism. MSA would buy alignment robustness we don't need when the interesting forks are near the root.
- Same task in, meaningful out. All supplied traces must be runs of the same task; forkpoint measures behavioral variance, not correctness. Mixing tasks yields a meaningless tree (it will still run and warn on a single trace).
- Prefix-anchored view. A trie treats trajectories as sharing a common start. If
two runs take identical steps but shifted by one insertion early on, the trie sees
them as fully divergent from that point (no gap alignment). This is intentional
(see approach 2) and rarely bites because early forks dominate, but it means
forkpoint over-reports divergence for agents whose only variation is an occasional
extra early step. Use
--strict-argsdeliberately: it makes every argument difference a fork, which is stricter than most callers want by default. - Tool-call granularity. Reasoning/planning content inside LLM spans is not modelled — only the observable tool-call trajectory. Two runs that "think" differently but call the same tools read as identical (by design: behavior = actions).
- Stability score is a heuristic.
0.7·path_consistency + 0.3·argument_stabilityis a documented, tunable composite, not a calibrated probability. The raw components are always reported so you can gate on whichever matters to you. - Argument volatility is position-agnostic. It pools all invocations of a tool regardless of where in the trajectory they occur; a tool called at different depths with different args reads as volatile even if each position is internally stable.
MIT — see LICENSE.
See RESEARCH.md for the frontier signals that motivated this experiment.