Skip to content
中文

AgentCoreEngineSetup ​

CORE · type · Type contract

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 ​

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

Other public entry points:@jangts/agent-core, @jangts/agent-core/engine, @jangts/agent-core/types.

Definition ​

Type: AgentCoreEngineSetup<State, Result, App>

Type expression
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 }))
  );

Type parameters ​

Type parameterConstraintDefault type
State——
Result——
App—undefined

Union branch structure ​

Optional shapes of AgentCoreEngineSetup: choose one shape; required fields for each branch are listed separately.

Branch 1
FieldTypeRequiredDescription
cacheEngineCacheOptions | undefinedOptionalEngine-local LRU bounds; not copied as cache data when forking.
agentCacheAgentCachePort | undefinedOptionalBorrowed App service cache; forks must explicitly provide their own port.
maxRoundsnumber | undefinedOptionalRound budget; must be a positive safe integer. Defaults to 8 rounds.
executionExecutionOptions | undefinedOptionalCancellation and diagnostics shared by every round.
errors{ exhausted?: () => Error; } | undefinedOptionalBuilds the error thrown when the round budget is exhausted (defaults to a BudgetError).
branchAgentBranch | undefinedOptionalRead-only. See the type definition and usage context.
toolsToolBinding | undefinedOptionalRead-only. See the type definition and usage context.
modelAgentModelBinding | undefinedOptionalSee the type definition and usage context.
modelsundefinedOptionalSee the type definition and usage context.
workflowundefinedOptionalSee the type definition and usage context.
appundefinedOptionalSee the type definition and usage context.
Branch 2
FieldTypeRequiredDescription
cacheEngineCacheOptions | undefinedOptionalEngine-local LRU bounds; not copied as cache data when forking.
agentCacheAgentCachePort | undefinedOptionalBorrowed App service cache; forks must explicitly provide their own port.
maxRoundsnumber | undefinedOptionalRound budget; must be a positive safe integer. Defaults to 8 rounds.
executionExecutionOptions | undefinedOptionalCancellation and diagnostics shared by every round.
errors{ exhausted?: () => Error; } | undefinedOptionalBuilds the error thrown when the round budget is exhausted (defaults to a BudgetError).
branchAgentBranch | undefinedOptionalRead-only. See the type definition and usage context.
toolsToolBinding | undefinedOptionalRead-only. See the type definition and usage context.
modelAgentModelBinding | undefinedOptionalSee the type definition and usage context.
modelsundefinedOptionalSee the type definition and usage context.
workflowAgentWorkflow<State, Result, App>RequiredRead-only. See the type definition and usage context.
appApp | undefinedOptionalRead-only. See the type definition and usage context.

Type condition: 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; })

Branch 3
FieldTypeRequiredDescription
cacheEngineCacheOptions | undefinedOptionalEngine-local LRU bounds; not copied as cache data when forking.
agentCacheAgentCachePort | undefinedOptionalBorrowed App service cache; forks must explicitly provide their own port.
maxRoundsnumber | undefinedOptionalRound budget; must be a positive safe integer. Defaults to 8 rounds.
executionExecutionOptions | undefinedOptionalCancellation and diagnostics shared by every round.
errors{ exhausted?: () => Error; } | undefinedOptionalBuilds the error thrown when the round budget is exhausted (defaults to a BudgetError).
branchAgentBranch | undefinedOptionalRead-only. See the type definition and usage context.
toolsToolBinding | undefinedOptionalRead-only. See the type definition and usage context.
modelstring | undefinedOptionalSee the type definition and usage context.
modelsReadonly<Record<string, AgentModelBinding>>RequiredSee the type definition and usage context.
maxModelCallsnumber | undefinedOptionalSee the type definition and usage context.
workflowundefinedOptionalSee the type definition and usage context.
appundefinedOptionalSee the type definition and usage context.
Branch 4
FieldTypeRequiredDescription
cacheEngineCacheOptions | undefinedOptionalEngine-local LRU bounds; not copied as cache data when forking.
agentCacheAgentCachePort | undefinedOptionalBorrowed App service cache; forks must explicitly provide their own port.
maxRoundsnumber | undefinedOptionalRound budget; must be a positive safe integer. Defaults to 8 rounds.
executionExecutionOptions | undefinedOptionalCancellation and diagnostics shared by every round.
errors{ exhausted?: () => Error; } | undefinedOptionalBuilds the error thrown when the round budget is exhausted (defaults to a BudgetError).
branchAgentBranch | undefinedOptionalRead-only. See the type definition and usage context.
toolsToolBinding | undefinedOptionalRead-only. See the type definition and usage context.
modelstring | undefinedOptionalSee the type definition and usage context.
modelsReadonly<Record<string, AgentModelBinding>>RequiredSee the type definition and usage context.
maxModelCallsnumber | undefinedOptionalSee the type definition and usage context.
workflowAgentWorkflow<State, Result, App>RequiredRead-only. See the type definition and usage context.
appApp | undefinedOptionalRead-only. See the type definition and usage context.

Type condition: 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; })

Examples ​

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

API reference, usage examples and developer guides.