@tangle-network/agent-knowledge 4.0.1 → 5.0.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 (37) hide show
  1. package/AGENTS.md +35 -19
  2. package/CHANGELOG.md +48 -0
  3. package/README.md +220 -943
  4. package/dist/benchmarks/index.d.ts +3 -2
  5. package/dist/benchmarks/index.js +1 -1
  6. package/dist/{chunk-EUAXSBMH.js → chunk-AKYJG2MR.js} +224 -224
  7. package/dist/chunk-AKYJG2MR.js.map +1 -0
  8. package/dist/{chunk-BBCIB4UL.js → chunk-EYIA5PLQ.js} +27 -195
  9. package/dist/chunk-EYIA5PLQ.js.map +1 -0
  10. package/dist/{chunk-3CAAGJCE.js → chunk-LMR53POQ.js} +1227 -574
  11. package/dist/chunk-LMR53POQ.js.map +1 -0
  12. package/dist/{chunk-WCYW2GDA.js → chunk-MYFM6LKH.js} +2 -2
  13. package/dist/chunk-MYFM6LKH.js.map +1 -0
  14. package/dist/cli.js +1 -1
  15. package/dist/index-Cf7txrYP.d.ts +790 -0
  16. package/dist/index.d.ts +252 -73
  17. package/dist/index.js +2813 -2229
  18. package/dist/index.js.map +1 -1
  19. package/dist/memory/index.d.ts +8 -709
  20. package/dist/memory/index.js +2 -2
  21. package/dist/sources/index.d.ts +17 -33
  22. package/dist/sources/index.js +1 -1
  23. package/dist/{types-ZzY_x0r7.d.ts → types-BY-xLVw-.d.ts} +28 -67
  24. package/docs/eval/investment-material-facts.md +28 -29
  25. package/docs/eval/rag-eval-roadmap.md +21 -17
  26. package/docs/results/adaptive.md +13 -13
  27. package/docs/results/claim-grounding.md +11 -11
  28. package/docs/results/cost-quality.md +4 -4
  29. package/docs/results/investment-thesis.md +56 -56
  30. package/docs/results/research-driving.md +54 -54
  31. package/docs/two-agent-research-ab.md +94 -94
  32. package/package.json +11 -11
  33. package/skills/build-with-agent-knowledge/SKILL.md +97 -0
  34. package/dist/chunk-3CAAGJCE.js.map +0 -1
  35. package/dist/chunk-BBCIB4UL.js.map +0 -1
  36. package/dist/chunk-EUAXSBMH.js.map +0 -1
  37. package/dist/chunk-WCYW2GDA.js.map +0 -1
package/AGENTS.md CHANGED
@@ -2,22 +2,31 @@
2
2
 
3
3
  Use this package when an agent needs persistent, source-grounded knowledge that improves over time.
4
4
 
5
- ## Repo layering — this package depends on agent-eval, never the reverse
5
+ ## Package layering
6
6
 
7
7
  ```
8
- agent-knowledge (this repo) ─┐
9
- ├──► agent-eval (substrate — the bottom)
10
- agent-runtime ───────────────┘
8
+ agent-runtime
9
+ |
10
+ agent-knowledge
11
+ / \
12
+ agent-eval agent-interface
11
13
  ```
12
14
 
13
- **Rule: agent-knowledge depends on agent-eval. agent-eval MUST NOT import from agent-knowledge.** No upward imports, no peerDependency declaration in agent-eval pointing at agent-knowledge. Substrate primitives that agent-knowledge needs (`AnalystFinding`, `RunRecord`, optimizer types, release-confidence types) live in agent-eval; this repo consumes them.
15
+ Imports flow downward in this diagram.
16
+ `agent-knowledge` may import `agent-eval` and `agent-interface`, but it must not import `agent-runtime`.
17
+ Agent-powered work enters this package through callbacks.
18
+ `agent-runtime` owns live agent execution and composes this package when a complete agent workflow is needed.
19
+ `agent-eval` must not import `agent-knowledge`.
20
+ Shared run and experiment types that knowledge needs live in `agent-eval`.
14
21
 
15
22
  Types that stay in THIS repo because they're knowledge-domain-shaped:
16
23
  - `KbStore`, `KnowledgeFragment`, `KnowledgeChange`
17
24
  - `KnowledgeDiscoveryDispatcher`, source adapters (`createCornellLiiSource`, `createIrsPublicationsSource`)
18
25
  - Freshness store + change-detection primitives
19
26
 
