agentfootprint 1.1.0 → 1.2.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.
package/AGENTS.md CHANGED
@@ -22,11 +22,11 @@ src/
22
22
  ├── tools/ → ToolRegistry + defineTool
23
23
  ├── stages/ → Reusable flowchart stages (seedScope, callLLM, parseResponse, etc.)
24
24
  ├── scope/ → AgentScope paths + helpers
25
- ├── memory/ → Message utilities (appendMessage, slidingWindow, truncateToCharBudget)
25
+ ├── memory/ → Message utilities (appendMessage, lastMessage, lastAssistantMessage)
26
26
  ├── executor/ → agentLoop (core ReAct loop)
27
27
  ├── compositions/→ withRetry, withFallback, withCircuitBreaker
28
28
  ├── streaming/ → StreamEmitter, SSEFormatter, AgentStreamEvent
29
- ├── lib/ → Instructions (agentInstruction, InstructionsToLLM subflow), narrative (grounding helpers), loop (buildAgentLoop), slots, call stages
29
+ ├── lib/ → Instructions (agentInstruction, InstructionsToLLM subflow), narrative (agentRenderer), loop (buildAgentLoop), slots, call stages
30
30
  └── types/ → All type definitions (messages, llm, tools, content blocks)
31
31
  ```
32
32
 
@@ -281,7 +281,6 @@ Collects during traversal via recorder hooks — no post-processing of narrative
281
281
  ## Anti-Patterns
282
282
 
283
283
  - Never use the old functional API (`LLMCall({...})`, `Agent({...})`) — always use `LLMCall.create({...})` builder pattern
284
- - Never use `CostRecorderV2` — use `CostRecorder` (V2 is a deprecated alias)
285
284
  - Never pass recorders via constructor options — use `.recorder()` builder method
286
285
  - Don't use `name`/`parameters` on `defineTool` — use `id`/`inputSchema`
287
286
  - Don't use `tokens.stats()` — use `tokens.getStats()`
package/CLAUDE.md CHANGED
@@ -22,11 +22,11 @@ src/
22
22
  ├── tools/ → ToolRegistry + defineTool
23
23
  ├── stages/ → Reusable flowchart stages (seedScope, callLLM, parseResponse, etc.)
24
24
  ├── scope/ → AgentScope paths + helpers
25
- ├── memory/ → Message utilities (appendMessage, slidingWindow, truncateToCharBudget)
25
+ ├── memory/ → Message utilities (appendMessage, lastMessage, lastAssistantMessage)
26
26
  ├── executor/ → agentLoop (core ReAct loop)
27
27
  ├── compositions/→ withRetry, withFallback, withCircuitBreaker
28
28
  ├── streaming/ → StreamEmitter, SSEFormatter, AgentStreamEvent
29
- ├── lib/ → Instructions (agentInstruction, InstructionsToLLM subflow), narrative (grounding helpers), loop (buildAgentLoop), slots, call stages
29
+ ├── lib/ → Instructions (agentInstruction, InstructionsToLLM subflow), narrative (agentRenderer), loop (buildAgentLoop), slots, call stages
30
30
  └── types/ → All type definitions (messages, llm, tools, content blocks)
31
31
  ```
32
32
 
@@ -281,7 +281,6 @@ Collects during traversal via recorder hooks — no post-processing of narrative
281
281
  ## Anti-Patterns
282
282
 
283
283
  - Never use the old functional API (`LLMCall({...})`, `Agent({...})`) — always use `LLMCall.create({...})` builder pattern
284
- - Never use `CostRecorderV2` — use `CostRecorder` (V2 is a deprecated alias)
285
284
  - Never pass recorders via constructor options — use `.recorder()` builder method
286
285
  - Don't use `name`/`parameters` on `defineTool` — use `id`/`inputSchema`
287
286
  - Don't use `tokens.stats()` — use `tokens.getStats()`
@@ -511,7 +511,7 @@ src/
511
511
  ├── models/ → Model configs (anthropic, openai, ollama, bedrock)
512
512
  ├── adapters/ → Mock, Anthropic, OpenAI, Bedrock, MCP, A2A, createProvider
