KnowledgeSnapshot
KIT · interface · Type contract
Materialized read result.
Import
ts
import type { KnowledgeSnapshot } from '@jangts/agent-core/kits/knowledge';js
/** @typedef {import('@jangts/agent-core/kits/knowledge').KnowledgeSnapshot} KnowledgeSnapshot */Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits/knowledge, @jangts/agent-core/kits.
Definition
ts
interface KnowledgeSnapshotExtends or implements: KnowledgeRead.
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. Deterministic identity derived from document, revision and selection. |
revision | string | Required | Read-only. Revision of the document that produced this content. |
locale | string | undefined | Optional | Read-only. See the type definition and usage context. |
content | string | Required | Read-only. Rendered text, trimmed; sections are separated by blank lines. |
documentId | string | Required | Read-only. See the type definition and usage context. |
selection | SectionSelection | Required | Read-only. Must reference existing sections; an invalid selection throws. |
Examples
- Knowledge: documents, sections, and evidence snapshots: One document contract supports plain objects and anchored text; a selection yields an evidence snapshot with an explicit version.
First read one plain-object document
Beginner · Node.js
ts
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const catalog = Knowledge.defineKnowledgeCatalog([
{ id: 'manual', revision: '1', parts: ['Agent Core 支持普通 Workflow 节点。'] },
]);
const snapshot = catalog.read({ documentId: 'manual', selection: { mode: 'document' } });
console.log(snapshot.content, snapshot.revision);js
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const catalog = Knowledge.defineKnowledgeCatalog([
{ id: 'manual', revision: '1', parts: ['Agent Core 支持普通 Workflow 节点。'] },
]);
const snapshot = catalog.read({ documentId: 'manual', selection: { mode: 'document' } });
console.log(snapshot.content, snapshot.revision);Add sections and a budget to the same read
Configuration · Node.js
ts
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const catalog = Knowledge.defineKnowledgeCatalog([
{ id: 'manual', revision: '2', parts: [
{ id: 'start', parts: ['先运行一个节点。', { id: 'advanced', parts: ['再增加模型和工具。'] }] },
] },
], { maxChars: 2000 });
console.log(catalog.sectionIds('manual'));
const snapshot = catalog.read({ documentId: 'manual', selection: { mode: 'subtree', sectionIds: ['start'] } });
console.log(snapshot.content, snapshot.id);js
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const catalog = Knowledge.defineKnowledgeCatalog([
{ id: 'manual', revision: '2', parts: [
{ id: 'start', parts: ['先运行一个节点。', { id: 'advanced', parts: ['再增加模型和工具。'] }] },
] },
], { maxChars: 2000 });
console.log(catalog.sectionIds('manual'));
const snapshot = catalog.read({ documentId: 'manual', selection: { mode: 'subtree', sectionIds: ['start'] } });
console.log(snapshot.content, snapshot.id);