AgentBranch
CORE · interface · Type contract
Immutable identity of one branch of an agent.
The three required ids are generated per engine unless the host restores a branch; the optional ids are only present on a fork and record the exact origin, so a forked run can be attributed without consulting external storage.
Import
ts
import type { AgentBranch } from '@jangts/agent-core/engine';js
/** @typedef {import('@jangts/agent-core/engine').AgentBranch} AgentBranch */Other public entry points:@jangts/agent-core, @jangts/agent-core/engine, @jangts/agent-core/types.
Definition
ts
interface AgentBranchField structure
| Field | Type | Required | Description |
|---|---|---|---|
agentId | string | Required | Read-only. Agent the branch belongs to. |
branchId | string | Required | Read-only. Branch identifier, unique within the agent. |
agentVersionId | string | Required | Read-only. Agent version the branch was created from. |
parentBranchId | string | undefined | Optional | Read-only. Parent branch id; present only for a fork. |
parentAgentVersionId | string | undefined | Optional | Read-only. Agent version of the parent branch; present only for a fork. |
forkPointId | string | undefined | Optional | Read-only. Checkpoint the branch was forked at; present only for a fork. |
Examples
- Reusing a base Workflow and Agent branches: add preserves the old Workflow and produces a new combined Workflow; fork inherits existing bindings and the branch origin.
A base Workflow produces a new version
Beginner · 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 extended = workflow.add({
nodes: [{ id: 'format', description: '为现有回答增加结尾',
run: state => ({ answer: state.answer + '!' }), routes: [route.deliver('answer')] }],
routes: { greet: [route.to('format')] },
});
console.log(await new AgentCoreEngine({ workflow: extended }).run({ name: 'Ivan' }));
console.log(workflow.ids()); // 基础定义仍然只有 greetjs
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 extended = workflow.add({
nodes: [{ id: 'format', description: '为现有回答增加结尾',
run: state => ({ answer: state.answer + '!' }), routes: [route.deliver('answer')] }],
routes: { greet: [route.to('format')] },
});
console.log(await new AgentCoreEngine({ workflow: extended }).run({ name: 'Ivan' }));
console.log(workflow.ids()); // 基础定义仍然只有 greetInherit the base Agent bindings and branch origin
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 base = new AgentCoreEngine({ workflow });
const checkpoint = base.checkpoint({ name: 'Ivan' });
const branch = base.fork({ at: checkpoint });
console.log(await branch.run(checkpoint.read()));
console.log(branch.branch.parentBranchId === base.branch.branchId);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 base = new AgentCoreEngine({ workflow });
const checkpoint = base.checkpoint({ name: 'Ivan' });
const branch = base.fork({ at: checkpoint });
console.log(await branch.run(checkpoint.read()));
console.log(branch.branch.parentBranchId === base.branch.branchId);