20
- **The test for "where does a type live?"** — does this concept make sense WITHOUT persistent knowledge or sourced fragments? If yes, it's substrate (agent-eval). If no, it's a knowledge-domain concept (stays here).
27
+ **The test for "where does a type live?"**
28
+ If the concept makes sense without persistent knowledge or sourced fragments, it belongs in `agent-eval` or `agent-interface`.
29
+ Otherwise, it stays in this package.
21
30
 
22
31
  ## Rules
23
32
 
@@ -66,42 +75,50 @@ The parser rejects absolute paths, `..`, control characters, and writes outside
66
75
 
67
76
  ## Eval Boundary
68
77
 
69
- Compare candidate knowledge bases on an actual task corpus by running an `@tangle-network/agent-eval` improvement loop (`runImprovementLoop`) over the variants; each run is scored into a `RunRecord`.
78
+ Use a complete `OptimizationMethod` from `@tangle-network/agent-eval` with `runRetrievalImprovementLoop()`, `runRagOptimization()`, `optimizeKnowledgeBasePolicy()`, or `runAgentMemoryImprovement()`.
79
+ The method owns candidate search and resume compatibility.
80
+ This package owns serialized knowledge candidates, real KB or memory adapters, isolated data partitions, and safe activation.
70
81
 
71
82
  Use `knowledgeReleaseReport()` before promotion. It folds the candidate and baseline `RunRecord[]` (plus optional traces and the gate decision) into `agent-eval` release confidence evidence.
72
83
 
73
84
  ## Integration Boundaries
74
85
 
75
- - Use `KbStore` for storage. Implement D1 in the consuming app when needed.
76
- - Use `KnowledgeDiscoveryDispatcher` for research workers. Production apps should wire this to their own swarm/fleet runtime.
86
+ - Use `KbStore` for storage. Applications may provide any durable backend that implements it.
87
+ - Use `KnowledgeDiscoveryDispatcher` for research workers. Applications should connect it to their own runtime.
77
88
  - Do not bypass `lint` or `validate` before using generated knowledge in an agent.
78
89
 
79
90
  ## Pluggable Sources + Freshness + Changes
80
91
 
81
92
  Agents that need to stay current against external authorities should compose:
82
93
 
83
- - `createCornellLiiSource({ selectors })` US Code + Wex from law.cornell.edu.
84
- - `createIrsPublicationsSource({ publications, revenueProcedures })` IRS index + named pubs.
85
- - `createStateSosSource({ state, baseUrl, entities })` generic state SOS adapter.
94
+ - `createCornellLiiSource({ selectors })`: US Code and Wex from law.cornell.edu.
95
+ - `createIrsPublicationsSource({ publications, revenueProcedures })`: IRS index and named publications.
96
+ - `createStateSosSource({ state, baseUrl, entities })`: generic state SOS adapter.
86
97
 
87
- Every fetch returns `KnowledgeFragment[]` with `provenance.verifiable` indicating whether the authority was successfully authenticated. Refuse to cite fragments with `verifiable: false`.
98
+ Every fetch returns `KnowledgeFragment[]` with `provenance.verifiable` indicating whether the configured URL returned an acceptable response and the expected content was extracted.
99
+ This flag does not authenticate the publisher or cryptographically prove the content.
100
+ Refuse to cite fragments with `verifiable: false`.
88
101
 
89
102
  Track per-tenant freshness with `createFileSystemFreshnessStore({ root })` and re-fetch only when `stale({ workspaceId, sourceId, ttlMs })` returns true.
90
103
 
91
- Diff snapshots with `detectChanges(prev, next)`. Each `KnowledgeChange` carries `affectedDimensions` — pass those to your eval scheduler to re-run only the relevant campaigns.
104
+ Diff snapshots with `detectChanges(prev, next)`.
105
+ Each `KnowledgeChange` carries `affectedDimensions`; pass those to your eval scheduler to run only the relevant campaigns again.
92
106
 
93
107
  ## Authorship
94
108
 
95
- Do not add `Co-Authored-By:` trailers (or any other AI-attribution lines) to commits, PR descriptions, or other artifacts in this repo. Author = the human running the session. Applies to every contributor, including AI agents and subagents — do not include the default Claude Code template trailer.
109
+ Do not add `Co-Authored-By:` trailers or other AI-attribution lines to commits, PR descriptions, or repository artifacts.
110
+ The author is the human running the session.
96
111
 
97
112
  ## Comment & doc discipline (no historical narrative)
98
113
 
99
- Comments describe **what the code does and why** — never what it used to do, what it replaced, which audit found a bug, or what the prior version looked like. History belongs in commit messages and PR descriptions, not the source tree.
114
+ Comments describe **what the code does and why**.
115
+ They must not describe what code used to do, what it replaced, which audit found a bug, or what a prior version looked like.
116
+ History belongs in commit messages and PR descriptions.
100
117
 