513
513
  ├── tools/ → ToolRegistry, defineTool
514
- ├── memory/ → Message helpers (appendMessage, slidingWindow, truncate)
514
+ ├── memory/ → Message helpers (appendMessage, lastMessage, lastAssistantMessage)
515
515
  ├── scope/ → AgentScope (typed paths into footprintjs ScopeFacade)
516
516
  ├── stages/ → Reusable stage functions (seedScope, callLLM, parseResponse, etc.)
517
517
  ├── core/ → AgentRecorder, PromptProvider, ToolProvider, AgentLoopConfig
@@ -530,8 +530,7 @@ Single entry point: `import { ... } from 'agentfootprint'`
530
530
 
531
531
  ## Anti-Patterns to Avoid
532
532
 
533
- 1. **Never use `CostRecorderV2`**it's deprecated. Use `CostRecorder`.
534
- 2. **Never post-process the flowchart** — use recorders to collect data during traversal.
533
+ 1. **Never post-process the flowchart** use recorders to collect data during traversal.
535
534
  3. **Never build agents without `mock()`** in tests — no API keys in test suites.
536
535
  4. **Don't skip `.recorder(rec)`** — always attach recorders to observe execution.
537
536
  5. **Don't use raw footprintjs stages** for agent logic — use concept builders (`Agent.create()`, `LLMCall.create()`, etc.).
@@ -78,7 +78,6 @@ runner.toFlowChart() // for subflow composition
78
78
 
79
79
  ## Rules
80
80
 
81
- - Use `CostRecorder` (not `CostRecorderV2`)
82
81
  - Never post-process — use recorders
83
82
  - Use `mock([...])` in tests
84
83
  - Use concept builders, not raw stages
@@ -101,7 +101,6 @@ runner.toFlowChart() // for subflow composition
101
101
 
102
102
  ## Rules
103
103
 
104
- - Never use `CostRecorderV2` — use `CostRecorder`
105
104
  - Never post-process — use recorders to collect data during traversal
106
105
  - Always use `mock([...])` in tests — no API keys in test suites
107
106
  - Use concept builders (`Agent.create()`, etc.) not raw stages
@@ -93,7 +93,6 @@ runner.toFlowChart() // expose for subflow composition
93
93
 
94
94
  ## Rules
95
95
 
96
- - Never use `CostRecorderV2` — use `CostRecorder`
97
96
  - Never post-process — use recorders
98
97
  - Always use `mock([...])` in tests — no API keys
99
98
  - Use concept builders, not raw stages
@@ -93,7 +93,6 @@ runner.toFlowChart() // expose for subflow composition
93
93
 
94
94
  ## Rules
95
95
 
96
- - Never use `CostRecorderV2` — use `CostRecorder`
97
96
  - Never post-process — use recorders
98
97
  - Always use `mock([...])` in tests — no API keys
99
98
  - Use concept builders, not raw stages
@@ -78,7 +78,6 @@ runner.toFlowChart() // for subflow composition
78
78
 
79
79
  ## Rules
80
80
 
81
- - Use `CostRecorder` (not `CostRecorderV2`)
82
81
  - Never post-process — use recorders
83
82
  - Use `mock([...])` in tests
84
83
  - Use concept builders, not raw stages
@@ -1 +1 @@
1
- {"version":3,"file":"CostRecorder.js","sourceRoot":"","sources":["../../../../src/recorders/v2/CostRecorder.ts"],"names":[],"mappings":"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AC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,UAAU;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;CACF"}
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * agentObservability() — one-call preset for full agent observability.
3
3
  *
4
- * Bundles TokenRecorder, ToolUsageRecorder, and CostRecorder into a single
5
- * CompositeRecorder. The consumer attaches one recorder and gets token tracking,
6
- * tool usage stats, and cost estimation without knowing the individual types.
4
+ * Bundles TokenRecorder, ToolUsageRecorder, CostRecorder, and ExplainRecorder
5
+ * into a single CompositeRecorder. One `.recorder()` call gives you token tracking,
6
+ * tool usage, cost estimation, and grounding analysis (sources vs claims).
7
7
  *
