Skip to content
English

Reflection ​

KIT · constant · 运行时值

导入 ​

ts
import { Reflection } from '@jangts/agent-core/kits/reflection';
js
import { Reflection } from '@jangts/agent-core/kits/reflection';

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

定义 ​

成员目录 ​

成员用途
defineReflection完整输入输出见下方重载。

成员详情 ​

defineReflection ​

ts
Reflection.defineReflection<App>(definition: ReflectionDefinition<App>): ReflectionTask<App>

Compile a reflection task.

Model-driven investigation through ordinary registered tools and the existing Core loop. The task always reports persisted: false: storing a report is the App's decision. Observed findings must cite evidence ids that were actually returned in this run, which is what keeps the report tied to real observations instead of model recall.

类型参数约束默认类型
App——
参数类型传递说明
definitionReflectionDefinition<App>必需—
definition 的字段
字段类型必需说明
modelPick<ModelRunner<string, readonly ModelTransportDefinition<unknown>[]>, "remainingCalls" | "createChild">必需只读。Parent runner; the reflection creates a child and preserves the parent's reserve.
sourceReflectionSource<App>必需只读。Evidence source queried through the reflection tools.
toolsreadonly ToolDefinition<any, any, App>[] | undefined可省略只读。Additional tools exposed to the reflection model.
maxCallsnumber | undefined可省略只读。Model calls the child may use; defaults to 4.
reserveCallsnumber | undefined可省略只读。Parent calls kept untouched; defaults to 1.
timeoutMsnumber | undefined可省略只读。Wall-clock limit for the whole reflection in milliseconds; defaults to 30000.
maxPagesnumber | undefined可省略只读。Maximum evidence pages read; defaults to 4.
maxEventsnumber | undefined可省略只读。Maximum evidence items collected; defaults to 64.
maxEvidenceCharsnumber | undefined可省略只读。Maximum evidence characters placed in the model context; defaults to 12000.
authorize(question: string, context: OperationContext<App>) => MaybePromise<void>必需Guards one reflection request; runs before any model call.

返回: ReflectionTask<App>。

返回值结构
字段类型必需说明
run(question: string, context: OperationContext<App>) => Promise<ReflectionReport>必需Answers the question from evidence; never throws for incomplete evidence alone.

使用示例 ​

绑定复盘模型、证据源和授权 ​

入门 · 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 });
}

相关策略源码 ​

相关定义 ​

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