@tangle-network/agent-knowledge 1.12.1 → 2.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/README.md CHANGED
@@ -35,7 +35,7 @@ Two ways in, depending on what you're doing:
35
35
  - *"Spawn live agents to improve a KB"* → pass an `updateKnowledge` callback to `improveKnowledgeBase`; runtime-backed supervisors live in `@tangle-network/agent-runtime`.
36
36
  - *"Tune retrieval for a knowledge base"* → `runRetrievalImprovementLoop` in the [Agent-Eval integration](#agent-eval-integration) section.
37
37
  - *"Run an operator-grade KB improvement cycle"* → `improveKnowledgeBase` in the [Agent-Eval integration](#agent-eval-integration) section.
38
- It creates a candidate KB, lets agents or deterministic hooks improve it, runs configured evals, can be resumed, and promotes only when the live KB has not changed underneath it.
38
+ It creates a candidate KB, lets agents or deterministic hooks improve it, runs configured evals, and returns exact candidate identity for later approval.
39
39
  - *"Expose the lower-level RAG lifecycle phases"* → `runRagKnowledgeImprovementLoop` in the [Agent-Eval integration](#agent-eval-integration) section.
40
40
  It exposes retrieval tuning, gap diagnosis, knowledge acquisition/update, answer-quality checks, and promotion as one typed lifecycle.
41
41
  - *"Evaluate RAG answers or a wiki/KB"* → `ragAnswerQualityJudge`, `createRagAnswerQualityHook`, and `scoreKnowledgeBaseIndex` in the [Agent-Eval integration](#agent-eval-integration) section.
@@ -53,8 +53,8 @@ Storage stays consumer-owned via `KbStore` (`MemoryKbStore`, `FileSystemKbStore`
53
53
  | RAG | Retrieval eval, source-span labels, answer quality checks, missing/stale/noisy-source diagnosis | `runRagKnowledgeImprovementLoop` |
54
54
  | Memory DB | Adapter contract that turns memory hits into source-like evidence and benchmark rows | `/memory` plus `runMemoryAdapterBenchmark` |
55
55
  | From scratch | Empty KB layout, source ingestion, write-block application, indexing, readiness checks | CLI `init` or `runKnowledgeResearchLoop` |
56
- | Existing KB | Candidate workspace, resume state, base-hash conflict check, promotion only after evals pass | `improveKnowledgeBase` |
57
- | Parallel agents | Per-run locks, isolated candidates, `promote: false` handoff, retry with the same `runId` | `improveKnowledgeBase` with runtime workers |
56
+ | Existing KB | Candidate workspace, resume state, base-hash conflict check, exact approved promotion | `improveKnowledgeBase` |
57
+ | Parallel agents | Per-run locks, isolated candidates, frozen candidate handoff, retry with the same `runId` | `improveKnowledgeBase` with runtime workers |
58
58
  | One-call agent job | Runtime supervisor plus all KB mechanics above | `runKnowledgeImprovementJob` from `@tangle-network/agent-runtime/knowledge` |
59
59
 
60
60
  ## CLI
@@ -119,7 +119,7 @@ from `@tangle-network/agent-knowledge`.
119
119
  without this package hardcoding an agent runner.
120
120
  - `improveKnowledgeBase()` wraps that lifecycle with durable candidate state,
121
121
  a per-run lock, resume support, isolated candidate workspaces, KB quality
122
- scoring, and conflict-safe promotion.
122
+ scoring, and an exact candidate reference for explicit promotion.
123
123
  Use it when running agents in loops against a real KB rather than only
124
124
  exposing phase hooks.
125
125
  - `evaluateKnowledgeBaseReadiness()` checks one KB root without running an
@@ -223,13 +223,14 @@ const result = await runKnowledgeBenchmarkSuite({
223
223
  respond: async ({ case: testCase }) => {
224
224
  if (testCase.taskKind !== 'retrieval') return { hits: [] }
225
225
  const hits = await retrieveFromYourKb(testCase.query)
226
- return { hits, costUsd: 0.001 }
226
+ return { hits }
227
227
  },
228
228
  })
229
229
 
230
230
  console.log(result.report.score.mean)
231
231
  ```
232
232
 
233
+ Billable responders must execute paid work through `context.cost.runPaidCall()`; `costUsd` on an artifact is display-only.
233
234
  Use `buildRetrievalBenchmarkCasesFromQrels()` for qrels-backed retrieval datasets.
234
235
  The smoke pack proves that every declared benchmark family is wired through the runner; full BEIR, MTEB, MS MARCO, TREC DL, MIRACL, LoTTE, BRIGHT, CRAG, HotpotQA, KILT, RAGTruth, and FaithBench runs should pass real dataset rows through the same case shapes.
235
236
  Use `KnowledgeAnswerBenchmarkCase` for CRAG/HotpotQA/KILT-style answer checks and RAGTruth/FaithBench-style hallucination checks by encoding required claims, forbidden claims, and expected source IDs.
@@ -272,6 +273,7 @@ const kbQuality = scoreKnowledgeBaseIndex(index, {
272
273
  Use `runRagKnowledgeImprovementLoop` when the product question is broader than retrieval:
273
274
  can the system find the gaps, gather or update knowledge, prove generated answers still behave, and decide whether to promote?
274
275
  `agent-knowledge` owns the knowledge/eval contract; the caller supplies the research, coding, connector, and answer-eval hooks.
276
+ This lower-level loop returns a promotion recommendation; it never writes to the live knowledge base.
275
277
 
276
278
  ```ts
277
279
  import { runRagKnowledgeImprovementLoop } from '@tangle-network/agent-knowledge'
@@ -299,12 +301,17 @@ console.log(result.promotion)
299
301
  ```
300
302
 
301
303
  Use `improveKnowledgeBase` when a program should own the candidate workspace and promotion mechanics.
302
- The wrapper composes the same RAG lifecycle, but adds resumable state under `.agent-knowledge/improvements/<runId>/`, a lock lease for parallel operators, and a base-hash check before copying the candidate over the live KB.
304
+ The wrapper composes the same RAG lifecycle, but adds resumable state under `.agent-knowledge/improvements/<runId>/`, a lock lease for parallel operators, and exact candidate bytes that can be approved later.
303
305
 
304
306
  ```ts
305
- import { improveKnowledgeBase } from '@tangle-network/agent-knowledge'
307
+ import {
308
+ improveKnowledgeBase,
309
+ knowledgeImprovementCandidateRef,
310
+ promoteKnowledgeCandidate,
311
+ withKnowledgeImprovementCandidate,
312
+ } from '@tangle-network/agent-knowledge'
306
313
 
307
- const result = await improveKnowledgeBase({
314
+ const staged = await improveKnowledgeBase({
308
315
  root: './kb',
309
316
  goal: 'Improve support refund-policy knowledge',
310
317
  readinessSpecs,
@@ -320,11 +327,24 @@ const result = await improveKnowledgeBase({
320
327
  requiredPhases: ['knowledge-update', 'retrieval-tuning', 'answer-quality'],
321
328
  })
322
329
 
323
- console.log(result.promoted, result.candidate?.evaluation)
330
+ const candidate = knowledgeImprovementCandidateRef(staged)
331
+ console.log(staged.evaluation, candidate)
332
+
333
+ await withKnowledgeImprovementCandidate({ root: './kb', candidate }, async (snapshot) => {
334
+ await inspectCandidateFiles(snapshot.root, snapshot.evaluation)
335
+ })
336
+
337
+ // Call this only after your product records approval for this exact candidate.
338
+ const promoted = await promoteKnowledgeCandidate({ root: './kb', candidate })
339
+ console.log(promoted.promoted)
324
340
  ```
325
341
 
326
- Pass `promote: false` to leave the candidate workspace open for another agent or a human edit.
327
- Calling `improveKnowledgeBase` again with the same `runId` re-evaluates that candidate and promotes it only if the original live KB hash still matches.
342
+ `improveKnowledgeBase` stages a measured candidate by default and does not change the live knowledge base.
343
+ Calling it again with the same `runId` resumes interrupted work.
344
+ `withKnowledgeImprovementCandidate` materializes the measured bytes in an isolated temporary directory for the callback, checks them again afterward, and removes the directory.
345
+ `promoteKnowledgeCandidate` applies only the frozen bytes identified by the approved candidate reference, and refuses if the live base changed.
346
+ The current release intentionally accepts only its strict run-state format; incomplete runs created by 1.x must be completed or restarted before upgrading.
347
+ The exact candidate workflow requires Linux; other knowledge, retrieval, and evaluation APIs remain cross-platform.
328
348
 
329
349
  If a required phase is missing its hook, the loop throws.
330
350
  That keeps the public API from reporting a fake “RAG improved” result when the caller only wired retrieval or only wired a researcher.
@@ -558,7 +578,7 @@ await runTwoAgentResearchLoop({
558
578
  `agent-knowledge` owns knowledge state and measurement.
559
579
  It deliberately does not own an agent runner.
560
580
  Live agent orchestration belongs in `@tangle-network/agent-runtime`.
561
- Use the one-call runtime job when you want agents, candidate workspaces, readiness checks, promotion, and spend measurement wired together:
581
+ Use the one-call runtime job when you want agents, candidate workspaces, readiness checks, exact candidate handoff, and spend measurement wired together:
562
582
 
563
583
  ```ts
564
584
  import { runKnowledgeImprovementJob } from '@tangle-network/agent-runtime/knowledge'
@@ -1,5 +1,5 @@
1
1
  import '@tangle-network/agent-eval/campaign';
2
2
  import '../types-CjqPcTTK.js';
3
- export { B as BuildRetrievalBenchmarkCasesFromQrelsOptions, I as INDUSTRY_MEMORY_BENCHMARKS, e as INDUSTRY_RAG_BENCHMARKS, K as KnowledgeAnswerBenchmarkCase, f as KnowledgeAnswerBenchmarkTaskKind, g as KnowledgeBenchmarkArtifact, h as KnowledgeBenchmarkCase, i as KnowledgeBenchmarkCaseBase, j as KnowledgeBenchmarkDistribution, k as KnowledgeBenchmarkEvaluation, l as KnowledgeBenchmarkFamily, m as KnowledgeBenchmarkReport, n as KnowledgeBenchmarkResponder, o as KnowledgeBenchmarkScenario, p as KnowledgeBenchmarkSliceSummary, q as KnowledgeBenchmarkSource, r as KnowledgeBenchmarkSpec, s as KnowledgeBenchmarkSplit, t as KnowledgeBenchmarkTaskKind, u as KnowledgeClaimMatcher, v as KnowledgeMemoryBenchmarkCase, w as KnowledgeMemoryBenchmarkTaskKind, x as KnowledgeMemoryEvent, y as KnowledgeMemoryFactMatcher, z as KnowledgeRetrievalBenchmarkCase, A as KnowledgeRetrievalBenchmarkQrel, C as KnowledgeRetrievalBenchmarkQuery, M as MemoryAdapterBenchmarkCandidate, D as MemoryAdapterBenchmarkRankingRow, V as RunKnowledgeBenchmarkSuiteOptions, W as RunKnowledgeBenchmarkSuiteResult, X as RunMemoryAdapterBenchmarkOptions, Y as RunMemoryAdapterBenchmarkResult, Z as buildFirstPartyMemoryLifecycleBenchmarkCases, _ as buildIndustryMemoryBenchmarkSmokeCases, $ as buildIndustryRagBenchmarkSmokeCases, a0 as buildKnowledgeBenchmarkScenarios, a1 as buildRetrievalBenchmarkCasesFromQrels, a4 as createInMemoryBenchmarkAdapter, a5 as createMemoryAdapterBenchmarkResponder, a6 as createNoopMemoryBenchmarkAdapter, a7 as isKnowledgeMemoryBenchmarkCase, a8 as knowledgeBenchmarkJudge, a9 as parseKnowledgeBenchmarkJsonl, aa as parseKnowledgeBenchmarkQrels, ab as renderKnowledgeBenchmarkReportMarkdown, ac as respondToIndustryMemoryBenchmarkSmokeCase, ad as respondToIndustryRagBenchmarkSmokeCase, ai as runKnowledgeBenchmarkSuite, aj as runMemoryAdapterBenchmark, al as scoreKnowledgeBenchmarkArtifact, am as scoreMemoryBenchmarkArtifact, ao as summarizeKnowledgeBenchmarkCampaign } from '../index-Cj5jRXOz.js';
3
+ export { B as BuildRetrievalBenchmarkCasesFromQrelsOptions, I as INDUSTRY_MEMORY_BENCHMARKS, d as INDUSTRY_RAG_BENCHMARKS, K as KnowledgeAnswerBenchmarkCase, e as KnowledgeAnswerBenchmarkTaskKind, f as KnowledgeBenchmarkArtifact, g as KnowledgeBenchmarkCase, h as KnowledgeBenchmarkCaseBase, i as KnowledgeBenchmarkDistribution, j as KnowledgeBenchmarkEvaluation, k as KnowledgeBenchmarkFamily, l as KnowledgeBenchmarkReport, m as KnowledgeBenchmarkResponder, n as KnowledgeBenchmarkScenario, o as KnowledgeBenchmarkSliceSummary, p as KnowledgeBenchmarkSource, q as KnowledgeBenchmarkSpec, r as KnowledgeBenchmarkSplit, s as KnowledgeBenchmarkTaskKind, t as KnowledgeClaimMatcher, u as KnowledgeMemoryBenchmarkCase, v as KnowledgeMemoryBenchmarkTaskKind, w as KnowledgeMemoryEvent, x as KnowledgeMemoryFactMatcher, y as KnowledgeRetrievalBenchmarkCase, z as KnowledgeRetrievalBenchmarkQrel, A as KnowledgeRetrievalBenchmarkQuery, M as MemoryAdapterBenchmarkCandidate, C as MemoryAdapterBenchmarkRankingRow, V as RunKnowledgeBenchmarkSuiteOptions, W as RunKnowledgeBenchmarkSuiteResult, X as RunMemoryAdapterBenchmarkOptions, Y as RunMemoryAdapterBenchmarkResult, Z as buildFirstPartyMemoryLifecycleBenchmarkCases, _ as buildIndustryMemoryBenchmarkSmokeCases, $ as buildIndustryRagBenchmarkSmokeCases, a0 as buildKnowledgeBenchmarkScenarios, a1 as buildRetrievalBenchmarkCasesFromQrels, a4 as createInMemoryBenchmarkAdapter, a5 as createMemoryAdapterBenchmarkResponder, a6 as createNoopMemoryBenchmarkAdapter, a7 as isKnowledgeMemoryBenchmarkCase, a8 as knowledgeBenchmarkJudge, a9 as parseKnowledgeBenchmarkJsonl, aa as parseKnowledgeBenchmarkQrels, ab as renderKnowledgeBenchmarkReportMarkdown, ac as respondToIndustryMemoryBenchmarkSmokeCase, ad as respondToIndustryRagBenchmarkSmokeCase, ai as runKnowledgeBenchmarkSuite, aj as runMemoryAdapterBenchmark, al as scoreKnowledgeBenchmarkArtifact, am as scoreMemoryBenchmarkArtifact, ao as summarizeKnowledgeBenchmarkCampaign } from '../index-BLxw1I_F.js';
4
4
  import '../types-C17sAROL.js';
5
5
  import '@tangle-network/agent-eval/rl';
@@ -21,7 +21,7 @@ import {
21
21
  scoreKnowledgeBenchmarkArtifact,
22
22
  scoreMemoryBenchmarkArtifact,
23
23
  summarizeKnowledgeBenchmarkCampaign
24
- } from "../chunk-ULXZI235.js";
24
+ } from "../chunk-RIHIYCX2.js";
25
25
  import "../chunk-DQ3PDMDP.js";
26
26
  import "../chunk-XVU5FFQA.js";
27
27
  import "../chunk-YMKHCTS2.js";