Skip to content
中文

ReflectionDefinition ​

KIT · interface · Type contract

Configuration for compiling a reflection task.

Import ​

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

Other public entry points:@jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/kits, @jangts/agent-core/kits/reflection.

Definition ​

ts
interface ReflectionDefinition<App>

Type parameters ​

Type parameterConstraintDefault type
App——

Field structure ​

FieldTypeRequiredDescription
modelPick<ModelRunner<string, readonly ModelTransportDefinition<unknown>[]>, "remainingCalls" | "createChild">RequiredRead-only. Parent runner; the reflection creates a child and preserves the parent's reserve.
sourceReflectionSource<App>RequiredRead-only. Evidence source queried through the reflection tools.
toolsreadonly ToolDefinition<any, any, App>[] | undefinedOptionalRead-only. Additional tools exposed to the reflection model.
maxCallsnumber | undefinedOptionalRead-only. Model calls the child may use; defaults to 4.
reserveCallsnumber | undefinedOptionalRead-only. Parent calls kept untouched; defaults to 1.
timeoutMsnumber | undefinedOptionalRead-only. Wall-clock limit for the whole reflection in milliseconds; defaults to 30000.
maxPagesnumber | undefinedOptionalRead-only. Maximum evidence pages read; defaults to 4.
maxEventsnumber | undefinedOptionalRead-only. Maximum evidence items collected; defaults to 64.
maxEvidenceCharsnumber | undefinedOptionalRead-only. Maximum evidence characters placed in the model context; defaults to 12000.
authorize(question: string, context: OperationContext<App>) => MaybePromise<void>RequiredGuards one reflection request; runs before any model call.

Member index ​

MemberPurpose
authorizeGuards one reflection request; runs before any model call.

Member details ​

authorize ​

Guards one reflection request; runs before any model call.

ts
ReflectionDefinition.authorize(question: string, context: OperationContext<App>): MaybePromise<void>

Guards one reflection request; runs before any model call.

ParameterTypePassingDescription
questionstringRequired—
contextOperationContext<App>Required—
Fields of context
FieldTypeRequiredDescription
appunknown extends App ? App : Readonly<App>RequiredRead-only. See the type definition and usage context.
loggerSubFlowLog | undefinedOptionalRead-only. Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the enclosing call, when recording is enabled.

Returns: MaybePromise<void>.

Awaited value: void.

Examples ​

Bind the reflection model, evidence source, and authorization ​

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

Build the same kind of evidence source from a log reader ​

Configuration · Node.js

The reader's directory scope, shutdown, and retention are managed by the App. The adapted source can be passed into the same 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 });
}

API reference, usage examples and developer guides.