AnswerReader
KIT · interface · Type contract
App-owned reader that gathers evidence for one task.
Import
ts
import type { AnswerReader } from '@jangts/agent-core/kits/answering';js
/** @typedef {import('@jangts/agent-core/kits/answering').AnswerReader} AnswerReader */Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits/answering, @jangts/agent-core/kits.
Definition
ts
interface AnswerReader<Input, Evidence, App, Data>Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Input | — | — |
Evidence | — | — |
App | — | — |
Data | — | unknown |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. See the type definition and usage context. |
read | (input: Input, context: OperationContext<App> & { readonly task: Readonly<AnswerTaskDefinition<Input, Data>>; }) => MaybePromise<Evidence> | Required | Produces evidence for the validated input; the task is passed through for context. |
Member index
| Member | Purpose |
|---|---|
read | Produces evidence for the validated input; the task is passed through for context. |
Member details
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.
| Parameter | Type | Passing | Description |
|---|---|---|---|
input | Input | Required | — |
context | OperationContext<App> & { readonly task: Readonly<AnswerTaskDefinition<Input, Data>>; } | Required | — |
Fields of context
| Field | Type | Required | Description |
|---|---|---|---|
app | unknown extends App ? App : Readonly<App> | Required | Read-only. See the type definition and usage context. |
logger | SubFlowLog | undefined | Optional | Read-only. Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | Required | Read-only. Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Diagnostic scope of the enclosing call, when recording is enabled. |
task | Readonly<AnswerTaskDefinition<Input, Data>> | Required | Read-only. See the type definition and usage context. |
Returns: MaybePromise<Evidence>.
Awaited value: Awaited<Evidence>.
Examples
- Answering catalog: tasks, source reads, and check references: One task definition ties together the input Schema, reader, output, and check, with real references verified at assembly.
- Answering Flow: item-by-item generation, review, and local repair: Preserve coverage relationships over a split question batch and repair failing items without regenerating the ones that passed.
Register one read task for explanatory material
Beginner · 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 }));Add check references to the same task and check the generated result
Configuration · 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));Related policy source
- Task references and synchronous/asynchronous reads
- Check result aggregation
- Generation, checks, review, local repair, and delivery
- Question coverage checks