Skip to content
English

AgentModelRuntime ​

CORE · type · 类型合同

The subset of a runner an engine may drive; kept small so the App can supply it.

导入 ​

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

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

定义 ​

类型: AgentModelRuntime

类型表达式
ts
type AgentModelRuntime = Pick<
  ModelRunner,
  'invoke' | 'prepare' | 'execution' | 'remainingCalls' | 'callCount' | 'totalCallCount'
>;

字段结构 ​

字段类型必需说明
invoke{ (request: string): Promise<ModelResult<string>>; <Result>(request: ModelCallRequest<never> & { readonly prepared: PreparedModelCall<Result>; }): Promise<ModelResult<Result>>; (request: ModelCallRequest<never>): Promise<ModelResult<string>>; <Result>(request: ModelCallRequest<ModelTransportDefinition<Result>> & { transport: ModelTransportDefinition<Result>; }): Promise<ModelResult<Result>>; <const Id extends string>(request: ModelCallRequest<Id> & { readonly transport: Id; }): Promise<ModelResult<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>>; (request: ModelCallRequest<string | ModelTransportDefinition<unknown>>): Promise<ModelResult<unknown>>; }必需Invoke one model call. Named and shorthand input share the same lifecycle: validation, measurement, budget charge, streaming, commit. A caller-supplied signal only shortens the call lifetime. Invoke a prepared call whose settings cannot be replaced. Invoke with the default transport and a plain-text result. Invoke with a transport instance supplied at the call site. Invoke with a transport id registered on this runner. Invoke without narrowing the transport type.
prepare{ (request?: import("../structs/model/runtime.js").ModelPrepareRequest<never>): import("../structs/model/runtime.js").PreparedModelCall<string>; <Result>(request: ModelPrepareRequest<ModelTransportDefinition<Result>> & { readonly transport: ModelTransportDefinition<Result>; }): PreparedModelCall<Result>; <const Id extends string>(request: ModelPrepareRequest<Id> & { readonly transport: Id; }): PreparedModelCall<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>; (request: import("../structs/model/runtime.js").ModelPrepareRequest<string | ModelTransportDefinition>): import("../structs/model/runtime.js").PreparedModelCall; }必需Prepare a call and measure it before invocation. A prepared call is single-use and bound to the stage, output tokens and transport it was measured with; invoke rejects any attempt to replace those settings. Prepare a call for a transport instance supplied at the call site. Prepare a call for a transport id, typed by the runner's registered transports. Prepare a call without narrowing the transport type.
executionExecutionContext必需只读。见类型定义及调用场景。
remainingCallsnumber必需只读。Calls still available to this runner after the parent's reserve is applied.
callCountnumber必需只读。Completed calls observed by this runner only.
totalCallCountnumber必需只读。Includes descendant attempts; local callCount and journal remain isolated.

成员目录 ​

成员用途
invokeInvoke one model call. Named and shorthand input share the same lifecycle: validation, measurement, budget charge, streaming, commit. A caller-supplied signal only shortens the call lifetime. Invoke a prepared call whose settings cannot be replaced. Invoke with the default transport and a plain-text result. Invoke with a transport instance supplied at the call site. Invoke with a transport id registered on this runner. Invoke without narrowing the transport type.
preparePrepare a call and measure it before invocation. A prepared call is single-use and bound to the stage, output tokens and transport it was measured with; invoke rejects any attempt to replace those settings. Prepare a call for a transport instance supplied at the call site. Prepare a call for a transport id, typed by the runner's registered transports. Prepare a call without narrowing the transport type.

成员详情 ​

invoke ​

Invoke one model call.

Named and shorthand input share the same lifecycle: validation, measurement, budget charge, streaming, commit. A caller-supplied signal only shortens the call lifetime. Invoke a prepared call whose settings cannot be replaced. Invoke with the default transport and a plain-text result. Invoke with a transport instance supplied at the call site. Invoke with a transport id registered on this runner. Invoke without narrowing the transport type.

ts
AgentModelRuntime.invoke(request: string): Promise<ModelResult<string>>

Invoke one model call.

Named and shorthand input share the same lifecycle: validation, measurement, budget charge, streaming, commit. A caller-supplied signal only shortens the call lifetime.

参数类型传递说明
requeststring必需—

返回: Promise<ModelResult<string>>。

等待后的值: ModelResult<string>。

