Skip to content
中文

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 ​

FieldTypeRequiredDescription
providerChatProviderRequiredSee the type definition and usage context.
executionundefinedOptionalSee the type definition and usage context.
transportsreadonly ModelTransportDefinition<unknown>[] | undefinedOptionalSee the type definition and usage context.
sink{ output?: ModelRunnerPorts["onOutput"]; } | undefinedOptionalSee the type definition and usage context.
errors{ inputBudget?: ModelRunnerPorts["inputBudgetError"]; outputBudget?: ModelRunnerPorts["outputBudgetError"]; } | undefinedOptionalSee the type definition and usage context.
childrenModelChildPolicy | undefinedOptionalRead-only. See the type definition and usage context.
maxInputCharsnumber | undefinedOptionalCharacter budget for the assembled input.
maxSchemaCharsnumber | undefinedOptionalCharacter allowance for registered capability schemas.
tokenBudgetModelTokenBudget | undefinedOptionalSee the type definition and usage context.
maxOutputTokensnumber | undefinedOptionalDefault output reservation; invoke can override it for one call.
maxCallsnumber | undefinedOptionalCalls allowed for the whole request, including descendant runners' reservations.
callTimeoutMsnumber | undefinedOptionalDeadline for one provider call, in milliseconds.
maxOutputCharsnumber | undefinedOptionalCap on streamed output characters; exceeding it fails the call.
usageboolean | undefinedOptionalRequest and record provider usage for each call.
signalundefinedOptionalSee the type definition and usage context.

Examples ​

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

API reference, usage examples and developer guides.