8
8
  * Stage-level timing is auto-attached by the runners (MetricRecorder on the
9
9
  * executor) — this preset covers the agent-level concerns only.
@@ -12,7 +12,6 @@
12
12
  * ```typescript
13
13
  * import { Agent, agentObservability } from 'agentfootprint';
14
14
  *
15
- * // One call — tokens, tools, and cost tracking
16
15
  * const obs = agentObservability();
17
16
  * const agent = Agent.create({ provider })
18
17
  * .recorder(obs)
@@ -20,43 +19,35 @@
20
19
  *
21
20
  * await agent.run('hello');
22
21
  *
23
- * // Access stats
24
- * console.log(obs.tokens()); // { totalCalls: 2, totalInputTokens: 150, ... }
25
- * console.log(obs.tools()); // { totalCalls: 1, byTool: { search: { calls: 1, ... } } }
26
- * console.log(obs.cost()); // 0.0042
27
- * ```
28
- *
29
- * @example
30
- * ```typescript
31
- * // With cost estimation
32
- * const obs = agentObservability({
33
- * pricing: {
34
- * 'claude-sonnet-4-20250514': { input: 3, output: 15 },
35
- * 'gpt-4o': { input: 2.5, output: 10 },
36
- * },
37
- * });
22
+ * obs.tokens(); // { totalCalls: 2, totalInputTokens: 150, ... }
23
+ * obs.tools(); // { totalCalls: 1, byTool: { search: { calls: 1, ... } } }
24
+ * obs.cost(); // 0.0042
25
+ * obs.explain(); // { sources, claims, decisions, summary }
38
26
  * ```
39
27
  */
40
28
  import { CompositeRecorder } from './CompositeRecorder';
41
29
  import { CostRecorder } from './CostRecorder';
30
+ import { ExplainRecorder } from './ExplainRecorder';
42
31
  import { TokenRecorder } from './TokenRecorder';
43
32
  import { ToolUsageRecorder } from './ToolUsageRecorder';
44
33
  /**
45
34
  * Create a bundled agent observability recorder.
46
35
  *
47
- * Tracks tokens, tool usage, and cost in a single `.recorder()` call.
36
+ * Tracks tokens, tool usage, cost, and grounding in a single `.recorder()` call.
48
37
  * Stage timing is handled separately by MetricRecorder (auto-attached by runners).
49
38
  */
50
39
  export function agentObservability(options) {
51
40
  const tokenRec = new TokenRecorder();
52
41
  const toolRec = new ToolUsageRecorder();
53
42
  const costRec = new CostRecorder(options?.pricing ? { pricingTable: options.pricing } : undefined);
54
- const composite = new CompositeRecorder([tokenRec, toolRec, costRec], options?.id ?? 'agent-observability');
43
+ const explainRec = new ExplainRecorder();
44
+ const composite = new CompositeRecorder([tokenRec, toolRec, costRec, explainRec], options?.id ?? 'agent-observability');
55
45
  // Convenience accessors — no need to dig into children
56
46
  composite.tokens = () => tokenRec.getStats();
57
47
  composite.tools = () => toolRec.getStats();
58
48
  composite.cost = () => costRec.getTotalCost();
59
49
  composite.costEntries = () => costRec.getEntries();
50
+ composite.explain = () => explainRec.explain();
60
51
  return composite;
61
52
  }
62
53
  //# sourceMappingURL=agentObservability.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agentObservability.js","sourceRoot":"","sources":["../../../../src/recorders/v2/agentObservability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAKH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,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EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,UAAU;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;CACF;AAxCD,oCAwCC"}
