Skip to content
English

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.

导入 ​

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

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

定义 ​

类型: AgentCoreEngineSetup<State, Result, App>

类型表达式
ts
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
字段类型必需说明
cacheEngineCacheOptions | undefined可省略Engine-local LRU bounds; not copied as cache data when forking.
agentCacheAgentCachePort | undefined可省略Borrowed App service cache; forks must explicitly provide their own port.
maxRoundsnumber | undefined可省略Round budget; must be a positive safe integer. Defaults to 8 rounds.
executionExecutionOptions | 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).
branchAgentBranch | undefined可省略只读。见类型定义及调用场景。
toolsToolBinding | undefined可省略只读。见类型定义及调用场景。
modelAgentModelBinding | undefined可省略见类型定义及调用场景。
modelsundefined可省略见类型定义及调用场景。
workflowundefined可省略见类型定义及调用场景。
appundefined可省略见类型定义及调用场景。
分支 2
字段类型必需说明
cacheEngineCacheOptions | undefined可省略Engine-local LRU bounds; not copied as cache data when forking.
agentCacheAgentCachePort | undefined可省略Borrowed App service cache; forks must explicitly provide their own port.
maxRoundsnumber | undefined可省略Round budget; must be a positive safe integer. Defaults to 8 rounds.
executionExecutionOptions | 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).
branchAgentBranch | undefined可省略只读。见类型定义及调用场景。
toolsToolBinding | undefined可省略只读。见类型定义及调用场景。
modelAgentModelBinding | undefined可省略见类型定义及调用场景。
modelsundefined可省略见类型定义及调用场景。
workflowAgentWorkflow<State, Result, App>必需只读。见类型定义及调用场景。
appApp | 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
字段类型必需说明
cacheEngineCacheOptions | undefined可省略Engine-local LRU bounds; not copied as cache data when forking.
agentCacheAgentCachePort | undefined可省略Borrowed App service cache; forks must explicitly provide their own port.
maxRoundsnumber | undefined可省略Round budget; must be a positive safe integer. Defaults to 8 rounds.
executionExecutionOptions | 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).
branchAgentBranch | undefined可省略只读。见类型定义及调用场景。
toolsToolBinding | undefined可省略只读。见类型定义及调用场景。
modelstring | undefined可省略见类型定义及调用场景。
modelsReadonly<Record<string, AgentModelBinding>>必需见类型定义及调用场景。
maxModelCallsnumber | undefined可省略见类型定义及调用场景。
workflowundefined可省略见类型定义及调用场景。
appundefined可省略见类型定义及调用场景。
分支 4
字段类型必需说明
cacheEngineCacheOptions | undefined可省略Engine-local LRU bounds; not copied as cache data when forking.
agentCacheAgentCachePort | undefined可省略Borrowed App service cache; forks must explicitly provide their own port.
maxRoundsnumber | undefined可省略Round budget; must be a positive safe integer. Defaults to 8 rounds.
executionExecutionOptions | 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).
branchAgentBranch | undefined可省略只读。见类型定义及调用场景。
toolsToolBinding | undefined可省略只读。见类型定义及调用场景。
modelstring | undefined可省略见类型定义及调用场景。
modelsReadonly<Record<string, AgentModelBinding>>必需见类型定义及调用场景。
maxModelCallsnumber | undefined可省略见类型定义及调用场景。
workflowAgentWorkflow<State, Result, App>必需只读。见类型定义及调用场景。
appApp | 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; })

使用示例 ​

一个普通步骤即可运行 ​

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

相关策略源码 ​

相关定义 ​

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