Skip to content
English

CoreStep ​

CORE · type · 类型合同

One loop iteration. Must be re-entrant: the same step object runs every round.

导入 ​

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

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

定义 ​

ts
type CoreStep<Result> = (
  roundIndex: number,
  context: ExecutionContext & import('../debug.js').NodeReportingContext & CacheContext,
) => MaybePromise<StepOutcome<Result>>;

泛型参数 ​

类型参数约束默认类型
Result——

调用 ​

ts
CoreStep(roundIndex: number, context: ExecutionContext & import("../debug.js").NodeReportingContext & CacheContext): MaybePromise<StepOutcome<Result>>
参数类型传递说明
roundIndexnumber必需—
contextExecutionContext & NodeReportingContext & CacheContext必需—
context 的字段
字段类型必需说明
loggerSubFlowLog | undefined可省略只读。Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignal必需只读。Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefined可省略只读。Diagnostic scope of the enclosing call, when recording is enabled.
report(update: import("./execution/workflow.js").WorkflowNodeReport) => void必需Reports progress for the active node; Core supplies the execution identity.
createSubFlowLogger() => SubFlowLogger必需Bound to this context and owned by runtime; repeated calls in one visit return the same instance.
cacheNodeCache必需只读。见类型定义及调用场景。
agentCacheNodeAgentCache | undefined可省略只读。见类型定义及调用场景。

返回: MaybePromise<StepOutcome<Result>>。

等待后的值: StepOutcome<Result>。

返回值的可选结构: 选择其中一种结构,各分支的字段要求分别列出。

分支 1
字段类型必需说明
type"continue"必需只读。见类型定义及调用场景。
分支 2
字段类型必需说明
type"complete"必需只读。见类型定义及调用场景。
valueResult必需只读。见类型定义及调用场景。

使用示例 ​

一个普通步骤即可运行 ​

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

增加显式 Workflow,仍然调用 run ​

配置 · 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: '访客' }));

相关策略源码 ​

相关定义 ​

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