返回值结构
字段类型必需说明
valuestring必需只读。见类型定义及调用场景。
invocationReadonly<ModelCallRecord>必需只读。见类型定义及调用场景。
ts
AgentModelRuntime.invoke<Result>(request: ModelCallRequest<never> & { readonly prepared: PreparedModelCall<Result>; }): Promise<ModelResult<Result>>

Invoke a prepared call whose settings cannot be replaced.

类型参数约束默认类型
Result——
参数类型传递说明
requestModelCallRequest<never> & { readonly prepared: PreparedModelCall<Result>; }必需—

参数 request的可选结构: 选择其中一种结构,各分支的字段要求分别列出。

分支 1
字段类型必需说明
loggerSubFlowLogger | undefined可省略只读。Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefined可省略只读。Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefined可省略只读。Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> & PreparedModelCall<Result>必需只读。Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportundefined可省略只读。见类型定义及调用场景。
inputstring必需见类型定义及调用场景。
instructionsstring | undefined可省略见类型定义及调用场景。
分支 2
字段类型必需说明
loggerSubFlowLogger | undefined可省略只读。Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefined可省略只读。Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefined可省略只读。Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> & PreparedModelCall<Result>必需只读。Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportundefined可省略只读。见类型定义及调用场景。
inputreadonly ModelMessage[] | BuiltContext | ContextPlan必需见类型定义及调用场景。
instructionsundefined可省略见类型定义及调用场景。

返回: Promise<ModelResult<Result>>。

等待后的值: ModelResult<Result>。

返回值结构
字段类型必需说明
valueResult必需只读。见类型定义及调用场景。
invocationReadonly<ModelCallRecord>必需只读。见类型定义及调用场景。
ts
AgentModelRuntime.invoke(request: ModelCallRequest<never>): Promise<ModelResult<string>>

Invoke with the default transport and a plain-text result.

参数类型传递说明
requestModelCallRequest<never>必需—

参数 request的可选结构: 选择其中一种结构,各分支的字段要求分别列出。

分支 1
字段类型必需说明
loggerSubFlowLogger | undefined可省略只读。Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefined可省略只读。Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefined可省略只读。Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefined可省略只读。Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportundefined可省略只读。见类型定义及调用场景。
inputstring必需见类型定义及调用场景。
instructionsstring | undefined可省略见类型定义及调用场景。
分支 2
字段类型必需说明
loggerSubFlowLogger | undefined可省略只读。Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefined可省略只读。Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefined可省略只读。Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefined可省略只读。Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportundefined可省略只读。见类型定义及调用场景。
inputreadonly ModelMessage[] | BuiltContext | ContextPlan必需见类型定义及调用场景。
instructionsundefined可省略见类型定义及调用场景。

返回: Promise<ModelResult<string>>。

等待后的值: ModelResult<string>。

返回值结构
字段类型必需说明
valuestring必需只读。见类型定义及调用场景。
invocationReadonly<ModelCallRecord>必需只读。见类型定义及调用场景。
ts
AgentModelRuntime.invoke<Result>(request: ModelCallRequest<ModelTransportDefinition<Result>> & { transport: ModelTransportDefinition<Result>; }): Promise<ModelResult<Result>>

Invoke with a transport instance supplied at the call site.

类型参数约束默认类型
Result——
参数类型传递说明
requestModelCallRequest<ModelTransportDefinition<Result>> & { transport: ModelTransportDefinition<Result>; }必需—

参数 request的可选结构: 选择其中一种结构,各分支的字段要求分别列出。

分支 1
字段类型必需说明
loggerSubFlowLogger | undefined可省略只读。Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefined可省略只读。Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefined可省略只读。Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefined可省略只读。Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportModelTransportDefinition<Result>必需只读。见类型定义及调用场景。
inputstring必需见类型定义及调用场景。
instructionsstring | undefined可省略见类型定义及调用场景。
分支 2
字段类型必需说明
loggerSubFlowLogger | undefined可省略只读。Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefined可省略只读。Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefined可省略只读。Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefined可省略只读。Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportModelTransportDefinition<Result>必需只读。见类型定义及调用场景。
inputreadonly ModelMessage[] | BuiltContext | ContextPlan必需见类型定义及调用场景。
instructionsundefined可省略见类型定义及调用场景。

返回: Promise<ModelResult<Result>>。

等待后的值: ModelResult<Result>。

返回值结构
字段类型必需说明
valueResult必需只读。见类型定义及调用场景。
invocationReadonly<ModelCallRecord>必需只读。见类型定义及调用场景。
ts
AgentModelRuntime.invoke<const Id extends string>(request: ModelCallRequest<Id> & { readonly transport: Id; }): Promise<ModelResult<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>>

