agentfootprint 6.26.1 → 6.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +122 -108
  2. package/dist/core/agent/AgentBuilder.js +75 -1
  3. package/dist/core/agent/AgentBuilder.js.map +1 -1
  4. package/dist/esm/core/agent/AgentBuilder.js +75 -1
  5. package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
  6. package/dist/esm/index.js.map +1 -1
  7. package/dist/esm/lib/context-bisect/index.js +1 -0
  8. package/dist/esm/lib/context-bisect/index.js.map +1 -1
  9. package/dist/esm/lib/context-bisect/toBacktrackTrace.js +132 -0
  10. package/dist/esm/lib/context-bisect/toBacktrackTrace.js.map +1 -0
  11. package/dist/esm/lib/trace-toolpack/debugPrompt.js +36 -0
  12. package/dist/esm/lib/trace-toolpack/debugPrompt.js.map +1 -0
  13. package/dist/esm/lib/trace-toolpack/index.js +11 -0
  14. package/dist/esm/lib/trace-toolpack/index.js.map +1 -1
  15. package/dist/esm/lib/trace-toolpack/lazyToolpack.js +72 -0
  16. package/dist/esm/lib/trace-toolpack/lazyToolpack.js.map +1 -0
  17. package/dist/esm/lib/trace-toolpack/selfExplain.js +174 -0
  18. package/dist/esm/lib/trace-toolpack/selfExplain.js.map +1 -0
  19. package/dist/esm/lib/trace-toolpack/traceDebugAgent.js +40 -0
  20. package/dist/esm/lib/trace-toolpack/traceDebugAgent.js.map +1 -0
  21. package/dist/esm/lib/trace-toolpack/traceToolpack.js +11 -0
  22. package/dist/esm/lib/trace-toolpack/traceToolpack.js.map +1 -1
  23. package/dist/esm/observe.js +10 -1
  24. package/dist/esm/observe.js.map +1 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/lib/context-bisect/index.js +3 -1
  27. package/dist/lib/context-bisect/index.js.map +1 -1
  28. package/dist/lib/context-bisect/toBacktrackTrace.js +136 -0
  29. package/dist/lib/context-bisect/toBacktrackTrace.js.map +1 -0
  30. package/dist/lib/trace-toolpack/debugPrompt.js +39 -0
  31. package/dist/lib/trace-toolpack/debugPrompt.js.map +1 -0
  32. package/dist/lib/trace-toolpack/index.js +18 -1
  33. package/dist/lib/trace-toolpack/index.js.map +1 -1
  34. package/dist/lib/trace-toolpack/lazyToolpack.js +76 -0
  35. package/dist/lib/trace-toolpack/lazyToolpack.js.map +1 -0
  36. package/dist/lib/trace-toolpack/selfExplain.js +203 -0
  37. package/dist/lib/trace-toolpack/selfExplain.js.map +1 -0
  38. package/dist/lib/trace-toolpack/traceDebugAgent.js +44 -0
  39. package/dist/lib/trace-toolpack/traceDebugAgent.js.map +1 -0
  40. package/dist/lib/trace-toolpack/traceToolpack.js +11 -0
  41. package/dist/lib/trace-toolpack/traceToolpack.js.map +1 -1
  42. package/dist/observe.js +52 -36
  43. package/dist/observe.js.map +1 -1
  44. package/dist/types/core/agent/AgentBuilder.d.ts +25 -0
  45. package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
  46. package/dist/types/index.d.ts +1 -0
  47. package/dist/types/index.d.ts.map +1 -1
  48. package/dist/types/lib/context-bisect/index.d.ts +1 -0
  49. package/dist/types/lib/context-bisect/index.d.ts.map +1 -1
  50. package/dist/types/lib/context-bisect/toBacktrackTrace.d.ts +139 -0
  51. package/dist/types/lib/context-bisect/toBacktrackTrace.d.ts.map +1 -0
  52. package/dist/types/lib/trace-toolpack/debugPrompt.d.ts +20 -0
  53. package/dist/types/lib/trace-toolpack/debugPrompt.d.ts.map +1 -0
  54. package/dist/types/lib/trace-toolpack/index.d.ts +11 -0
  55. package/dist/types/lib/trace-toolpack/index.d.ts.map +1 -1
  56. package/dist/types/lib/trace-toolpack/lazyToolpack.d.ts +36 -0
  57. package/dist/types/lib/trace-toolpack/lazyToolpack.d.ts.map +1 -0
  58. package/dist/types/lib/trace-toolpack/selfExplain.d.ts +101 -0
  59. package/dist/types/lib/trace-toolpack/selfExplain.d.ts.map +1 -0
  60. package/dist/types/lib/trace-toolpack/traceDebugAgent.d.ts +43 -0
  61. package/dist/types/lib/trace-toolpack/traceDebugAgent.d.ts.map +1 -0
  62. package/dist/types/lib/trace-toolpack/traceToolpack.d.ts.map +1 -1
  63. package/dist/types/observe.d.ts +3 -1
  64. package/dist/types/observe.d.ts.map +1 -1
  65. package/package.json +1 -1
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <h1 align="center">Agentfootprint</h1>
4
4
 
5
5
  <p align="center">
6
- <strong>Your agent picked the wrong tool, gave a wrong answer — and the logs can't tell you why.<br/>Agentfootprint can.</strong>
6
+ <strong>Your agent gave an answer that <em>looks</em> right — and it's wrong.<br/>The logs can't tell you who influenced it. Agentfootprint can.</strong>
7
7
  </p>
8
8
 
9
9
  <p align="center">
