ReflectionTask
KIT · interface · 类型合同
Compiled reflection task.
导入
ts
import type { ReflectionTask } from '@jangts/agent-core/kits/reflection';js
/** @typedef {import('@jangts/agent-core/kits/reflection').ReflectionTask} ReflectionTask */其他公开入口:@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/kits、@jangts/agent-core/kits/reflection。
定义
ts
interface ReflectionTask<App>泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
App | — | — |
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
run | (question: string, context: OperationContext<App>) => Promise<ReflectionReport> | 必需 | Answers the question from evidence; never throws for incomplete evidence alone. |
成员目录
| 成员 | 用途 |
|---|---|
run | Answers the question from evidence; never throws for incomplete evidence alone. |
成员详情
run
Answers the question from evidence; never throws for incomplete evidence alone.
ts
ReflectionTask.run(question: string, context: OperationContext<App>): Promise<ReflectionReport>Answers the question from evidence; never throws for incomplete evidence alone.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
question | string | 必需 | — |
context | OperationContext<App> | 必需 | — |
context 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
app | unknown extends App ? App : Readonly<App> | 必需 | 只读。见类型定义及调用场景。 |
logger | SubFlowLog | undefined | 可省略 | 只读。Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | 必需 | 只读。Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Diagnostic scope of the enclosing call, when recording is enabled. |
返回: Promise<ReflectionReport>。
等待后的值: ReflectionReport。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | string | 必需 | 只读。见类型定义及调用场景。 |
status | "completed" | "incomplete" | 必需 | 只读。incomplete when evidence, model budget or the timeout stopped the work early. |
question | string | 必需 | 只读。Question as submitted; at most 2000 characters. |
findings | readonly ReflectionFinding[] | 必需 | 只读。见类型定义及调用场景。 |
limitations | readonly string[] | 必需 | 只读。Known limitations, for example exhausted budgets or incomplete coverage. |
evidence | readonly ReflectionEvidence[] | 必需 | 只读。Evidence items the reflection actually saw. |
coverage | readonly { readonly consistency: "best-effort" | "snapshot"; readonly complete: boolean | null; readonly gaps: readonly string[]; }[] | 必需 | 只读。Coverage statement of each page that was read. |
createdAtMs | number | 必需 | 只读。见类型定义及调用场景。 |
expiresAtMs | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
persisted | false | 必需 | 只读。Marker: a report is returned to the caller and never stored by the Kit. |
使用示例
- 日志复盘:授权元数据与证据报告:App 提供获准证据源,复盘任务通过普通模型与工具合同生成有来源的报告。
绑定复盘模型、证据源和授权
入门 · Node.js
ts
import { defineReflection } from '@jangts/agent-core/kits/reflection';
import type { ReflectionSource } from '@jangts/agent-core/kits/reflection';
import type { ModelRunner, OperationContext } from '@jangts/agent-core';
export function review<App>(model: ModelRunner, source: ReflectionSource<App>,
authorize: (question: string, context: OperationContext<App>) => Promise<void>) {
return defineReflection({ model, source, authorize,
maxCalls: 4, reserveCalls: 1, maxPages: 4, maxEvents: 64, maxEvidenceChars: 12000 });
}js
import { defineReflection } from '@jangts/agent-core/kits/reflection';
export function review(model, source, authorize) {
return defineReflection({ model, source, authorize,
maxCalls: 4, reserveCalls: 1, maxPages: 4, maxEvents: 64, maxEvidenceChars: 12000 });
}从日志 reader 构造同一种证据源
配置 · Node.js
reader 的目录范围、关闭与保留期由 App 管理。适配后的 source 可传入同一个 defineReflection。
ts
import { defineReflectionLogSource } from '@jangts/agent-core/kits/reflection';
import type { ReflectionLogReader } from '@jangts/agent-core/kits/reflection';
import type { OperationContext } from '@jangts/agent-core';
export function logSource<App>(reader: ReflectionLogReader, traceId: string,
authorize: (context: OperationContext<App>) => Promise<void>) {
return defineReflectionLogSource({ reader, traceId, id: 'authorized-history', authorize });
}js
import { defineReflectionLogSource } from '@jangts/agent-core/kits/reflection';
export function logSource(reader, traceId, authorize) {
return defineReflectionLogSource({ reader, traceId, id: 'authorized-history', authorize });
}