AgentCoreEngineOptions
CORE · interface · 类型合同
Engine construction options.
导入
ts
import type { AgentCoreEngineOptions } from '@jangts/agent-core/engine';1
js
/** @typedef {import('@jangts/agent-core/engine').AgentCoreEngineOptions} AgentCoreEngineOptions */1
其他公开入口:@jangts/agent-core、@jangts/agent-core/engine、@jangts/agent-core/types、@jangts/agent-core/structs。
定义
ts
interface AgentCoreEngineOptions1
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
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). |
使用示例
- Agent:先运行,再逐步绑定 Tool 与依赖:Engine 执行有界循环;绑定 Workflow 后,每次只传状态中变化的数据。
一个普通步骤即可运行
入门 · 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);1
2
3
4
5
2
3
4
5
js
import { AgentCoreEngine } from '@jangts/agent-core/engine';
const agent = new AgentCoreEngine();
const answer = await agent.run(() => ({ type: 'complete', value: '你好,Core' }));
console.log(answer);1
2
3
4
2
3
4
增加显式 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: '访客' }));1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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: '访客' }));1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12