@@ -43,10 +43,20 @@ domain knowledge to fix either:
43
43
  | **Business logic** — wrong branch, wrong math | the code | stack trace, debugger, `console.log` |
44
44
  | **Contextual** — wrong tool chosen, wrong fact believed, stale memory trusted | **what the model was given** | **nothing. Until now.** |
45
45
 
46
- Agents introduced the third class. The code is correct, the infra is healthy — and
47
- the run is still wrong, because two tool descriptions read alike, or an injected
48
- fact was misleading, or memory carried last week's truth. Classical logs can't
49
- explain it: **they record what the code did, never what the context did.**
46
+ Agents introduced the third class. The code is correct, the infra is healthy, the
47
+ answer even reads well — and the run is still wrong, because something influenced
48
+ the model:
49
+
50
+ | The model… | because… |
51
+ |---|---|
52
+ | picked the wrong tool | two descriptions read nearly alike — it chose between twins |
53
+ | believed a wrong "fact" | a tool returned it, or an injected fact planted it |
54
+ | followed the wrong instruction | the wrong skill / steering fired — or fired one iteration too early |
55
+ | answered from the past | a previous turn or stale memory bled into this one |
56
+
57
+ Classical logs can't explain any of it: **they record what the code did, never
58
+ what the context did.** The debugging question changed — no longer *"what did my
59
+ code do?"* but **"who influenced the model?"**
50
60
 
51
61
  ## The idea
52
62
 
@@ -97,6 +107,63 @@ A: verifyAuditBundle → valid: false, brokenAt: #16 — the tampered record, na
97
107
 
98
108
  And you don't have to read the trace yourself — **we provide the tools for an LLM to track it for you**: the trace toolpack let a debugger model find a planted bug while reading **9.5% of the trace** ([guide](docs/guides/trace-debugging.md)).
99
109
 
