Agent: run first, then bind tools and dependencies step by step
The Engine executes a bounded loop; after a Workflow is bound, each run only receives the data that changed in state.
Without a Workflow, run accepts a CoreStep, and the step returns an explicit continue or complete. After a Workflow is bound, run accepts that Workflow's State and returns the business Result; it is not a new result envelope. Model and tool calls separately return unified results carrying an invocation.
The Workflow can be omitted at construction and bound later with a single bindWorkflow; both assembly styles use the same run. One Engine binds exactly one Workflow, and there is no runtime Workflow switching. Stable dependencies belong to the instance, while the current input and cancellation signal belong to the request. By default there are at most 8 rounds; maxRounds is the round budget, not the node count, and multiple stages in the same round do not consume an extra round.
A node's run returns only the changed fields. Core commits after cancellation and field checks; requires/provides are runtime contracts, and data that has not been obtained must not be faked as complete. Both self-orchestrated CoreStep and explicit Workflow remain supported.
Progressive examples for the same business case
A single ordinary step is enough to run
Beginner · 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);Add an explicit Workflow and still call run
Configuration · 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: '访客' }));Bind once when dependencies become ready later
Extension · Node.js
No Workflow was passed again. The supplied signal is merged with the instance signal; cancellation does not let a late result become a successful commit.
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<string>({ maxRounds: 2 }).bindWorkflow(workflow);
const controller = new AbortController();
console.log(await agent.run({ name: 'Ivan' }, { signal: controller.signal }));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({ maxRounds: 2 }).bindWorkflow(workflow);
const controller = new AbortController();
console.log(await agent.run({ name: 'Ivan' }, { signal: controller.signal }));