Invoke with a transport id registered on this runner.

类型参数约束默认类型
Idstring—
参数类型传递说明
requestModelCallRequest<Id> & { readonly transport: Id; }必需—

参数 request的可选结构: 选择其中一种结构,各分支的字段要求分别列出。

分支 1
字段类型必需说明
loggerSubFlowLogger | undefined可省略只读。Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefined可省略只读。Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefined可省略只读。Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefined可省略只读。Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportId必需只读。见类型定义及调用场景。
inputstring必需见类型定义及调用场景。
instructionsstring | undefined可省略见类型定义及调用场景。
分支 2
字段类型必需说明
loggerSubFlowLogger | undefined可省略只读。Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefined可省略只读。Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefined可省略只读。Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefined可省略只读。Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportId必需只读。见类型定义及调用场景。
inputreadonly ModelMessage[] | BuiltContext | ContextPlan必需见类型定义及调用场景。
instructionsundefined可省略见类型定义及调用场景。

返回: Promise<ModelResult<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>>。

等待后的值: ModelResult<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>。

返回值结构
字段类型必需说明
valueRegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>必需只读。见类型定义及调用场景。
invocationReadonly<ModelCallRecord>必需只读。见类型定义及调用场景。
ts
AgentModelRuntime.invoke(request: ModelCallRequest<string | ModelTransportDefinition<unknown>>): Promise<ModelResult<unknown>>

Invoke without narrowing the transport type.

参数类型传递说明
requestModelCallRequest<string | ModelTransportDefinition<unknown>>必需—

参数 request的可选结构: 选择其中一种结构,各分支的字段要求分别列出。

分支 1
字段类型必需说明
loggerSubFlowLogger | undefined可省略只读。Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefined可省略只读。Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefined可省略只读。Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefined可省略只读。Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportstring | ModelTransportDefinition<unknown> | undefined可省略只读。见类型定义及调用场景。
inputstring必需见类型定义及调用场景。
instructionsstring | undefined可省略见类型定义及调用场景。
分支 2
字段类型必需说明
loggerSubFlowLogger | undefined可省略只读。Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefined可省略只读。Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefined可省略只读。Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefined可省略只读。Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportstring | ModelTransportDefinition<unknown> | undefined可省略只读。见类型定义及调用场景。
inputreadonly ModelMessage[] | BuiltContext | ContextPlan必需见类型定义及调用场景。
instructionsundefined可省略见类型定义及调用场景。

返回: Promise<ModelResult<unknown>>。

等待后的值: ModelResult<unknown>。

返回值结构
字段类型必需说明
valueunknown必需只读。见类型定义及调用场景。
invocationReadonly<ModelCallRecord>必需只读。见类型定义及调用场景。

prepare ​

Prepare a call and measure it before invocation.

A prepared call is single-use and bound to the stage, output tokens and transport it was measured with; invoke rejects any attempt to replace those settings. Prepare a call for a transport instance supplied at the call site. Prepare a call for a transport id, typed by the runner's registered transports. Prepare a call without narrowing the transport type.

ts
AgentModelRuntime.prepare(request?: import("../structs/model/runtime.js").ModelPrepareRequest<never>): import("../structs/model/runtime.js").PreparedModelCall<string>

Prepare a call and measure it before invocation.

A prepared call is single-use and bound to the stage, output tokens and transport it was measured with; invoke rejects any attempt to replace those settings.

参数类型传递说明
requestModelPrepareRequest<never> | undefined可省略—

参数 request的可选结构: 选择其中一种结构,各分支的字段要求分别列出。

分支 1

undefined

分支 2
字段类型必需说明
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportundefined可省略只读。见类型定义及调用场景。
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。

返回: PreparedModelCall<string>。

