AgentModelBinding
CORE · type · Type contract
Model binding accepted by the engine.
Execution scope belongs to the engine, so a bound model may not carry its own signal or execution options.
Import
ts
import type { AgentModelBinding } from '@jangts/agent-core/engine';js
/** @typedef {import('@jangts/agent-core/engine').AgentModelBinding} AgentModelBinding */Other public entry points:@jangts/agent-core, @jangts/agent-core/engine, @jangts/agent-core/types.
Definition
Type: AgentModelBinding
Type expression
ts
type AgentModelBinding = ModelRunnerOptions & { execution?: never; signal?: never };Field structure
| Field | Type | Required | Description |
|---|---|---|---|
provider | ChatProvider | Required | See the type definition and usage context. |
execution | undefined | Optional | See the type definition and usage context. |
transports | readonly ModelTransportDefinition<unknown>[] | undefined | Optional | See the type definition and usage context. |
sink | { output?: ModelRunnerPorts["onOutput"]; } | undefined | Optional | See the type definition and usage context. |
errors | { inputBudget?: ModelRunnerPorts["inputBudgetError"]; outputBudget?: ModelRunnerPorts["outputBudgetError"]; } | undefined | Optional | See the type definition and usage context. |
children | ModelChildPolicy | undefined | Optional | Read-only. See the type definition and usage context. |
maxInputChars | number | undefined | Optional | Character budget for the assembled input. |
maxSchemaChars | number | undefined | Optional | Character allowance for registered capability schemas. |
tokenBudget | ModelTokenBudget | undefined | Optional | See the type definition and usage context. |
maxOutputTokens | number | undefined | Optional | Default output reservation; invoke can override it for one call. |
maxCalls | number | undefined | Optional | Calls allowed for the whole request, including descendant runners' reservations. |
callTimeoutMs | number | undefined | Optional | Deadline for one provider call, in milliseconds. |
maxOutputChars | number | undefined | Optional | Cap on streamed output characters; exceeding it fails the call. |
usage | boolean | undefined | Optional | Request and record provider usage for each call. |
signal | undefined | Optional | See the type definition and usage context. |
Examples
- Bind once, multiple models per run, and switching across runs: Provide stable model configuration at construction; requests select by configuration ID instead of injecting a Provider repeatedly.
Bind the model to the Agent in advance
Beginner · Node.js
ts
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { input: string; answer?: string };
const workflow = defineWorkflow<State, string>({ id: 'chat', nodes: [{
id: 'reply', description: '用绑定模型回答', startsRound: true,
async run(state, { model }) {
const { value } = await model.invoke({ input: state.input });
return { answer: value };
}, routes: [route.deliver('answer')],
}] });
const provider = {
async *stream(messages: readonly { content: string }[]) {
yield '收到:' + messages.at(-1)!.content;
},
};
const agent = new AgentCoreEngine({ workflow, model: { provider } });
console.log(await agent.run({ input: '你好' }));js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({ id: 'chat', nodes: [{
id: 'reply', description: '用绑定模型回答', startsRound: true,
async run(state, { model }) {
const { value } = await model.invoke({ input: state.input });
return { answer: value };
}, routes: [route.deliver('answer')],
}] });
const provider = {
async *stream(messages) {
yield '收到:' + messages.at(-1).content;
},
};
const agent = new AgentCoreEngine({ workflow, model: { provider } });
console.log(await agent.run({ input: '你好' }));Add a model catalog and supply only the ID at call time
Configuration · Node.js
ts
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { input: string; answer?: string };
const workflow = defineWorkflow<State, string>({ id: 'chat', nodes: [{
id: 'reply', description: '用绑定模型回答', startsRound: true,
async run(state, { model }) {
const { value } = await model.invoke({ input: state.input });
return { answer: value };
}, routes: [route.deliver('answer')],
}] });
const provider = {
async *stream(messages: readonly { content: string }[]) {
yield '收到:' + messages.at(-1)!.content;
},
};
const agent = new AgentCoreEngine({ workflow, model: 'quick', maxModelCalls: 4,
models: { quick: { provider, maxCalls: 2 }, careful: { provider, maxCalls: 2 } },
});
console.log(await agent.run({ input: '简答' }));
console.log(await agent.run({ input: '仔细回答' }, { modelId: 'careful' }));
agent.switchModel('careful');
console.log(await agent.run({ input: '后续默认使用 careful' }));js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({ id: 'chat', nodes: [{
id: 'reply', description: '用绑定模型回答', startsRound: true,
async run(state, { model }) {
const { value } = await model.invoke({ input: state.input });
return { answer: value };
}, routes: [route.deliver('answer')],
}] });
const provider = {
async *stream(messages) {
yield '收到:' + messages.at(-1).content;
},
};
const agent = new AgentCoreEngine({ workflow, model: 'quick', maxModelCalls: 4,
models: { quick: { provider, maxCalls: 2 }, careful: { provider, maxCalls: 2 } },
});
console.log(await agent.run({ input: '简答' }));
console.log(await agent.run({ input: '仔细回答' }, { modelId: 'careful' }));
agent.switchModel('careful');
console.log(await agent.run({ input: '后续默认使用 careful' }));