ReflectionTask
KIT · interface · Type contract
Compiled reflection task.
Import
ts
import type { ReflectionTask } from '@jangts/agent-core/kits/reflection';js
/** @typedef {import('@jangts/agent-core/kits/reflection').ReflectionTask} ReflectionTask */Other public entry points:@jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/kits, @jangts/agent-core/kits/reflection.
Definition
ts
interface ReflectionTask<App>Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
App | — | — |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
run | (question: string, context: OperationContext<App>) => Promise<ReflectionReport> | Required | Answers the question from evidence; never throws for incomplete evidence alone. |
Member index
| Member | Purpose |
|---|---|
run | Answers the question from evidence; never throws for incomplete evidence alone. |
Member details
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.
| Parameter | Type | Passing | Description |
|---|---|---|---|
question | string | Required | — |
context | OperationContext<App> | 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. |
Returns: Promise<ReflectionReport>.
Awaited value: ReflectionReport.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. See the type definition and usage context. |
status | "completed" | "incomplete" | Required | Read-only. incomplete when evidence, model budget or the timeout stopped the work early. |
question | string | Required | Read-only. Question as submitted; at most 2000 characters. |
findings | readonly ReflectionFinding[] | Required | Read-only. See the type definition and usage context. |
limitations | readonly string[] | Required | Read-only. Known limitations, for example exhausted budgets or incomplete coverage. |
evidence | readonly ReflectionEvidence[] | Required | Read-only. Evidence items the reflection actually saw. |
coverage | readonly { readonly consistency: "best-effort" | "snapshot"; readonly complete: boolean | null; readonly gaps: readonly string[]; }[] | Required | Read-only. Coverage statement of each page that was read. |
createdAtMs | number | Required | Read-only. See the type definition and usage context. |
expiresAtMs | number | undefined | Optional | Read-only. See the type definition and usage context. |
persisted | false | Required | Read-only. Marker: a report is returned to the caller and never stored by the Kit. |
Examples
- Log reflection: authorization metadata and evidence reports: The App supplies authorized evidence sources; the reflection task produces a sourced report through ordinary model and tool contracts.
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 });
}