@@ -2,9 +2,9 @@
2
2
  /**
3
3
  * agentObservability() — one-call preset for full agent observability.
4
4
  *
5
- * Bundles TokenRecorder, ToolUsageRecorder, and CostRecorder into a single
6
- * CompositeRecorder. The consumer attaches one recorder and gets token tracking,
7
- * tool usage stats, and cost estimation without knowing the individual types.
5
+ * Bundles TokenRecorder, ToolUsageRecorder, CostRecorder, and ExplainRecorder
6
+ * into a single CompositeRecorder. One `.recorder()` call gives you token tracking,
7
+ * tool usage, cost estimation, and grounding analysis (sources vs claims).
8
8
  *
9
9
  * Stage-level timing is auto-attached by the runners (MetricRecorder on the
10
10
  * executor) — this preset covers the agent-level concerns only.
@@ -13,7 +13,6 @@
13
13
  * ```typescript
14
14
  * import { Agent, agentObservability } from 'agentfootprint';
15
15
  *
16
- * // One call — tokens, tools, and cost tracking
17
16
  * const obs = agentObservability();
18
17
  * const agent = Agent.create({ provider })
19
18
  * .recorder(obs)
@@ -21,45 +20,37 @@
21
20
  *
22
21
  * await agent.run('hello');
23
22
  *
24
- * // Access stats
25
- * console.log(obs.tokens()); // { totalCalls: 2, totalInputTokens: 150, ... }
26
- * console.log(obs.tools()); // { totalCalls: 1, byTool: { search: { calls: 1, ... } } }
27
- * console.log(obs.cost()); // 0.0042
28
- * ```
29
- *
30
- * @example
31
- * ```typescript
32
- * // With cost estimation
33
- * const obs = agentObservability({
34
- * pricing: {
35
- * 'claude-sonnet-4-20250514': { input: 3, output: 15 },
36
- * 'gpt-4o': { input: 2.5, output: 10 },
37
- * },
38
- * });
23
+ * obs.tokens(); // { totalCalls: 2, totalInputTokens: 150, ... }
24
+ * obs.tools(); // { totalCalls: 1, byTool: { search: { calls: 1, ... } } }
25
+ * obs.cost(); // 0.0042
26
+ * obs.explain(); // { sources, claims, decisions, summary }
39
27
  * ```
40
28
  */
41
29
  Object.defineProperty(exports, "__esModule", { value: true });
42
30
  exports.agentObservability = void 0;
43
31
  const CompositeRecorder_1 = require("./CompositeRecorder");
44
32
  const CostRecorder_1 = require("./CostRecorder");
33
+ const ExplainRecorder_1 = require("./ExplainRecorder");
45
34
  const TokenRecorder_1 = require("./TokenRecorder");
46
35
  const ToolUsageRecorder_1 = require("./ToolUsageRecorder");
47
36
  /**
48
37
  * Create a bundled agent observability recorder.
49
38
  *
50
- * Tracks tokens, tool usage, and cost in a single `.recorder()` call.
39
+ * Tracks tokens, tool usage, cost, and grounding in a single `.recorder()` call.
51
40
  * Stage timing is handled separately by MetricRecorder (auto-attached by runners).
52
41
  */
53
42
  function agentObservability(options) {
54
43
  const tokenRec = new TokenRecorder_1.TokenRecorder();
55
44
  const toolRec = new ToolUsageRecorder_1.ToolUsageRecorder();
56
45
  const costRec = new CostRecorder_1.CostRecorder(options?.pricing ? { pricingTable: options.pricing } : undefined);
57
- const composite = new CompositeRecorder_1.CompositeRecorder([tokenRec, toolRec, costRec], options?.id ?? 'agent-observability');
46
+ const explainRec = new ExplainRecorder_1.ExplainRecorder();
47
+ const composite = new CompositeRecorder_1.CompositeRecorder([tokenRec, toolRec, costRec, explainRec], options?.id ?? 'agent-observability');
58
48
  // Convenience accessors — no need to dig into children
59
49
  composite.tokens = () => tokenRec.getStats();
60
50
  composite.tools = () => toolRec.getStats();
61
51
  composite.cost = () => costRec.getTotalCost();
62
52
  composite.costEntries = () => costRec.getEntries();
53
+ composite.explain = () => explainRec.explain();
63
54
  return composite;
64
55
  }
65
56
  exports.agentObservability = agentObservability;