返回值结构
字段类型必需说明
modelIdstring | undefined可省略只读。Model binding the call was prepared with.
stageIdstring必需只读。见类型定义及调用场景。
transportIdstring必需只读。见类型定义及调用场景。
maxOutputTokensnumber必需只读。见类型定义及调用场景。
remainingCallsnumber必需只读。Calls still available; a live value, so later spends are visible.
measure(input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurement必需Preflight measurement of one input shape. Never marks the call used and never charges the budget.
optionsPick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature">必需只读。见类型定义及调用场景。
schemaCharsnumber必需只读。见类型定义及调用场景。
instructionstring | undefined可省略只读。见类型定义及调用场景。
createResponse() => ModelResponseCollector<string>必需见类型定义及调用场景。
ts
AgentModelRuntime.prepare<Result>(request: ModelPrepareRequest<ModelTransportDefinition<Result>> & { readonly transport: ModelTransportDefinition<Result>; }): PreparedModelCall<Result>

Prepare a call for a transport instance supplied at the call site.

类型参数约束默认类型
Result——
参数类型传递说明
requestModelPrepareRequest<ModelTransportDefinition<Result>> & { readonly transport: ModelTransportDefinition<Result>; }必需—
request 的字段
字段类型必需说明
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportModelTransportDefinition<Result>必需只读。见类型定义及调用场景。
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。

返回: PreparedModelCall<Result>。

返回值结构
字段类型必需说明
modelIdstring | undefined可省略只读。Model binding the call was prepared with.
stageIdstring必需只读。见类型定义及调用场景。
transportIdstring必需只读。见类型定义及调用场景。
maxOutputTokensnumber必需只读。见类型定义及调用场景。
remainingCallsnumber必需只读。Calls still available; a live value, so later spends are visible.
measure(input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurement必需Preflight measurement of one input shape. Never marks the call used and never charges the budget.
optionsPick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature">必需只读。见类型定义及调用场景。
schemaCharsnumber必需只读。见类型定义及调用场景。
instructionstring | undefined可省略只读。见类型定义及调用场景。
createResponse() => ModelResponseCollector<Result>必需见类型定义及调用场景。
ts
AgentModelRuntime.prepare<const Id extends string>(request: ModelPrepareRequest<Id> & { readonly transport: Id; }): PreparedModelCall<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>

Prepare a call for a transport id, typed by the runner's registered transports.

类型参数约束默认类型
Idstring—
参数类型传递说明
requestModelPrepareRequest<Id> & { readonly transport: Id; }必需—
request 的字段
字段类型必需说明
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportId必需只读。见类型定义及调用场景。
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。

返回: PreparedModelCall<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>。

返回值结构
字段类型必需说明
modelIdstring | undefined可省略只读。Model binding the call was prepared with.
stageIdstring必需只读。见类型定义及调用场景。
transportIdstring必需只读。见类型定义及调用场景。
maxOutputTokensnumber必需只读。见类型定义及调用场景。
remainingCallsnumber必需只读。Calls still available; a live value, so later spends are visible.
measure(input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurement必需Preflight measurement of one input shape. Never marks the call used and never charges the budget.
optionsPick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature">必需只读。见类型定义及调用场景。
schemaCharsnumber必需只读。见类型定义及调用场景。
instructionstring | undefined可省略只读。见类型定义及调用场景。
createResponse() => ModelResponseCollector<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>必需见类型定义及调用场景。
ts
AgentModelRuntime.prepare(request: import("../structs/model/runtime.js").ModelPrepareRequest<string | ModelTransportDefinition>): import("../structs/model/runtime.js").PreparedModelCall

Prepare a call without narrowing the transport type.

参数类型传递说明
requestModelPrepareRequest<string | ModelTransportDefinition<unknown>>必需—
request 的字段
字段类型必需说明
stageIdstring | undefined可省略只读。见类型定义及调用场景。
transportstring | ModelTransportDefinition<unknown> | undefined可省略只读。见类型定义及调用场景。
maxOutputTokensnumber | undefined可省略只读。见类型定义及调用场景。

返回: PreparedModelCall<unknown>。

返回值结构
字段类型必需说明
modelIdstring | undefined可省略只读。Model binding the call was prepared with.
stageIdstring必需只读。见类型定义及调用场景。
transportIdstring必需只读。见类型定义及调用场景。
maxOutputTokensnumber必需只读。见类型定义及调用场景。
remainingCallsnumber必需只读。Calls still available; a live value, so later spends are visible.
measure(input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurement必需Preflight measurement of one input shape. Never marks the call used and never charges the budget.
optionsPick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature">必需只读。见类型定义及调用场景。
schemaCharsnumber必需只读。见类型定义及调用场景。
instructionstring | undefined可省略只读。见类型定义及调用场景。
createResponse() => ModelResponseCollector<unknown>必需见类型定义及调用场景。

使用示例 ​

一个普通步骤即可运行 ​

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

相关策略源码 ​

相关定义 ​

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