CoreStep
CORE · type · Type contract
One loop iteration. Must be re-entrant: the same step object runs every round.
Import
ts
import type { CoreStep } from '@jangts/agent-core/engine';js
/** @typedef {import('@jangts/agent-core/engine').CoreStep} CoreStep */Other public entry points:@jangts/agent-core, @jangts/agent-core/engine, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
ts
type CoreStep<Result> = (
roundIndex: number,
context: ExecutionContext & import('../debug.js').NodeReportingContext & CacheContext,
) => MaybePromise<StepOutcome<Result>>;Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Result | — | — |
Call
ts
CoreStep(roundIndex: number, context: ExecutionContext & import("../debug.js").NodeReportingContext & CacheContext): MaybePromise<StepOutcome<Result>>| Parameter | Type | Passing | Description |
|---|---|---|---|
roundIndex | number | Required | — |
context | ExecutionContext & NodeReportingContext & CacheContext | Required | — |
Fields of context
| Field | Type | Required | Description |
|---|---|---|---|
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. |
report | (update: import("./execution/workflow.js").WorkflowNodeReport) => void | Required | Reports progress for the active node; Core supplies the execution identity. |
createSubFlowLogger | () => SubFlowLogger | Required | Bound to this context and owned by runtime; repeated calls in one visit return the same instance. |
cache | NodeCache | Required | Read-only. See the type definition and usage context. |
agentCache | NodeAgentCache | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: MaybePromise<StepOutcome<Result>>.
Awaited value: StepOutcome<Result>.
Optional shapes of Return value: choose one shape; required fields for each branch are listed separately.
Branch 1
| Field | Type | Required | Description |
|---|---|---|---|
type | "continue" | Required | Read-only. See the type definition and usage context. |
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
type | "complete" | Required | Read-only. See the type definition and usage context. |
value | Result | Required | Read-only. See the type definition and usage context. |
Examples
- Agent: run first, then bind tools and dependencies step by step: The Engine executes a bounded loop; after a Workflow is bound, each run only receives the data that changed in state.
A single ordinary step is enough to run
Beginner · Node.js
ts
import { AgentCoreEngine } from '@jangts/agent-core/engine';
const agent = new AgentCoreEngine<string>();
const answer = await agent.run(() => ({ type: 'complete', value: '你好,Core' }));
console.log(answer);js
import { AgentCoreEngine } from '@jangts/agent-core/engine';
const agent = new AgentCoreEngine();
const answer = await agent.run(() => ({ type: 'complete', value: '你好,Core' }));
console.log(answer);Add an explicit Workflow and still call run
Configuration · Node.js
ts
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { name: string; answer?: string };
const workflow = defineWorkflow<State, string>({
id: 'greeting',
nodes: [{
id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
run: state => ({ answer: '你好,' + state.name }),
routes: [route.deliver('answer')],
}],
});
const agent = new AgentCoreEngine({ workflow });
console.log(await agent.run({ name: 'Ivan' }));
console.log(await agent.run({ name: '访客' }));js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({
id: 'greeting',
nodes: [{
id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
run: state => ({ answer: '你好,' + state.name }),
routes: [route.deliver('answer')],
}],
});
const agent = new AgentCoreEngine({ workflow });
console.log(await agent.run({ name: 'Ivan' }));
console.log(await agent.run({ name: '访客' }));