@@ -1 +1 @@
1
- {"version":3,"file":"agentObservability.js","sourceRoot":"","sources":["../../../src/recorders/v2/agentObservability.ts"],"names":[],"mappings":";AAAA;;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G,IAAI,6BAAa,EAAE,CAAC;IACrC,MAAM,OAAO,GAAG,IAAI,qCAAiB,EAAE,CAAC;IACxC,MAAM,OAAO,GAAG,IAAI,2BAAY,CAC9B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CACjE,CAAC;IACF,MAAM,UAAU,GAAG,IAAI,iCAAe,EAAE,CAAC;IAEzC,MAAM,SAAS,GAAG,IAAI,qCAAiB,CACrC,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,EACxC,OAAO,EAAE,EAAE,IAAI,qBAAqB,CACP,CAAC;IAEhC,uDAAuD;IACvD,SAAS,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAC7C,SAAS,CAAC,KAAK,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC3C,SAAS,CAAC,IAAI,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;IAC9C,SAAS,CAAC,WAAW,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;IACnD,SAAS,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;IAE/C,OAAO,SAAS,CAAC;AACnB,CAAC;AAvBD,gDAuBC"}
@@ -11,12 +11,8 @@
11
11
  * console.log(`$${cost.getTotalCost().toFixed(4)}`);
12
12
  */
13
13
  import type { AgentRecorder, LLMCallEvent } from '../../core';
