EvidenceProjectionDefinition
KIT · interface · 类型合同
Projection configuration, keyed by the tool that produced an observation.
导入
ts
import type { EvidenceProjectionDefinition } from '@jangts/agent-core/kits/evidence';js
/** @typedef {import('@jangts/agent-core/kits/evidence').EvidenceProjectionDefinition} EvidenceProjectionDefinition */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/kits/evidence、@jangts/agent-core/kits。
定义
ts
interface EvidenceProjectionDefinition<Observation, Source>泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Observation | — | — |
Source | — | — |
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
providers | Readonly<Record<string, EvidenceProjectionProvider<Observation, Source>>> | 必需 | 只读。One provider per tool id; observations without a provider pass through unchanged. |
sourceId | (source: Source) => string | 必需 | 只读。Stable citation id for a source. |
toolId | ((observation: Observation) => string) | undefined | 可省略 | 只读。Selects the tool id of an observation; defaults to its toolId (or legacy tool) field. |
成员目录
| 成员 | 用途 |
|---|---|
sourceId | Stable citation id for a source. |
成员详情
sourceId
Stable citation id for a source.
ts
EvidenceProjectionDefinition.sourceId(source: Source): string| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
source | Source | 必需 | — |
返回: string。
使用示例
- Evidence:用真实观察检查完成性:用 App 定义的证据语义检查需求,避免把模型的“完成了”当成真实回执。
检查真实资料是否已读取
入门 · Node.js
ts
import { Evidence } from '@jangts/agent-core/kits/evidence';
type Observation = { sourceId: string; read: boolean };
type Requirement = { id: string; kind: 'source-read'; sourceId: string };
const checklist = Evidence.defineEvidenceChecklist<Observation, Requirement>([
{ kind: 'source-read', description: '资料读取已成功', isSatisfied: (seen, need) => seen.read && seen.sourceId === need.sourceId },
]);
console.log(checklist.isComplete({ observations: [{ sourceId: 'manual', read: true }], requirements: [{ id: 'need-manual', kind: 'source-read', sourceId: 'manual' }] }));js
import { Evidence } from '@jangts/agent-core/kits/evidence';
const checklist = Evidence.defineEvidenceChecklist([
{ kind: 'source-read', description: '资料读取已成功', isSatisfied: (seen, need) => seen.read && seen.sourceId === need.sourceId },
]);
console.log(checklist.isComplete({ observations: [{ sourceId: 'manual', read: true }], requirements: [{ id: 'need-manual', kind: 'source-read', sourceId: 'manual' }] }));相同清单返回缺口,再限定审查所用来源
配置 · Node.js
ts
import { Evidence } from '@jangts/agent-core/kits/evidence';
type Observation = { sourceId: string; read: boolean };
type Requirement = { id: string; kind: 'source-read'; sourceId: string };
const checklist = Evidence.defineEvidenceChecklist<Observation, Requirement>([
{ kind: 'source-read', description: '资料读取已成功', isSatisfied: (seen, need) => seen.read && seen.sourceId === need.sourceId },
]);
console.log(checklist.missing({ observations: [], requirements: [{ id: 'need-manual', kind: 'source-read', sourceId: 'manual' }] }));
type ToolObservation = { toolId: string; sources: { id: string; text: string }[] };
const projection = Evidence.defineEvidenceProjection<ToolObservation, { id: string; text: string }>({
sourceId: source => source.id,
providers: { search: { sources: row => row.sources, withSources: (row, sources) => ({ ...row, sources }) } },
});
console.log(projection.project({ observations: [{ toolId: 'search', sources: [{ id: 'manual', text: '使用指南' }, { id: 'faq', text: '常见问题' }] }], sourceIds: ['manual'] }));js
import { Evidence } from '@jangts/agent-core/kits/evidence';
const checklist = Evidence.defineEvidenceChecklist([
{ kind: 'source-read', description: '资料读取已成功', isSatisfied: (seen, need) => seen.read && seen.sourceId === need.sourceId },
]);
console.log(checklist.missing({ observations: [], requirements: [{ id: 'need-manual', kind: 'source-read', sourceId: 'manual' }] }));
const projection = Evidence.defineEvidenceProjection({
sourceId: source => source.id,
providers: { search: { sources: row => row.sources, withSources: (row, sources) => ({ ...row, sources }) } },
});
console.log(projection.project({ observations: [{ toolId: 'search', sources: [{ id: 'manual', text: '使用指南' }, { id: 'faq', text: '常见问题' }] }], sourceIds: ['manual'] }));