110
+ ## One contextual error, walked end to end
111
+
112
+ The third question above, in full — every value below is the captured output of
113
+ [`examples/observability/05-context-bisect.ts`](examples/observability/05-context-bisect.ts)
114
+ and [`06-backtrack-trace.ts`](examples/observability/06-backtrack-trace.ts), runnable offline.
115
+
116
+ **The bug.** A refunds agent carries a poisoned customer-profile fact. It answers:
117
+
118
+ > *"Refund APPROVED: Dana Reyes holds VIP tier override status, so the 47-day-old
119
+ > order qualifies for a refund beyond the 30-day window."*
120
+
121
+ The policy says 30 days. The logs look fine — the model was *given* bad context,
122
+ and classical logging has no row for that.
123
+
124
+ **The walk.** Because context here is state, the decision backtracks like a
125
+ variable: who read it, who wrote it, who let it in, where it was born —
126
+
127
+ ```text
128
+ ANSWER "Refund APPROVED…" ← the bug
129
+ READ call-llm#40 assembled the system prompt ← exactly what the model saw
130
+ LANDED context#6 wrote systemPromptInjections ← who mutated state
131
+ ALLOWED trigger { kind: 'always' } — active every iteration ← why it was let in
132
+ BORN defineFact('vip-override-fact') ← who wrote it
133
+ ```
134
+
135
+ That chain gives the **complete, provable candidate set** — every piece of
136
+ context that demonstrably reached the call, and nothing else. Influence scoring
137
+ then *ranks* inside it (the two facts sit 0.01 apart — proxies can't separate
138
+ them), and counterfactual **ablation proves**: removing `vip-override-fact`
139
+ flips APPROVED → DECLINED in **3/3 seeded reruns**; the benign style fact and
140
+ the lookup tool come back not-confirmed, 0/3. Scores are proxies; only the
141
+ ablation verdict makes a causal claim — the report says so itself.
142
+
143
+ **The same walk, visual.** One call serializes the report for
144
+ [AgentThinkingUI](https://github.com/footprintjs/agentThinkingUI)'s
145
+ `<BacktrackView>` — the "why?" board, triggerable from **any** decision point
146
+ (final answer, a mid-loop tool choice, a deterministic `decide()` rule):
147
+
148
+ ```typescript
149
+ import { localizeContextBug, toBacktrackTrace } from 'agentfootprint/observe';
150
+
151
+ const report = await localizeContextBug({ artifacts, embedder, atStep, rerun });
152
+ const trace = toBacktrackTrace(report, {
153
+ claim: 'The agent approved a refund 47 days past the 30-day window — why?',
154
+ answer: { text: buggyAnswer, label: 'the wrong answer' },
155
+ });
156
+ // <BacktrackView trace={trace}/> — or <BacktrackOverlay/> from any decision point
157
+ ```
158
+
159
+ <img alt="The BacktrackView board: the wrong answer, the suspects with influence meters, the CAUSAL 3/3 ablation stamp on the planted fact, and the chain-of-custody rewind showing the exact system prompt the model saw with the culprit sentence highlighted." src="docs/assets/backtrack-board.png" width="100%"/>
160
+
161
+ The rewind pane at the bottom is the killer view: **the exact system prompt the
162
+ model saw**, with the culprit sentence highlighted — recorded state, not a
163
+ reconstruction. And the same chain feeds the machine door: every id on the
164
+ board is a `runtimeStageId` a debugger LLM can drill with the
165
+ [trace toolpack](docs/guides/trace-debugging.md), token-cheaply.
166
+
100
167
  ---
101
168
 
102
169
  ## Pick your door
@@ -276,46 +343,6 @@ So we used the budget those abstractions would have cost us to invest deeply in
276
343
  > **We abstract context engineering — and hand back the trace.**
277
344
  > Live to develop · offline to monitor · detailed to improve.
278
345
 
279
- ### The reason — agents have a new class of bug
280
-
281
- For fifty years, software bugs have been **logic errors**. A wrong condition, a missed edge case, an off-by-one. You step through the code until you find the bad branch.
282
-
283
- LLM-powered apps add a second class of bug: **contextual errors.** The code is correct. The model is correct. The answer is wrong because **the LLM's decision rests on context that was ambiguous, confusing, or misleading at the moment of inference.**
284
-
285
- Tracking *which content the model actually saw, and why,* is the entire debugging job. Without it, the failure mode is invisible:
286
-
287
- | What got injected wrong | What the model did |
288
- |---|---|
289
- | Wrong instruction landed in the `system` slot | Followed the wrong rule |
290
- | Predicate fired one iteration too early | Reasoned with stale assumptions |
291
- | Skill body missing when the LLM called `read_skill` | Invented its own |
292
- | Cache prefix invalidated mid-iteration | Saw a silently rewritten stale version |
293
- | Tool returned but the `on-tool-return` injection didn't fire | Couldn't interpret the result |
294
-
295
- > [!IMPORTANT]
296
- > **The model doesn't tell you which of these went wrong. It just gives you the wrong answer.**
297
-
298
- You can't step through that with a debugger. By the time you read the response, the context that produced it is gone unless something recorded it.
299
-
300
- That's the gap agentfootprint fills. A framework that owns the control flow can debug logic errors. A framework that owns the *injection* can debug contextual errors — because every injection is a typed event with a where, when, why, and how-it-cached.
301
-
302
- ### What that buys you
303
-
304
- Because we own the injection, every LLM call backtracks to four typed answers:
305
-
306
- - **What** was injected
307
- - **Who** triggered it (which rule)
308
- - **When** it fired
309
- - **How** it landed — slot, position, cache
310
-
311
- Same trace, three workflows:
312
-
313
- - **Live — debug as you build.** See exactly which injection produced which token, which predicate fired this iteration, which prefix actually got cached.
314
- - **Offline — monitor what shipped.** Replay any past run from its trace. Alert on drift. Attribute cost per injection.
315
- - **Detailed — improve via export.** Every successful trajectory is labeled training data for SFT, DPO, or RL — no separate data-collection phase.
316
-
317
- And a fourth, novel: **the agent can read its own trace.** Six months after the agent rejected loan #42, *"why did you reject it?"* answers from the recorded evidence — the tool calls (`credit_score_check → 580`), the decisions, the rules that fired — not a rerun. Causal memory turns the trace into the agent's working memory.
318
-
319
346
  ---
320
347
 
321
348
  ## How do I design my agent or system of agents?
@@ -474,7 +501,7 @@ The patterns the field knows reduce to the same alphabet:
474
501
  | **Router** | `Conditional → Agent_A \| Agent_B \| Agent_C` |
475
502
  | **Hierarchical** | `Agent_planner → Sequence( Agent_worker×N ) → synth` |
476
503
 
477
- Same trick as Beat 1: instead of N libraries for N patterns, we found the M building blocks all N patterns are made of.
504
+ Same trick as the injection model: instead of N libraries for N patterns, we found the M building blocks all N patterns are made of.
478
505
 
479
506
  > 📖 Compare: [hand-rolled vs declarative](https://footprintjs.github.io/agentfootprint/getting-started/why/) · [migration from LangChain / CrewAI / LangGraph](https://footprintjs.github.io/agentfootprint/getting-started/vs/)
480
507
 
@@ -489,15 +516,7 @@ Same trick as Beat 1: instead of N libraries for N patterns, we found the M buil
489
516
  <sub>One real run, fully explained — the <a href="https://github.com/footprintjs/agentfootprint-lens"><b>Lens</b></a> (<code>npm i agentfootprint-lens</code>): conversation · executed path · per-step timeline · stats, every pixel from the trace.</sub>
490
517
  </p>
491
518
 
492
- Because we own the loop (Beat 2), every decision and execution is captured during traversal — not bolted on. The default capture is the **causal trace**: every stage, read, write, and decision evidence, as a JSON-portable, scrubbable, queryable, exportable artifact. Beyond the default, wire custom recorders for cost, latency, or quality scoring — any observation hook fires on the same stream.
493
-
494
- <p align="center">
495
- <picture>
496
- <source media="(prefers-color-scheme: dark)" srcset="docs/assets/causal-memory-dark.svg">
497
- <source media="(prefers-color-scheme: light)" srcset="docs/assets/causal-memory-light.svg">
498
- <img alt="agentfootprint causal memory — Each agent run produces a JSON-portable causal trace: a scrubbable timeline of every stage with reads, writes, and captured decision evidence. The trace card shows a time-travel slider (Step 5 of 17, Live), an execution timeline with stage-duration bars, and the captured decision evidence pill (riskTier eq high → reject). Two built-in lenses view it: Lens (agent-centric) and Explainable Trace (structural). Three programmatic consumers fan out from it: audit replay (GDPR Article 22 adverse-action notice answered from chain, no LLM call, $15/1M to $0.25/1M tokens), cheap-model triage (Sonnet trace fed to Haiku for follow-ups), and training data export (every chain is a labeled trajectory ready for SFT/DPO/process-RL). One recording, two lenses, three consumers, zero extra instrumentation. Powered by footprintjs causalChain()." src="docs/assets/causal-memory-light.svg" width="100%"/>
499
- </picture>
500
- </p>
519
+ Because we own the loop, every decision and execution is captured during traversal — not bolted on. The default capture is the **causal trace**: every stage, read, write, and decision evidence as a JSON-portable, scrubbable, queryable, exportable artifact — and every LLM call backtracks to four typed answers: **what** was injected, **who** triggered it (which rule), **when** it fired, **how** it landed (slot · position · cache). Beyond the default, wire custom recorders for cost, latency, or quality scoring — any observation hook fires on the same stream.
501
520
 
502
521
  The same trace serves three downstream consumers — no extra instrumentation:
503
522
 
@@ -507,74 +526,60 @@ The same trace serves three downstream consumers — no extra instrumentation:
507
526
 
508
527
  3. **Training data — the substrate is already there.** Every successful chain is a labeled trajectory. SFT pairs (`{prompt, completion}`) fall out of the snapshot's history field; the export wrapper is roadmap work tracked in [GitHub issues](https://github.com/footprintjs/agentfootprint/issues). DPO and process-RL need additional collection layers (preference feedback, per-step reward annotation) that don't ship today.
509
528
 
510
- Two built-in lenses view the same trace:
529
+ Four views, one trace pick by question:
511
530
 
512
- | Lens | View | When to use |
531
+ | View | Shows | When to use |
513
532
  |---|---|---|
514
- | **Lens** | Agent-centric User/Agent[3 slots]/Tool flowchart with iteration scrubber and round commentary | Live debugging, "what did Neo see at step 5?" |
533
+ | **AgentThinkingUI** (the hero up top) | The run replayed as an animated, scrubbable story the brain, the tools, the reasoning | Show anyone *what the agent did* |
534
+ | **BacktrackView** ([the board above](#one-contextual-error-walked-end-to-end)) | A decision walked backwards — suspects, influence meters, ablation stamps, custody rewind | Answer *why it decided that* |
535
+ | **Lens** | Agent-centric — User/Agent[3 slots]/Tool flowchart with iteration scrubber and round commentary | Live debugging, "what did the agent see at step 5?" |
515
536
  | **Explainable Trace** | Structural — subflow tree, full flowchart, memory inspector, per-stage execution timeline | Architecture review, root-cause analysis |
516
537
 
538
+ And two **conversational** doors over the same evidence — ask instead of look:
539
+
540
+ ```ts
541
+ // dedicated: a cheap model debugs an expensive run by id — pays for what it opens
542
+ const debuggerAi = traceDebugAgent({ artifacts, provider: anthropic(), model: 'claude-haiku-4-5' });
543
+ await debuggerAi.run({ message: 'Why was loan APP-7 approved?' });
544
+
545
+ // in-conversation: the agent answers "why did you…?" from its OWN previous turn
546
+ Agent.create({ provider, model }).tool(lookupOrder)
547
+ .selfExplain({ delegate: { provider: anthropic(), model: 'claude-haiku-4-5' } })
548
+ .build();
549
+ ```
550
+
551
+ `.selfExplain()` mounts one skill: the catalog stays clean until the LLM activates
552
+ it, evidence binds only to **completed** runs (never in-flight), and `delegate`
553
+ answers at the cheap model's price inside the expensive conversation.
554
+ [Guide](docs/guides/trace-debugging.md) · examples
555
+ [`07`](examples/observability/07-trace-debug-agent.ts) ·
556
+ [`08`](examples/observability/08-self-explain.ts).
557
+
517
558
  > 📖 Powered by [footprintjs `causalChain()`](https://footprintjs.github.io/footPrint/blog/backward-causal-chain/) — backward thin-slicing on the commit log. [Causal memory deep dive](https://footprintjs.github.io/agentfootprint/causal-deep-dive/) · [Explainability & compliance](https://footprintjs.github.io/footPrint/blog/explainability-compliance/)
518
559
 
519
560
  **One recording. Two lenses. Three consumers. Zero extra instrumentation.**
520
561
 
521
- ### Non-blocking observers `observerDelivery: 'deferred'` (RFC-001)
562
+ ### Observers stay off the hot path
522
563
 
523
- By default every `agent.on()` listener runs **synchronously inside the
524
- producing statement** a slow exporter or pretty-printer taxes every
525
- iteration of the ReAct loop. One option moves observation off the hot path:
564
+ By default every `agent.on()` listener runs synchronously inside the producing
565
+ statement. One option moves observation off the hot path:
526
566
 
527
567
  ```ts
528
- const agent = Agent.create({
529
- provider,
530
- model,
531
- observerDelivery: 'deferred', // default 'inline' — byte-identical to prior releases
532
- })
533
- .system('…')
534
- .build();
535
-
536
- await agent.run({ message });
568
+ Agent.create({ provider, model, observerDelivery: 'deferred' }) // default 'inline'
537
569
  // serverless / shutdown: settle async listener work before the freeze
538
570
  await agent.drainObservers({ timeoutMs: 5_000 });
539
571
  ```
540
572
 
541
- Every event is **captured** into footprintjs's bounded queue (≈ microseconds
542
- on the hot path) and **delivered one beat behind** at the next microtask
543
- checkpoint same typed events, same payloads, same order (a drop-in port,
544
- deep-equal tested). Terminal boundaries (resolve, crash, pause) drain the
545
- queue synchronously **before control returns**, so crash checkpoints and
546
- pause records are always complete. Queue stats land on
547
- `agent.getLastSnapshot()?.observerStats` (drops, flushes, per-listener time —
548
- "name the hog"). The causal-evidence recorder stays inline by design (the
549
- memory write stage reads it mid-run); a recorder declaring its own `delivery`
550
- field keeps it — a per-recorder override for free.
551
-
552
- **The measured deal** — 50-iteration full-feature agent, 3 747 events, a
553
- deliberately slow 5 ms-per-event wildcard listener, 100 ms mock LLM latency
554
- ([`examples/features/21-deferred-observers.ts`](examples/features/21-deferred-observers.ts)):
555
-
556
- | Streaming cadence | Mode | Wall | p95 / iteration | Drops |
557
- |---|---|---|---|---|
558
- | — | no listener (the floor) | 5.6 s | 115 ms | — |
559
- | 0 ms (back-to-back chunks) | inline + listener | 24.5 s | 727 ms | — |
560
- | 0 ms (back-to-back chunks) | **deferred** + listener | 24.0 s | 710 ms | 0 |
561
- | 20 ms (realistic streaming) | inline + listener | 34.8 s | 926 ms | — |
562
- | 20 ms (realistic streaming) | **deferred** + listener | **32.1 s (−2.7 s, −8%)** | **868 ms** | 0 |
563
-
564
- Honest mechanism: on a single thread a CPU-burning listener's total work is
565
- conserved — deferral recovers wall time where waits sit **adjacent** to the
566
- producing events (`llm_start` before the provider wait, `tool_start` before
567
- tool I/O, tokens between stream chunks). Back-to-back streaming
568
- (`chunkDelayMs: 0`) is the worst case (~2% wall saved); realistic streaming
569
- cadence makes token events wait-adjacent and the saving grows several-fold.
570
- What never depends on shape: the **bounded** queue (no OOM), **error
571
- isolation** (a throwing listener can't kill the run), **per-listener stats**,
572
- **zero loss** (`drops: 0`, gap-detectable), and **terminal completeness**.
573
- Not opting in costs nothing — the default path attaches exactly as before and
574
- allocates no queue.
575
-
576
- > 📖 Full semantics (capture policies, backpressure, `'block'` overflow):
577
- > [footprintjs deferred-observers guide](https://github.com/footprintjs/footPrint/blob/main/docs/guides/observers-deferred.md)
573
+ Events are captured into a bounded queue (≈ microseconds on the hot path) and
574
+ delivered one beat behind same typed events, same order, zero loss, a throwing
575
+ listener can't kill the run, and per-listener stats land on
576
+ `getLastSnapshot()?.observerStats` to name the hog. Terminal boundaries (resolve,
577
+ crash, pause) drain synchronously first, so checkpoints are always complete.
578
+ Measured: −8% wall on a 50-iteration agent with a deliberately slow listener
579
+ ([example 21](examples/features/21-deferred-observers.ts)).
580
+
581
+ > 📖 Full semantics (capture policies, backpressure, overflow):
582
+ > [deferred-observers guide](https://github.com/footprintjs/footPrint/blob/main/docs/guides/observers-deferred.md)
578
583
 
579
584
  ### Lint your tool catalog — before the model picks the wrong twin
580
585
 
@@ -656,7 +661,16 @@ The flowchart, recorders, and tests don't change between dev and prod.
656
661
  - Resilience primitives — `withRetry`, `withFallback`, `withCircuitBreaker`, `.outputFallback`, `agent.resumeOnError`
657
662
  - 60+ typed observability events — `agent` · `composition` · `context` · `stream` · `tools` · `skill` · `memory` · `cache` · `cost` · `permission` · `eval` · `embedding` · `pause` · `error` · `fallback` · `resilience` · `reliability` · `risk`
658
663
 
664
+ **Debugging & compliance** (`agentfootprint/observe`)
665
+ - Tool-catalog lint — `npx agentfootprint-lint-tools` (any framework's tool list) + runtime `toolChoiceRecorder` margins
666
+ - Contextual-bug localizer — `localizeContextBug` (causal slice → influence ranking → counterfactual ablation) + `bisectCulprits`
667
+ - `toBacktrackTrace` — render any decision as the BacktrackView "why?" board
668
+ - Trace toolpack — 6 bounded, LLM-callable tools so a debugger model walks the trace by id
669
+ - `traceDebugAgent` (dedicated debugger session) · `.selfExplain()` (in-conversation why-questions, skill-gated, with a cheap-model `delegate` switch)
670
+ - OTel GenAI span export · hash-chained tamper-evident audit bundles with an offline verifier
671
+
659
672
  **Tooling**
673
+ - **AgentThinkingUI** — animated run player + BacktrackView why-board (separate `agentthinkingui` package)
660
674
  - **Lens** · **Explainable Trace** — two visual replays of the causal trace (separate `agentfootprint-lens` package)
661
675
  - AI-coding-tool support — Claude Code · Cursor · Windsurf · Cline · Kiro · Copilot
662
676
 
@@ -14,6 +14,7 @@ const outputFallback_js_1 = require("../outputFallback.js");
14
14
  const defineInstruction_js_1 = require("../../lib/injection-engine/factories/defineInstruction.js");
15
15
  const commentaryTemplates_js_1 = require("../../recorders/observability/commentary/commentaryTemplates.js");
16
16
  const statusTemplates_js_1 = require("../../recorders/observability/status/statusTemplates.js");
17
+ const selfExplain_js_1 = require("../../lib/trace-toolpack/selfExplain.js");
17
18
  const Agent_js_1 = require("../Agent.js");
18
19
  /**
19
20
  * Fluent builder. `tool()` accepts any Tool<TArgs, TResult> and registers
@@ -107,6 +108,7 @@ class AgentBuilder {
107
108
  * `.thinkingHandler()` (response-side normalization choice).
108
109
  */
109
110
  thinkingBudgetValue;
111
+ selfExplainConfig;
110
112
  constructor(opts) {
111
113
  this.opts = opts;
112
114
  // Cache layer: opts.caching === 'off' propagates to scope's
@@ -659,6 +661,44 @@ class AgentBuilder {
659
661
  this.thinkingBudgetValue = opts.budget;
660
662
  return this;
661
663
  }
664
+ /**
665
+ * Let this agent answer why-questions about its OWN previous completed
666
+ * turn, from its recorded trace. Mounts one skill: day to day the tool
667
+ * catalog carries only the skill's activation row; when the user asks
668
+ * "why did you…", the LLM activates it and that iteration alone gets
669
+ * the trace tools (inline mode) or a single `explain_run` tool that
670
+ * runs a nested trace debugger on a cheaper model (delegate mode).
671
+ *
672
+ * Evidence binds LATE — always to the previous COMPLETED run, never
673
+ * the in-flight one — and includes control edges (a per-run
674
+ * control-dependence recorder is attached automatically).
675
+ *
676
+ * @example
677
+ * Agent.create({ provider, model })
678
+ * .system('You are a refunds assistant.')
679
+ * .tool(lookupOrder)
680
+ * .selfExplain() // inline, zero config
681
+ * .build();
682
+ *
683
+ * @example
684
+ * .selfExplain({ delegate: { provider: anthropic(), model: 'claude-haiku-4-5' } })
685
+ */
686
+ selfExplain(opts = {}) {
687
+ if (this.selfExplainConfig !== undefined) {
688
+ throw new Error('AgentBuilder.selfExplain: already enabled.');
689
+ }
690
+ if (this.opts.reactMode === 'classic') {
691
+ // Classic ReAct caches the tools slot on turn 1 — a mid-turn skill
692
+ // activation could never surface the trace tools. Fail loud at
693
+ // build-time rather than silently never answering why-questions.
694
+ throw new Error('AgentBuilder.selfExplain: requires per-iteration slot recomposition — ' +
695
+ "reactMode 'classic' caches the tools slot, so the activated trace tools " +
696
+ "would never reach the model. Use the default 'dynamic' mode (or " +
697
+ "'dynamic-grouped'), or use traceDebugAgent() as a separate session instead.");
698
+ }
699
+ this.selfExplainConfig = opts;
700
+ return this;
701
+ }
662
702
  build() {
663
703
  // Resolve the voice config: bundled defaults + consumer overrides.
664
704
  // Templates flow through the same barrel exports the rest of the
@@ -671,13 +711,47 @@ class AgentBuilder {
671
711
  const opts = this.maxIterationsOverride !== undefined
672
712
  ? { ...this.opts, maxIterations: this.maxIterationsOverride }
673
713
  : this.opts;
674
- const agent = new Agent_js_1.Agent(opts, this.systemPromptValue, this.registry, voice, this.injectionList, this.memoryList, this.outputSchemaParser, this.toolProviderRef, this.systemPromptCachePolicy, this.cachingDisabledValue, this.cacheStrategyOverride, this.outputFallbackCfg, this.reliabilityConfig, this.thinkingHandlerValue, this.thinkingBudgetValue);
714
+ // .selfExplain(): a fresh binding per build() two built agents never
715
+ // share evidence. One mounted skill (methodology body only) + the trace
716
+ // tools on a skill-scoped ToolProvider composed with the consumer's own,
717
+ // so the catalog gains them ONLY on the activated iteration.
718
+ //
719
+ // Name reservation (mirrors the read_skill rule): the tools slot dedupes
720
+ // by name with first-occurrence-wins and the static registry merges
721
+ // FIRST — a consumer tool named like a trace tool would silently shadow
722
+ // it, and the skill body would instruct the model into the wrong tool.
723
+ if (this.selfExplainConfig) {
724
+ const reserved = this.selfExplainConfig.delegate
725
+ ? ['explain_run']
726
+ : ['run_overview', 'trace_node', 'trace_slice', 'who_wrote', 'get_value'];
727
+ const clash = this.registry.find((entry) => reserved.includes(entry.name));
728
+ if (clash) {
729
+ throw new Error(`AgentBuilder.selfExplain: tool name '${clash.name}' is reserved by .selfExplain() ` +
730
+ `(${this.selfExplainConfig.delegate ? 'delegate' : 'inline'} mode). The tools slot ` +
731
+ `dedupes by name (first wins), so your tool would silently shadow the trace tool. ` +
732
+ `Rename it, or reserved names: ${reserved.join(', ')}.`);
733
+ }
734
+ }
735
+ const selfExplainBinding = this.selfExplainConfig ? new selfExplain_js_1.SelfExplainBinding() : undefined;
736
+ const injections = selfExplainBinding
737
+ ? [...this.injectionList, (0, selfExplain_js_1.buildSelfExplainSkill)(this.selfExplainConfig)]
738
+ : this.injectionList;
739
+ const toolProvider = selfExplainBinding
740
+ ? (0, selfExplain_js_1.buildSelfExplainToolProvider)(selfExplainBinding, this.selfExplainConfig, this.toolProviderRef)
741
+ : this.toolProviderRef;
742
+ const agent = new Agent_js_1.Agent(opts, this.systemPromptValue, this.registry, voice, injections, this.memoryList, this.outputSchemaParser, toolProvider, this.systemPromptCachePolicy, this.cachingDisabledValue, this.cacheStrategyOverride, this.outputFallbackCfg, this.reliabilityConfig, this.thinkingHandlerValue, this.thinkingBudgetValue);
675
743
  // Attach builder-collected recorders so they receive events from
676
744
  // the very first run. Mirrors what consumers would do post-build
677
745
  // via `agent.attach(rec)`; the builder method is purely sugar.
678
746
  for (const rec of this.recorderList) {
679
747
  agent.attach(rec);
680
748
  }
749
+ if (selfExplainBinding) {
750
+ // Late binding: capture fires at each run's terminal flush, when
751
+ // getLastSnapshot() IS the just-completed run (never in-flight).
752
+ selfExplainBinding.bindTo(() => agent.getLastSnapshot());
753
+ agent.attach(selfExplainBinding.recorder());
754
+ }
681
755
  return agent;
682
756
  }
683
757
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AgentBuilder.js","sourceRoot":"","sources":["../../../src/core/agent/AgentBuilder.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,wDAI4B;AAC5B,4DAK8B;AAG9B,oGAA8F;AAM9F,4GAA6G;AAC7G,gGAAiG;AACjG,0CAAoC;AAGpC;;;GAGG;AACH,MAAa,YAAY;IACN,IAAI,CAAe;IAC5B,iBAAiB,GAAG,EAAE,CAAC;IAC/B;;;;OAIG;IACK,uBAAuB,GAAgB,QAAQ,CAAC;IACxD;;;;;OAKG;IACK,oBAAoB,GAAG,KAAK,CAAC;IACrC;;;;;OAKG;IACK,qBAAqB,CAAiB;IAC7B,QAAQ,GAAwB,EAAE,CAAC;IACnC,aAAa,GAAgB,EAAE,CAAC;IAChC,UAAU,GAAuB,EAAE,CAAC;IACrD;;;OAGG;IACK,kBAAkB,CAA+B;IAEzD;2EACuE;IAC/D,iBAAiB,CAAmC;IAC5D;;;;;OAKG;IACK,eAAe,CAAgB;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C,YAAY,EAAE,CAAC;YACpC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;QACD,IAAI,kBAAkB,EAAE,CAAC;YACvB,iEAAiE;YACjE,iEAAiE;YACjE,kBAAkB,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC;YACzD,KAAK,CAAC,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAryBD,oCAqyBC"}
@@ -11,6 +11,7 @@ import { validateCannedAgainstSchema, } from '../outputFallback.js';
11
11
  import { defineInstruction } from '../../lib/injection-engine/factories/defineInstruction.js';
12
12
  import { defaultCommentaryTemplates } from '../../recorders/observability/commentary/commentaryTemplates.js';
13
13
  import { defaultStatusTemplates } from '../../recorders/observability/status/statusTemplates.js';
14
+ import { buildSelfExplainSkill, buildSelfExplainToolProvider, SelfExplainBinding, } from '../../lib/trace-toolpack/selfExplain.js';
14
15
  import { Agent } from '../Agent.js';
15
16
  /**
16
17
  * Fluent builder. `tool()` accepts any Tool<TArgs, TResult> and registers
@@ -104,6 +105,7 @@ export class AgentBuilder {
104
105
  * `.thinkingHandler()` (response-side normalization choice).
105
106
  */
106
107
  thinkingBudgetValue;
108
+ selfExplainConfig;
107
109
  constructor(opts) {
108
110
  this.opts = opts;
109
111
  // Cache layer: opts.caching === 'off' propagates to scope's
@@ -656,6 +658,44 @@ export class AgentBuilder {
656
658
  this.thinkingBudgetValue = opts.budget;
657
659
  return this;
658
660
  }
661
+ /**
662
+ * Let this agent answer why-questions about its OWN previous completed
663
+ * turn, from its recorded trace. Mounts one skill: day to day the tool
664
+ * catalog carries only the skill's activation row; when the user asks
665
+ * "why did you…", the LLM activates it and that iteration alone gets
666
+ * the trace tools (inline mode) or a single `explain_run` tool that
667
+ * runs a nested trace debugger on a cheaper model (delegate mode).
668
+ *
669
+ * Evidence binds LATE — always to the previous COMPLETED run, never
670
+ * the in-flight one — and includes control edges (a per-run
671
+ * control-dependence recorder is attached automatically).
672
+ *
673
+ * @example
674
+ * Agent.create({ provider, model })
675
+ * .system('You are a refunds assistant.')
676
+ * .tool(lookupOrder)
677
+ * .selfExplain() // inline, zero config
678
+ * .build();
679
+ *
680
+ * @example
681
+ * .selfExplain({ delegate: { provider: anthropic(), model: 'claude-haiku-4-5' } })
682
+ */
683
+ selfExplain(opts = {}) {
684
+ if (this.selfExplainConfig !== undefined) {
685
+ throw new Error('AgentBuilder.selfExplain: already enabled.');
686
+ }
687
+ if (this.opts.reactMode === 'classic') {
688
+ // Classic ReAct caches the tools slot on turn 1 — a mid-turn skill
689
+ // activation could never surface the trace tools. Fail loud at
690
+ // build-time rather than silently never answering why-questions.
691
+ throw new Error('AgentBuilder.selfExplain: requires per-iteration slot recomposition — ' +
692
+ "reactMode 'classic' caches the tools slot, so the activated trace tools " +
693
+ "would never reach the model. Use the default 'dynamic' mode (or " +
694
+ "'dynamic-grouped'), or use traceDebugAgent() as a separate session instead.");
695
+ }
696
+ this.selfExplainConfig = opts;
697
+ return this;
698
+ }
659
699
  build() {
660
700
  // Resolve the voice config: bundled defaults + consumer overrides.
661
701
  // Templates flow through the same barrel exports the rest of the
@@ -668,13 +708,47 @@ export class AgentBuilder {
668
708
  const opts = this.maxIterationsOverride !== undefined
669
709
  ? { ...this.opts, maxIterations: this.maxIterationsOverride }
670
710
  : this.opts;
671
- const agent = new Agent(opts, this.systemPromptValue, this.registry, voice, this.injectionList, this.memoryList, this.outputSchemaParser, this.toolProviderRef, this.systemPromptCachePolicy, this.cachingDisabledValue, this.cacheStrategyOverride, this.outputFallbackCfg, this.reliabilityConfig, this.thinkingHandlerValue, this.thinkingBudgetValue);
711
+ // .selfExplain(): a fresh binding per build() two built agents never
712
+ // share evidence. One mounted skill (methodology body only) + the trace
713
+ // tools on a skill-scoped ToolProvider composed with the consumer's own,
714
+ // so the catalog gains them ONLY on the activated iteration.
715
+ //
716
+ // Name reservation (mirrors the read_skill rule): the tools slot dedupes
717
+ // by name with first-occurrence-wins and the static registry merges
718
+ // FIRST — a consumer tool named like a trace tool would silently shadow
719
+ // it, and the skill body would instruct the model into the wrong tool.
720
+ if (this.selfExplainConfig) {
721
+ const reserved = this.selfExplainConfig.delegate
722
+ ? ['explain_run']
723
+ : ['run_overview', 'trace_node', 'trace_slice', 'who_wrote', 'get_value'];
724
+ const clash = this.registry.find((entry) => reserved.includes(entry.name));
725
+ if (clash) {
726
+ throw new Error(`AgentBuilder.selfExplain: tool name '${clash.name}' is reserved by .selfExplain() ` +
727
+ `(${this.selfExplainConfig.delegate ? 'delegate' : 'inline'} mode). The tools slot ` +
728
+ `dedupes by name (first wins), so your tool would silently shadow the trace tool. ` +
729
+ `Rename it, or reserved names: ${reserved.join(', ')}.`);
730
+ }
731
+ }
732
+ const selfExplainBinding = this.selfExplainConfig ? new SelfExplainBinding() : undefined;
733
+ const injections = selfExplainBinding
734
+ ? [...this.injectionList, buildSelfExplainSkill(this.selfExplainConfig)]
735
+ : this.injectionList;
736
+ const toolProvider = selfExplainBinding
737
+ ? buildSelfExplainToolProvider(selfExplainBinding, this.selfExplainConfig, this.toolProviderRef)
738
+ : this.toolProviderRef;
739
+ const agent = new Agent(opts, this.systemPromptValue, this.registry, voice, injections, this.memoryList, this.outputSchemaParser, toolProvider, this.systemPromptCachePolicy, this.cachingDisabledValue, this.cacheStrategyOverride, this.outputFallbackCfg, this.reliabilityConfig, this.thinkingHandlerValue, this.thinkingBudgetValue);
672
740
  // Attach builder-collected recorders so they receive events from
673
741
  // the very first run. Mirrors what consumers would do post-build
674
742
  // via `agent.attach(rec)`; the builder method is purely sugar.
675
743
  for (const rec of this.recorderList) {
676
744
  agent.attach(rec);
677
745
  }
746
+ if (selfExplainBinding) {
747
+ // Late binding: capture fires at each run's terminal flush, when
748
+ // getLastSnapshot() IS the just-completed run (never in-flight).
749
+ selfExplainBinding.bindTo(() => agent.getLastSnapshot());
750
+ agent.attach(selfExplainBinding.recorder());
751
+ }
678
752
  return agent;
679
753
  }
680
754
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AgentBuilder.js","sourceRoot":"","sources":["../../../../src/core/agent/AgentBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,uBAAuB,GAGxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,2BAA2B,GAI5B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2DAA2D,CAAC;AAM9F,OAAO,EAAE,0BAA0B,EAAE,MAAM,iEAAiE,CAAC;AAC7G,OAAO,EAAE,sBAAsB,EAAE,MAAM,yDAAyD,CAAC;AACjG,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC;;;GAGG;AACH,MAAM,OAAO,YAAY;IACN,IAAI,CAAe;IAC5B,iBAAiB,GAAG,EAAE,CAAC;IAC/B;;;;OAIG;IACK,uBAAuB,GAAgB,QAAQ,CAAC;IACxD;;;;;OAKG;IACK,oBAAoB,GAAG,KAAK,CAAC;IACrC;;;;;OAKG;IACK,qBAAqB,CAAiB;IAC7B,QAAQ,GAAwB,EAAE,CAAC;IACnC,aAAa,GAAgB,EAAE,CAAC;IAChC,UAAU,GAAuB,EAAE,CAAC;IACrD;;;OAGG;IACK,kBAAkB,CAA+B;IAEzD;2EACuE;IAC/D,iBAAiB,CAAmC;IAC5D;;;;;OAKG;IACK,eAAe,CAAgB;IACvC;;;;OAIG;IACK,qBAAqB,CAAU;IACvC;;;OAGG;IACc,YAAY,GAA6C,EAAE,CAAC;IAC7E,gEAAgE;IAChE,iEAAiE;IACjE,kEAAkE;IAClE,iEAAiE;IACjE,+CAA+C;IACvC,YAAY,GAAG,SAAS,CAAC;IACzB,mBAAmB,GAAqC,EAAE,CAAC;IAC3D,iBAAiB,GAAqC,EAAE,CAAC;IACjE;;;;;OAKG;IACK,iBAAiB,CAAqB;IAE9C;;;;;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