14
- export interface ModelPricing {
15
- /** Cost per 1M input tokens in USD. */
16
- readonly input: number;
17
- /** Cost per 1M output tokens in USD. */
18
- readonly output: number;
19
- }
14
+ import type { ModelPricing } from '../../models/types';
15
+ export type { ModelPricing } from '../../models/types';
20
16
  export interface CostEntry {
21
17
  readonly model: string;
22
18
  readonly inputTokens: number;
@@ -1 +1 @@
1
- {"version":3,"file":"CostRecorder.d.ts","sourceRoot":"","sources":["../../../../src/recorders/v2/CostRecorder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACtD;AAED,qBAAa,YAAa,YAAW,aAAa;IAChD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,YAAY,CAA+B;gBAEvC,OAAO,GAAE,mBAAwB;IAK7C,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAmBpC,YAAY,IAAI,MAAM;IAItB,UAAU,IAAI,SAAS,EAAE;IAIzB,KAAK,IAAI,IAAI;CAGd"}
1
+ {"version":3,"file":"CostRecorder.d.ts","sourceRoot":"","sources":["../../../../src/recorders/v2/CostRecorder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACtD;AAED,qBAAa,YAAa,YAAW,aAAa;IAChD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,YAAY,CAA+B;gBAEvC,OAAO,GAAE,mBAAwB;IAK7C,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAmBpC,YAAY,IAAI,MAAM;IAItB,UAAU,IAAI,SAAS,EAAE;IAIzB,KAAK,IAAI,IAAI;CAGd"}
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * agentObservability() — one-call preset for full agent observability.
3
3
  *
4
- * Bundles TokenRecorder, ToolUsageRecorder, and CostRecorder into a single
5
- * CompositeRecorder. The consumer attaches one recorder and gets token tracking,
6
- * tool usage stats, and cost estimation without knowing the individual types.
4
+ * Bundles TokenRecorder, ToolUsageRecorder, CostRecorder, and ExplainRecorder
5
+ * into a single CompositeRecorder. One `.recorder()` call gives you token tracking,
6
+ * tool usage, cost estimation, and grounding analysis (sources vs claims).
7
7
  *
8
8
  * Stage-level timing is auto-attached by the runners (MetricRecorder on the
9
9
  * executor) — this preset covers the agent-level concerns only.
@@ -12,7 +12,6 @@
12
12
  * ```typescript
13
13
  * import { Agent, agentObservability } from 'agentfootprint';
14
14
  *
15
- * // One call — tokens, tools, and cost tracking
16
15
  * const obs = agentObservability();
17
16
  * const agent = Agent.create({ provider })
18
17
  * .recorder(obs)
@@ -20,26 +19,16 @@
20
19
  *
21
20
  * await agent.run('hello');
22
21
  *
23
- * // Access stats
24
- * console.log(obs.tokens()); // { totalCalls: 2, totalInputTokens: 150, ... }
25
- * console.log(obs.tools()); // { totalCalls: 1, byTool: { search: { calls: 1, ... } } }
26
- * console.log(obs.cost()); // 0.0042
27
- * ```
28
- *
29
- * @example
30
- * ```typescript
31
- * // With cost estimation
32
- * const obs = agentObservability({
33
- * pricing: {
34
- * 'claude-sonnet-4-20250514': { input: 3, output: 15 },
35
- * 'gpt-4o': { input: 2.5, output: 10 },
36
- * },
37
- * });
22
+ * obs.tokens(); // { totalCalls: 2, totalInputTokens: 150, ... }
23
+ * obs.tools(); // { totalCalls: 1, byTool: { search: { calls: 1, ... } } }
24
+ * obs.cost(); // 0.0042
25
+ * obs.explain(); // { sources, claims, decisions, summary }
38
26
  * ```
39
27
  */
40
28
  import type { ModelPricing, CostEntry } from './CostRecorder';
41
29
  import type { TokenStats } from './TokenRecorder';
42
30
  import type { ToolUsageStats } from './ToolUsageRecorder';
31
+ import type { Explanation } from './ExplainRecorder';
43
32
  import { CompositeRecorder } from './CompositeRecorder';
44
33
  export interface AgentObservabilityOptions {
45
34
  /** Custom ID for the composite recorder. Default: 'agent-observability'. */
@@ -57,11 +46,13 @@ export interface AgentObservabilityRecorder extends CompositeRecorder {
57
46
  cost(): number;
58
47
  /** Per-call cost breakdown. */
59
48
  costEntries(): CostEntry[];
49
+ /** Grounding analysis — sources (tool results) vs claims (LLM output). */
50
+ explain(): Explanation;
60
51
  }
61
52
  /**
62
53
  * Create a bundled agent observability recorder.
63
54
  *
64
- * Tracks tokens, tool usage, and cost in a single `.recorder()` call.
55
+ * Tracks tokens, tool usage, cost, and grounding in a single `.recorder()` call.
65
56
  * Stage timing is handled separately by MetricRecorder (auto-attached by runners).
66
57
  */
67
58
  export declare function agentObservability(options?: AgentObservabilityOptions): AgentObservabilityRecorder;
@@ -1 +1 @@
1
- {"version":3,"file":"agentObservability.d.ts","sourceRoot":"","sources":["../../../../src/recorders/v2/agentObservability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAKxD,MAAM,WAAW,yBAAyB;IACxC,4EAA4E;IAC5E,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACxC;AAED,sEAAsE;AACtE,MAAM,WAAW,0BAA2B,SAAQ,iBAAiB;IACnE,8CAA8C;IAC9C,MAAM,IAAI,UAAU,CAAC;IACrB,8DAA8D;IAC9D,KAAK,IAAI,cAAc,CAAC;IACxB,gCAAgC;IAChC,IAAI,IAAI,MAAM,CAAC;IACf,+BAA+B;IAC/B,WAAW,IAAI,SAAS,EAAE,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,CAAC,EAAE,yBAAyB,GAClC,0BAA0B,CAmB5B"}
1
+ {"version":3,"file":"agentObservability.d.ts","sourceRoot":"","sources":["../../../../src/recorders/v2/agentObservability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAMxD,MAAM,WAAW,yBAAyB;IACxC,4EAA4E;IAC5E,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACxC;AAED,sEAAsE;AACtE,MAAM,WAAW,0BAA2B,SAAQ,iBAAiB;IACnE,8CAA8C;IAC9C,MAAM,IAAI,UAAU,CAAC;IACrB,8DAA8D;IAC9D,KAAK,IAAI,cAAc,CAAC;IACxB,gCAAgC;IAChC,IAAI,IAAI,MAAM,CAAC;IACf,+BAA+B;IAC/B,WAAW,IAAI,SAAS,EAAE,CAAC;IAC3B,0EAA0E;IAC1E,OAAO,IAAI,WAAW,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,CAAC,EAAE,yBAAyB,GAClC,0BAA0B,CAqB5B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentfootprint",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "The explainable agent framework — build AI agents you can explain, audit, and trust. Built on footprintjs.",
5
5
  "license": "MIT",
6
6
  "author": "Sanjay Krishna Anbalagan",