@tangle-network/agent-knowledge 20.0.1 → 22.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.
- package/CHANGELOG.md +21 -0
- package/README.md +8 -6
- package/dist/cli.js +2 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +100 -118
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +242 -3
- package/dist/index.js.map +1 -1
- package/dist/{inspect-CMigdsD5.js → inspect-B1VI49Y9.js} +285 -299
- package/dist/inspect-B1VI49Y9.js.map +1 -0
- package/dist/search/index.d.ts +3 -0
- package/dist/search/index.js +2 -0
- package/dist/search-BBr5eUyT.js +275 -0
- package/dist/search-BBr5eUyT.js.map +1 -0
- package/dist/search-Dde0PEtY.d.ts +120 -0
- package/dist/search-Dde0PEtY.d.ts.map +1 -0
- package/docs/agent-tools.md +60 -0
- package/docs/architecture.md +40 -1
- package/docs/cli.md +19 -0
- package/docs/compatibility.md +12 -0
- package/docs/improvement.md +79 -0
- package/docs/memory.md +12 -0
- package/docs/provenance.md +50 -0
- package/docs/rag-evaluation.md +82 -0
- package/package.json +13 -7
- package/dist/inspect-CMigdsD5.js.map +0 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Improve a live knowledge base
|
|
2
|
+
|
|
3
|
+
> Extracted from the README — see the [README](../README.md) for the package overview.
|
|
4
|
+
|
|
5
|
+
## Improve a live knowledge base
|
|
6
|
+
|
|
7
|
+
`improveKnowledgeBase` creates an isolated candidate, runs your update callback, measures the candidate, and returns an exact candidate reference.
|
|
8
|
+
It does not overwrite the live knowledge base.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import {
|
|
12
|
+
improveKnowledgeBase,
|
|
13
|
+
knowledgeImprovementCandidateRef,
|
|
14
|
+
promoteKnowledgeCandidate,
|
|
15
|
+
} from '@tangle-network/agent-knowledge'
|
|
16
|
+
|
|
17
|
+
const result = await improveKnowledgeBase({
|
|
18
|
+
root: './support-kb',
|
|
19
|
+
goal: 'Answer refund questions using the current policy',
|
|
20
|
+
implementationRef: 'git:0123456789abcdef0123456789abcdef01234567',
|
|
21
|
+
runId: 'refund-policy-2026-07',
|
|
22
|
+
maxCandidates: 3,
|
|
23
|
+
updateKnowledge: async ({ candidateRoot }) => {
|
|
24
|
+
await updateCandidate(candidateRoot) // Your code or agent writes only to this copy.
|
|
25
|
+
return { applied: true, summary: 'Updated refund knowledge' }
|
|
26
|
+
},
|
|
27
|
+
evaluate: ({ baselineRoot, candidateRoot }) =>
|
|
28
|
+
compareOnProductTasks({ baselineRoot, candidateRoot }),
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
if (result.candidate && result.evaluation?.passed) {
|
|
32
|
+
const candidate = knowledgeImprovementCandidateRef(result)
|
|
33
|
+
// Call this only after your application approves the measured candidate.
|
|
34
|
+
await promoteKnowledgeCandidate({ root: './support-kb', candidate })
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`updateCandidate` and `compareOnProductTasks` are application callbacks.
|
|
39
|
+
The update can come from a research agent, a coding agent, a source connector, or deterministic code.
|
|
40
|
+
The comparison must return the product measures that decide whether the change helped.
|
|
41
|
+
|
|
42
|
+
Use the same `runId` and `implementationRef` to resume an interrupted run.
|
|
43
|
+
Change `implementationRef` whenever callbacks, evaluation policy, models, indexes, or external configuration change.
|
|
44
|
+
Reusing a run ID with a different implementation reference fails before cached work or callbacks run.
|
|
45
|
+
Different run IDs create separate candidate workspaces, so workers can explore in parallel.
|
|
46
|
+
Promotion checks the original base hash and rejects a stale candidate instead of replacing newer work.
|
|
47
|
+
Candidate retries use `evaluateDevelopment` when provided, otherwise they use deterministic validation, readiness, and KB quality checks.
|
|
48
|
+
Diagnosis runs before acquisition and updates, using development data only.
|
|
49
|
+
Its findings and update results remain available to final answer checks and the promotion decision.
|
|
50
|
+
Development evaluation must use only train or selection data.
|
|
51
|
+
The configured `evaluate` callback and final RAG phases run once, on the first candidate that passes those development checks.
|
|
52
|
+
A failed final evaluation ends the run instead of selecting another candidate against final data.
|
|
53
|
+
|
|
54
|
+
The default evaluator reports only measured dimensions and averages those dimensions with equal weight.
|
|
55
|
+
It omits `answer_quality` without answer evaluation, `promotion_decision` without a promotion decision, and `blocking_readiness` without blocking readiness requirements.
|
|
56
|
+
Default evaluator version `2` records this weighting.
|
|
57
|
+
Declare additional authoritative local state through `stateScope`:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const stateScope = { pagesDirectory: 'kb/pages', researchState: true }
|
|
61
|
+
const result = await improveKnowledgeBase({ ...options, stateScope })
|
|
62
|
+
const identity = await hashKnowledgeBase(root, stateScope)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The default scope remains `knowledge/`, `raw/`, and `.agent-knowledge/sources.json`.
|
|
66
|
+
`pagesDirectory` replaces the default page directory for copying, indexing, hashing, and promotion.
|
|
67
|
+
`researchState: true` also includes canonical `.agent-knowledge/claim-ledgers/` records and `.agent-knowledge/events.json`.
|
|
68
|
+
The persisted run binds this scope, and resume rejects a different scope.
|
|
69
|
+
Candidate materialization, selected changes, promotion, and restoration preserve the same declared state.
|
|
70
|
+
Use `normalizeKnowledgeStateScope` when carrying this scope into another contract.
|
|
71
|
+
Indexes, locks, transaction journals, retrieval artifacts, credentials outside declared content directories, and external memory providers remain outside this identity.
|
|
72
|
+
Use the canonical `FileSystemKbStore({ root: candidateRoot })` for research records in update callbacks.
|
|
73
|
+
Callbacks must bind external state separately and must not close over a shared mutable store when evaluating isolated candidates.
|
|
74
|
+
A scoped KB hash does not identify an entire learner with external state.
|
|
75
|
+
|
|
76
|
+
A candidate can pass structural checks without any task outcome evaluation; the metric notes state this limit.
|
|
77
|
+
`candidate-ready` means the configured checks passed and the candidate remains detached from the live knowledge base.
|
|
78
|
+
|
|
79
|
+
Candidate promotion currently requires Linux because it relies on Linux directory descriptors for exact file identity.
|
package/docs/memory.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Integrate memory systems
|
|
2
|
+
|
|
3
|
+
> Extracted from the README — see the [README](../README.md) for the package overview.
|
|
4
|
+
|
|
5
|
+
## Integrate memory systems
|
|
6
|
+
|
|
7
|
+
`@tangle-network/agent-knowledge/memory` defines `AgentMemoryAdapter` and adapters for Mem0, Graphiti, and Neo4j Agent Memory.
|
|
8
|
+
The package is not a memory database.
|
|
9
|
+
Install the provider you use, create its client, and pass that client to the adapter.
|
|
10
|
+
|
|
11
|
+
The memory APIs support scoped reads and writes and isolated branches.
|
|
12
|
+
Compare providers on product tasks with `@tangle-network/agent-eval` before changing production behavior.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Prove what the agent saw and used
|
|
2
|
+
|
|
3
|
+
> Extracted from the README — see the [README](../README.md) for the package overview.
|
|
4
|
+
|
|
5
|
+
## Prove what the agent saw and used
|
|
6
|
+
|
|
7
|
+
A page existing in a knowledge base, a page appearing in retrieval results, and a page influencing a decision are three different facts. The receipt APIs preserve those joins without pretending they prove the page is true or that it improved the outcome.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import {
|
|
11
|
+
createKnowledgeRetrievalReceipt,
|
|
12
|
+
createKnowledgeUseReceipt,
|
|
13
|
+
createKnowledgeVisibilitySnapshot,
|
|
14
|
+
encodeKnowledgeVisibilitySnapshot,
|
|
15
|
+
KNOWLEDGE_SEARCH_RETRIEVER_ID,
|
|
16
|
+
knowledgeVisibilityArtifactRef,
|
|
17
|
+
} from '@tangle-network/agent-knowledge'
|
|
18
|
+
|
|
19
|
+
const visibility = createKnowledgeVisibilitySnapshot(await runStores.loadChain(runId))
|
|
20
|
+
const bytes = encodeKnowledgeVisibilitySnapshot(visibility)
|
|
21
|
+
await artifacts.put('artifact://run/visibility.json', bytes)
|
|
22
|
+
|
|
23
|
+
const retrieval = createKnowledgeRetrievalReceipt({
|
|
24
|
+
runId,
|
|
25
|
+
query: 'prior verifier obstruction',
|
|
26
|
+
retriever: { id: KNOWLEDGE_SEARCH_RETRIEVER_ID, version: '1.0.0', configDigest },
|
|
27
|
+
visibility,
|
|
28
|
+
visibilityArtifact: knowledgeVisibilityArtifactRef({
|
|
29
|
+
uri: 'artifact://run/visibility.json',
|
|
30
|
+
bytes,
|
|
31
|
+
}),
|
|
32
|
+
results,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const use = createKnowledgeUseReceipt({
|
|
36
|
+
retrieval,
|
|
37
|
+
selectedRank: 1,
|
|
38
|
+
relation: 'extends',
|
|
39
|
+
consumer: { kind: 'artifact', uri: 'artifact://run/DECISION.md', digest },
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
console.log(visibility.snapshotDigest, retrieval.receiptDigest, use.receiptDigest)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
ELI5: the visibility snapshot is the bookshelf the agent was allowed to see, the retrieval receipt is the exact books search handed back, and the use receipt records which returned book the agent attached to a downstream decision or artifact.
|
|
46
|
+
|
|
47
|
+
Create the snapshot once per knowledge view and reuse it: the retrieval receipt stores the snapshot's digest, page count, and storage locator, not its pages, so repeated queries over one view do not re-serialize the inventory.
|
|
48
|
+
`verifyKnowledgeRetrievalReceipt` proves the receipt itself; `assertKnowledgeRetrievalMatchesVisibility` and `assertKnowledgeRetrievalMatchesVisibilityArtifact` prove that every returned result occurs in that exact snapshot.
|
|
49
|
+
|
|
50
|
+
The receipts are content-addressed and mutation-sensitive. They do **not** establish correctness, novelty, compliance, or causal lift; Eval owns those later judgments. Read [knowledge retrieval and use receipts](docs/knowledge-use-receipts.md) for the complete proof boundary, trace attributes, and experiment design.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Evaluate and improve RAG
|
|
2
|
+
|
|
3
|
+
> Extracted from the README — see the [README](../README.md) for the package overview.
|
|
4
|
+
|
|
5
|
+
## Evaluate and improve RAG
|
|
6
|
+
|
|
7
|
+
Use the narrowest API that matches the job:
|
|
8
|
+
|
|
9
|
+
| API | What it does |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `runRetrievalImprovementLoop` | Runs one complete `OptimizationMethod` over serialized retrieval configuration. |
|
|
12
|
+
| `runRagOptimization` | Optimizes retrieval and answer behavior as one serialized RAG configuration. |
|
|
13
|
+
| `scoreKnowledgeBaseIndex` | Measures KB structure, citations, source freshness, and configured quality thresholds. |
|
|
14
|
+
| `runRagKnowledgeImprovementLoop` | Connects retrieval tuning, gap diagnosis, source acquisition, KB updates, answer checks, and a promotion decision. |
|
|
15
|
+
| `improveKnowledgeBase` | Adds resumable state, isolated candidates, exact promotion, and conflict detection around that process. |
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import type {
|
|
19
|
+
OptimizationMethod,
|
|
20
|
+
} from '@tangle-network/agent-eval/campaign'
|
|
21
|
+
import {
|
|
22
|
+
runRetrievalImprovementLoop,
|
|
23
|
+
type RetrievalEvalArtifact,
|
|
24
|
+
type RetrievalEvalScenario,
|
|
25
|
+
} from '@tangle-network/agent-knowledge'
|
|
26
|
+
|
|
27
|
+
async function tuneRetrieval(
|
|
28
|
+
method: OptimizationMethod<RetrievalEvalScenario, RetrievalEvalArtifact>,
|
|
29
|
+
) {
|
|
30
|
+
return runRetrievalImprovementLoop({
|
|
31
|
+
executionRef: 'git:0123456789abcdef0123456789abcdef01234567',
|
|
32
|
+
baseline: { k: 5, reranker: false },
|
|
33
|
+
method,
|
|
34
|
+
trainScenarios,
|
|
35
|
+
selectionScenarios,
|
|
36
|
+
finalScenarios,
|
|
37
|
+
retrieve: ({ scenario, config, k }) => search(scenario.query, { ...config, k }),
|
|
38
|
+
runDir: 'refund-retrieval',
|
|
39
|
+
expectUsage: 'off', // Local search does not make a billable model call.
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The method receives train and selection cases.
|
|
45
|
+
`agent-eval` keeps final cases out of the search and measures the exact selected configuration on them afterward.
|
|
46
|
+
Every optimization call requires an explicit complete method.
|
|
47
|
+
Create an official method with `gepaOptimizationMethod()` or `skillOptOptimizationMethod()` from `@tangle-network/agent-eval/campaign`, or pass another complete public `OptimizationMethod`.
|
|
48
|
+
Reuse the run directory only with the method's compatible resume mode.
|
|
49
|
+
Use separate run directories to explore branches in parallel.
|
|
50
|
+
Optimizer-specific identity and resume settings stay on the supplied method; this package does not reinterpret them.
|
|
51
|
+
The supplied method owns its engine inputs and resume state.
|
|
52
|
+
`executionRef` owns retrieval, index, judge, model, and external-service identity.
|
|
53
|
+
Use `git:<40 lowercase hex>` or `sha256:<64 lowercase hex>` and change it whenever any candidate execution or scoring behavior changes.
|
|
54
|
+
Each candidate has one canonical serialized identity.
|
|
55
|
+
See the [`agent-eval` method guide](https://github.com/tangle-network/agent-eval/blob/main/docs/campaign-proposers.md) for official GEPA and SkillOpt methods.
|
|
56
|
+
SkillOpt is skill-only; use it here only when the serialized candidate is itself a skill.
|
|
57
|
+
Read reported spend from `result.comparison.totalCost` and upstream source and run identity from `result.comparison.best.provenance`.
|
|
58
|
+
Official external methods must report observed package identity.
|
|
59
|
+
Custom in-process methods have no external package identity, so their behavior must be covered by `executionRef`.
|
|
60
|
+
Treat `accountingComplete: false` as incomplete evidence for activation.
|
|
61
|
+
|
|
62
|
+
Retrieval, RAG, and serialized-candidate optimization accept Eval's optional `claim` and `finalEvidence` options.
|
|
63
|
+
Use `claim.independentUnit` to group questions from the same source.
|
|
64
|
+
A `new-units` claim requires separate source units for development and final evaluation.
|
|
65
|
+
Results retain scenario scores, source-unit scores, and both observation counts.
|
|
66
|
+
Claim metadata declares the intended scope; it does not authenticate labels or establish certification.
|
|
67
|
+
|
|
68
|
+
For fresh final evidence, pass a shared durable ledger from `openFinalEvidenceLedger()` in `@tangle-network/agent-eval/experiment`.
|
|
69
|
+
The policy also requires a request ID and the actual evaluator's content digest.
|
|
70
|
+
Eval reserves final units before search and records exposure before measurement.
|
|
71
|
+
Interrupted measurements consume that evidence, and another request cannot restore its freshness.
|
|
72
|
+
See [Eval's integrity guide](https://github.com/tangle-network/agent-eval/blob/main/docs/evaluation-integrity.md) for the full controls and limits.
|
|
73
|
+
|
|
74
|
+
Retrieval and answer generation remain callbacks.
|
|
75
|
+
This lets the same evaluation code work with local search, vector databases, hybrid search, rerankers, and hosted RAG services.
|
|
76
|
+
Adaptive diagnosis, acquisition, and update callbacks finish before retrieval or RAG final scoring starts.
|
|
77
|
+
Only answer evaluation, the terminal promotion decision, and the returned result can observe selected configurations.
|
|
78
|
+
Answer-quality evidence must name at least two final scenario IDs, immutable dataset and evaluator references, non-empty finite metrics, and observed cost accounting.
|
|
79
|
+
Promotion also requires `answerQualityCostCeiling`.
|
|
80
|
+
|
|
81
|
+
For evaluator admission, use `auditEvaluator()` from `@tangle-network/agent-eval/meta-eval` with actual judgments of independently verified controls.
|
|
82
|
+
The application must enforce evaluator and auditor separation and retain evidence for the labels.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-knowledge",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.0",
|
|
4
4
|
"description": "Build, search, evaluate, and improve source-backed knowledge bases.",
|
|
5
5
|
"homepage": "https://github.com/tangle-network/agent-knowledge#readme",
|
|
6
6
|
"repository": {
|
|
@@ -38,6 +38,11 @@
|
|
|
38
38
|
"types": "./dist/benchmarks/index.d.ts",
|
|
39
39
|
"import": "./dist/benchmarks/index.js",
|
|
40
40
|
"default": "./dist/benchmarks/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./search": {
|
|
43
|
+
"types": "./dist/search/index.d.ts",
|
|
44
|
+
"import": "./dist/search/index.js",
|
|
45
|
+
"default": "./dist/search/index.js"
|
|
41
46
|
}
|
|
42
47
|
},
|
|
43
48
|
"bin": {
|
|
@@ -67,11 +72,12 @@
|
|
|
67
72
|
"format": "biome format --write src tests",
|
|
68
73
|
"check:skills": "node scripts/check-skills.mjs",
|
|
69
74
|
"check:path-containment": "node scripts/check-path-containment.mjs",
|
|
70
|
-
"verify:package": "pnpm run check:version-bump && pnpm run check:skills && pnpm run check:path-containment && pnpm run check:api-surface && publint && attw --pack --profile esm-only . && node scripts/verify-package.mjs",
|
|
75
|
+
"verify:package": "pnpm run check:version-bump && pnpm run check:skills && pnpm run check:path-containment && pnpm run check:api-surface && publint && attw --pack --profile esm-only . && node scripts/verify-package.mjs && pnpm run verify:search",
|
|
71
76
|
"verify:official-optimizers": "node scripts/verify-official-optimizers.mjs",
|
|
72
77
|
"check:version-bump": "node scripts/check-version-bump.mjs",
|
|
73
78
|
"check:api-surface": "node scripts/check-api-surface.mjs",
|
|
74
|
-
"api:surface": "node scripts/check-api-surface.mjs --write"
|
|
79
|
+
"api:surface": "node scripts/check-api-surface.mjs --write",
|
|
80
|
+
"verify:search": "node scripts/verify-search-entry.mjs"
|
|
75
81
|
},
|
|
76
82
|
"dependencies": {
|
|
77
83
|
"@types/proper-lockfile": "4.1.4",
|
|
@@ -79,15 +85,15 @@
|
|
|
79
85
|
"zod": "4.6.5"
|
|
80
86
|
},
|
|
81
87
|
"peerDependencies": {
|
|
82
|
-
"@tangle-network/agent-eval": ">=0.
|
|
83
|
-
"@tangle-network/agent-interface": "^
|
|
88
|
+
"@tangle-network/agent-eval": ">=0.213.0 <0.214.0",
|
|
89
|
+
"@tangle-network/agent-interface": "^5.0.0"
|
|
84
90
|
},
|
|
85
91
|
"devDependencies": {
|
|
86
92
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
87
93
|
"@biomejs/biome": "^2.5.14",
|
|
88
94
|
"@neo4j-labs/agent-memory": "0.5.0",
|
|
89
|
-
"@tangle-network/agent-eval": "0.
|
|
90
|
-
"@tangle-network/agent-interface": "
|
|
95
|
+
"@tangle-network/agent-eval": "0.213.0",
|
|
96
|
+
"@tangle-network/agent-interface": "5.0.0",
|
|
91
97
|
"@types/node": "^26.6.2",
|
|
92
98
|
"mem0ai": "3.3.0",
|
|
93
99
|
"oxc-parser": "0.151.0",
|