Skip to content
English

AnswerReader ​

KIT · interface · 类型合同

App-owned reader that gathers evidence for one task.

导入 ​

ts
import type { AnswerReader } from '@jangts/agent-core/kits/answering';
js
/** @typedef {import('@jangts/agent-core/kits/answering').AnswerReader} AnswerReader */

其他公开入口:@jangts/agent-core/types、@jangts/agent-core/kits/answering、@jangts/agent-core/kits。

定义 ​

ts
interface AnswerReader<Input, Evidence, App, Data>

泛型参数 ​

类型参数约束默认类型
Input——
Evidence——
App——
Data—unknown

字段结构 ​

字段类型必需说明
idstring必需只读。见类型定义及调用场景。
read(input: Input, context: OperationContext<App> & { readonly task: Readonly<AnswerTaskDefinition<Input, Data>>; }) => MaybePromise<Evidence>必需Produces evidence for the validated input; the task is passed through for context.

成员目录 ​

成员用途
readProduces evidence for the validated input; the task is passed through for context.

成员详情 ​

read ​

Produces evidence for the validated input; the task is passed through for context.

ts
AnswerReader.read(input: Input, context: OperationContext<App> & { readonly task: Readonly<AnswerTaskDefinition<Input, Data>>; }): MaybePromise<Evidence>

Produces evidence for the validated input; the task is passed through for context.

参数类型传递说明
inputInput必需—
contextOperationContext<App> & { readonly task: Readonly<AnswerTaskDefinition<Input, Data>>; }必需—
context 的字段
字段类型必需说明
appunknown extends App ? App : Readonly<App>必需只读。见类型定义及调用场景。
loggerSubFlowLog | undefined可省略只读。Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignal必需只读。Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefined可省略只读。Diagnostic scope of the enclosing call, when recording is enabled.
taskReadonly<AnswerTaskDefinition<Input, Data>>必需只读。见类型定义及调用场景。

返回: MaybePromise<Evidence>。

等待后的值: Awaited<Evidence>。

使用示例 ​

为说明资料登记一个读取任务 ​

入门 · Node.js

ts
import { Answering } from '@jangts/agent-core/kits/answering';
import { Presentation } from '@jangts/agent-core/kits/presentation';
const readers = Answering.defineAnswerReaderCatalog([{ id: 'manual', read: (input: string) => ({ question: input, source: 'Agent Core 允许普通对象节点。' }) }]);
const checks = Answering.defineAnswerCheckCatalog<string, {}>([]);
const outputs = Presentation.defineOutputCatalog([{ id: 'reply', kind: 'text', fields: [{ id: 'text', owner: 'generated' }] }]);
const tasks = Answering.defineAnswerTaskCatalog([
  { id: 'explain', description: '根据说明资料解释接口', readerId: 'manual', outputId: 'reply', goalIds: ['explain'], checkIds: [], metadata: {},
    inputSchema: { jsonSchema: { type: 'string' }, parse(value: unknown) { if (typeof value !== 'string') throw new Error('需要问题'); return value; } } },
], { readers, checks, outputs });
console.log(tasks.read({ taskId: 'explain', input: '如何定义节点?' }, { app: {}, signal: new AbortController().signal }));
js
import { Answering } from '@jangts/agent-core/kits/answering';
import { Presentation } from '@jangts/agent-core/kits/presentation';
const readers = Answering.defineAnswerReaderCatalog([{ id: 'manual', read: (input) => ({ question: input, source: 'Agent Core 允许普通对象节点。' }) }]);
const checks = Answering.defineAnswerCheckCatalog([]);
const outputs = Presentation.defineOutputCatalog([{ id: 'reply', kind: 'text', fields: [{ id: 'text', owner: 'generated' }] }]);
const tasks = Answering.defineAnswerTaskCatalog([
    { id: 'explain', description: '根据说明资料解释接口', readerId: 'manual', outputId: 'reply', goalIds: ['explain'], checkIds: [], metadata: {},
        inputSchema: { jsonSchema: { type: 'string' }, parse(value) { if (typeof value !== 'string')
                throw new Error('需要问题'); return value; } } },
], { readers, checks, outputs });
console.log(tasks.read({ taskId: 'explain', input: '如何定义节点?' }, { app: {}, signal: new AbortController().signal }));

相同任务增加检查引用并检查生成结果 ​

配置 · Node.js

ts
import { Answering } from '@jangts/agent-core/kits/answering';
import { Presentation } from '@jangts/agent-core/kits/presentation';
const readers = Answering.defineAnswerReaderCatalog([{ id: 'manual', read: (input: string) => ({ question: input, source: 'Agent Core 允许普通对象节点。' }) }]);
const checks = Answering.defineAnswerCheckCatalog<string, {}>([
  { id: 'nonempty', check: value => ({ status: value.trim() ? 'passed' : 'failed', value: value.trim(), issues: value.trim() ? [] : [{ code: 'EMPTY', message: '答案为空' }] }) },
]);
const outputs = Presentation.defineOutputCatalog([{ id: 'reply', kind: 'text', fields: [{ id: 'text', owner: 'generated' }] }]);
const tasks = Answering.defineAnswerTaskCatalog([
  { id: 'explain', description: '根据说明资料解释接口', readerId: 'manual', outputId: 'reply', goalIds: ['explain'], checkIds: ['nonempty'], metadata: {},
    inputSchema: { jsonSchema: { type: 'string' }, parse(value: unknown) { if (typeof value !== 'string') throw new Error('需要问题'); return value; } } },
], { readers, checks, outputs });
const context = { app: {}, signal: new AbortController().signal };
const evidence = await tasks.readAsync({ taskId: 'explain', input: '如何定义节点?' }, context);
console.log(evidence, checks.check({ checkIds: tasks.require('explain').checkIds, value: ' 普通对象即可。 ' }, context));
js
import { Answering } from '@jangts/agent-core/kits/answering';
import { Presentation } from '@jangts/agent-core/kits/presentation';
const readers = Answering.defineAnswerReaderCatalog([{ id: 'manual', read: (input) => ({ question: input, source: 'Agent Core 允许普通对象节点。' }) }]);
const checks = Answering.defineAnswerCheckCatalog([
    { id: 'nonempty', check: value => ({ status: value.trim() ? 'passed' : 'failed', value: value.trim(), issues: value.trim() ? [] : [{ code: 'EMPTY', message: '答案为空' }] }) },
]);
const outputs = Presentation.defineOutputCatalog([{ id: 'reply', kind: 'text', fields: [{ id: 'text', owner: 'generated' }] }]);
const tasks = Answering.defineAnswerTaskCatalog([
    { id: 'explain', description: '根据说明资料解释接口', readerId: 'manual', outputId: 'reply', goalIds: ['explain'], checkIds: ['nonempty'], metadata: {},
        inputSchema: { jsonSchema: { type: 'string' }, parse(value) { if (typeof value !== 'string')
                throw new Error('需要问题'); return value; } } },
], { readers, checks, outputs });
const context = { app: {}, signal: new AbortController().signal };
const evidence = await tasks.readAsync({ taskId: 'explain', input: '如何定义节点?' }, context);
console.log(evidence, checks.check({ checkIds: tasks.require('explain').checkIds, value: ' 普通对象即可。 ' }, context));

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。