AnswerTaskDefinition
KIT · interface · Type contract
Static binding of one answerable task.
Import
ts
import type { AnswerTaskDefinition } from '@jangts/agent-core/kits/answering';js
/** @typedef {import('@jangts/agent-core/kits/answering').AnswerTaskDefinition} AnswerTaskDefinition */Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits/answering, @jangts/agent-core/kits.
Definition
ts
interface AnswerTaskDefinition<Input, Data>Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Input | — | unknown |
Data | — | unknown |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. Unique task id. |
description | string | Required | Read-only. See the type definition and usage context. |
readerId | string | Required | Read-only. Reader that produces the evidence for this task; must be registered. |
outputId | string | Required | Read-only. Output contract the answer must satisfy; must be registered. |
goalIds | readonly string[] | Required | Read-only. Goals this task serves; non-empty. |
scopeId | string | undefined | Optional | Read-only. Optional scope narrowing the task. |
checkIds | readonly string[] | Required | Read-only. Checks applied to the produced value; every id must be registered. |
inputSchema | SchemaAdapter<Input> | Required | Read-only. Schema for the task input, validated before the reader runs. |
metadata | Data | Required | Read-only. App metadata passed back through the reader context; opaque to the Kit. |
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