101
118
  - Bad: `// replaces the inline retry loop`, `// fix for the silent-zero bug`, `// the 2yr rewrite added this`, `// audit fix`
102
- - Good: `// value: null when retries exhaust callers must inspect succeeded`
119
+ - Good: `// value is null when retries exhaust; callers must inspect succeeded`
103
120
 
104
- Applies to docstrings, README sections, SKILL.md, AGENTS.md, CLAUDE.md — anywhere the source tree carries prose.
121
+ This applies anywhere the repository carries prose.
105
122
 
106
123
  ## No fallbacks. Fail loud.
107
124
 
@@ -110,4 +127,3 @@ Sloppy fallbacks corrupt every signal downstream. No silent zeros, no `?? defaul
110
127
  External-boundary calls (LLM, network, FS, subprocess) return *typed outcomes* (`{ succeeded, value, error }`). Callers MUST inspect `succeeded` before using `value`. Named, opted-in fallback rotations (`policy.fallbackModels: [...]`) are fine; deep `?? "kimi"` helpers are not.
111
128
 
112
129
  Full doctrine: `~/dotfiles/claude/AGENTS.md` → "No fallbacks. Fail loud."
113
-
package/CHANGELOG.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.0.0
4
+
5
+ ### Breaking Changes
6
+
7
+ - Retrieval improvement now requires independent train, selection, and final scenarios plus an explicit complete `OptimizationMethod`.
8
+ - Serialized retrieval and RAG optimization now requires an immutable `executionRef` covering candidate execution and scoring behavior.
9
+ - Memory configuration improvement now requires a baseline configuration, a complete `OptimizationMethod`, and independent train, selection, and final histories.
10
+ - The RAG lifecycle promotion callback is now `decidePromotion` and runs only after final evidence passes regression, provenance, and cost checks.
11
+ - Knowledge improvement requires an immutable `implementationRef`, separates repeatable development evaluation from single-use final evaluation, and refuses to resume after interrupted final scoring.
12
+ - Memory candidate factories no longer receive scenario, repetition, or seed identity and must report observed external charges through `recordExternalCost()`.
13
+ - Answer-quality hooks require immutable evaluator identity, final scenario identity, and complete cost evidence.
14
+ - Removed the public retrieval and memory proposer-search options; candidate generation and selection now belong to `agent-eval` methods.
15
+
16
+ ### Added
17
+
18
+ - Added a shared serialized-candidate adapter for running complete `agent-eval` optimization methods with canonical candidate identity and untouched final comparison.
19
+ - Added full RAG configuration optimization and KB maintenance policy optimization.
20
+ - Added direct support for official GEPA and SkillOpt methods through the shared `OptimizationMethod` contract.
21
+ - Added durable per-configuration memory candidate identities to prevent stale result reuse.
22
+ - Added live activation verification so resumed memory runs reject configuration drift.
23
+ - Added private execution contexts that expose memory operations, cancellation, and cost metering without evaluation labels.
24
+
25
+ ### Changed
26
+
27
+ - Updated `@tangle-network/agent-eval` to `0.126.5` and `@tangle-network/agent-interface` to `0.32.0`.
28
+ - Kept memory provider evaluations resumable and branch-isolated while moving search ownership to the supplied method.
29
+ - Restricted immutable references to lowercase SHA-256 and full Git commit identities.
30
+
31
+ ## 4.1.0
32
+
33
+ ### Added
34
+
35
+ - Added optional scenario input to `knowledgeReleaseReport()` so a required holdout can prove both scenario and run coverage.
36
+
37
+ ### Changed
38
+
39
+ - Split knowledge-base improvement and RAG evaluation internals into focused modules while preserving public exports and implementation behavior.
40
+ - Split the knowledge improvement tests into candidate, promotion, activation, and integrity suites with shared setup in one support module.
41
+ - Removed unused development dependencies and internal-only exports.
42
+ - Updated the test runner to Vitest 4 and Node type definitions to 26; TypeScript remains on 5.9 because tsup's declaration bundler does not yet support TypeScript 7.
43
+ - Declared Node types explicitly in TypeScript configuration instead of relying on ambient type discovery.
44
+ - Corrected the package dependency guide and RAG roadmap to reflect runtime-owned agent execution through `runKnowledgeImprovementJob()`.
45
+ - Removed historical commentary and em dashes from repository documentation.
46
+
47
+ ### Fixed
48
+
49
+ - Replaced the stale versioned HTTP user agent with a stable package identity and added request-header coverage.
50
+
3
51
  ## 4.0.1
4
52
 
5
53
  ### Changed