AgentCoreEngineSetup
CORE · type · 类型合同
Engine construction options.
Combines round budget and error factories with exactly one model shape (a single bound model or a named catalog), an optional tool runtime, an optional branch identity, and an optional workflow together with its App dependencies.
导入
import type { AgentCoreEngineSetup } from '@jangts/agent-core/engine';/** @typedef {import('@jangts/agent-core/engine').AgentCoreEngineSetup} AgentCoreEngineSetup */其他公开入口:@jangts/agent-core、@jangts/agent-core/engine、@jangts/agent-core/types。
定义
类型: AgentCoreEngineSetup<State, Result, App>
类型表达式
type AgentCoreEngineSetup<State, Result, App = undefined> = AgentCoreEngineOptions & {
readonly branch?: AgentBranch;
readonly tools?: ToolBinding;
} & (
| {
model?: AgentModelBinding;
models?: never;
}
| {
model?: string;
models: Readonly<Record<string, AgentModelBinding>>;
maxModelCalls?: number;
}
) &
(
| { workflow?: undefined; app?: never }
| ({ readonly workflow: AgentWorkflow<State, Result, App> } & ([App] extends [undefined]
? { readonly app?: undefined }
: { readonly app: App }))
);泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
State | — | — |
Result | — | — |
App | — | undefined |
联合分支结构
AgentCoreEngineSetup的可选结构: 选择其中一种结构,各分支的字段要求分别列出。
分支 1
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
cache | EngineCacheOptions | undefined | 可省略 | Engine-local LRU bounds; not copied as cache data when forking. |
agentCache | AgentCachePort | undefined | 可省略 | Borrowed App service cache; forks must explicitly provide their own port. |
maxRounds | number | undefined | 可省略 | Round budget; must be a positive safe integer. Defaults to 8 rounds. |
execution | ExecutionOptions | undefined | 可省略 | Cancellation and diagnostics shared by every round. |
errors | { exhausted?: () => Error; } | undefined | 可省略 | Builds the error thrown when the round budget is exhausted (defaults to a BudgetError). |
branch | AgentBranch | undefined | 可省略 | 只读。见类型定义及调用场景。 |
tools | ToolBinding | undefined | 可省略 | 只读。见类型定义及调用场景。 |
model | AgentModelBinding | undefined | 可省略 | 见类型定义及调用场景。 |
models | undefined | 可省略 | 见类型定义及调用场景。 |
workflow | undefined | 可省略 | 见类型定义及调用场景。 |
app | undefined | 可省略 | 见类型定义及调用场景。 |
分支 2
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
cache | EngineCacheOptions | undefined | 可省略 | Engine-local LRU bounds; not copied as cache data when forking. |
agentCache | AgentCachePort | undefined | 可省略 | Borrowed App service cache; forks must explicitly provide their own port. |
maxRounds | number | undefined | 可省略 | Round budget; must be a positive safe integer. Defaults to 8 rounds. |
execution | ExecutionOptions | undefined | 可省略 | Cancellation and diagnostics shared by every round. |
errors | { exhausted?: () => Error; } | undefined | 可省略 | Builds the error thrown when the round budget is exhausted (defaults to a BudgetError). |
branch | AgentBranch | undefined | 可省略 | 只读。见类型定义及调用场景。 |
tools | ToolBinding | undefined | 可省略 | 只读。见类型定义及调用场景。 |
model | AgentModelBinding | undefined | 可省略 | 见类型定义及调用场景。 |
models | undefined | 可省略 | 见类型定义及调用场景。 |
workflow | AgentWorkflow<State, Result, App> | 必需 | 只读。见类型定义及调用场景。 |
app | App | undefined | 可省略 | 只读。见类型定义及调用场景。 |
类型条件: AgentCoreEngineOptions & { readonly branch?: AgentBranch; readonly tools?: ToolBinding; } & { model?: AgentModelBinding; models?: never; } & { readonly workflow: AgentWorkflow<State, Result, App>; } & ([App] extends [undefined] ? { readonly app?: undefined; } : { readonly app: App; })
分支 3
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
cache | EngineCacheOptions | undefined | 可省略 | Engine-local LRU bounds; not copied as cache data when forking. |
agentCache | AgentCachePort | undefined | 可省略 | Borrowed App service cache; forks must explicitly provide their own port. |
maxRounds | number | undefined | 可省略 | Round budget; must be a positive safe integer. Defaults to 8 rounds. |
execution | ExecutionOptions | undefined | 可省略 | Cancellation and diagnostics shared by every round. |
errors | { exhausted?: () => Error; } | undefined | 可省略 | Builds the error thrown when the round budget is exhausted (defaults to a BudgetError). |
branch | AgentBranch | undefined | 可省略 | 只读。见类型定义及调用场景。 |
tools | ToolBinding | undefined | 可省略 | 只读。见类型定义及调用场景。 |
model | string | undefined | 可省略 | 见类型定义及调用场景。 |
models | Readonly<Record<string, AgentModelBinding>> | 必需 | 见类型定义及调用场景。 |
maxModelCalls | number | undefined | 可省略 | 见类型定义及调用场景。 |
workflow | undefined | 可省略 | 见类型定义及调用场景。 |
app | undefined | 可省略 | 见类型定义及调用场景。 |
分支 4
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
cache | EngineCacheOptions | undefined | 可省略 | Engine-local LRU bounds; not copied as cache data when forking. |
agentCache | AgentCachePort | undefined | 可省略 | Borrowed App service cache; forks must explicitly provide their own port. |
maxRounds | number | undefined | 可省略 | Round budget; must be a positive safe integer. Defaults to 8 rounds. |
execution | ExecutionOptions | undefined | 可省略 | Cancellation and diagnostics shared by every round. |
errors | { exhausted?: () => Error; } | undefined | 可省略 | Builds the error thrown when the round budget is exhausted (defaults to a BudgetError). |
branch | AgentBranch | undefined | 可省略 | 只读。见类型定义及调用场景。 |
tools | ToolBinding | undefined | 可省略 | 只读。见类型定义及调用场景。 |
model | string | undefined | 可省略 | 见类型定义及调用场景。 |
models | Readonly<Record<string, AgentModelBinding>> | 必需 | 见类型定义及调用场景。 |
maxModelCalls | number | undefined | 可省略 | 见类型定义及调用场景。 |
workflow | AgentWorkflow<State, Result, App> | 必需 | 只读。见类型定义及调用场景。 |
app | App | undefined | 可省略 | 只读。见类型定义及调用场景。 |
类型条件: AgentCoreEngineOptions & { readonly branch?: AgentBranch; readonly tools?: ToolBinding; } & { model?: string; models: Readonly<Record<string, AgentModelBinding>>; maxModelCalls?: number; } & { readonly workflow: AgentWorkflow<State, Result, App>; } & ([App] extends [undefined] ? { readonly app?: undefined; } : { readonly app: App; })
使用示例
- Agent:先运行,再逐步绑定 Tool 与依赖:Engine 执行有界循环;绑定 Workflow 后,每次只传状态中变化的数据。
一个普通步骤即可运行
入门 · Node.js
import { AgentCoreEngine } from '@jangts/agent-core/engine';
const agent = new AgentCoreEngine<string>();
const answer = await agent.run(() => ({ type: 'complete', value: '你好,Core' }));
console.log(answer);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
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: '访客' }));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: '访客' }));