AgentModelRuntime
CORE · type · Type contract
The subset of a runner an engine may drive; kept small so the App can supply it.
Import
import type { AgentModelRuntime } from '@jangts/agent-core/engine';/** @typedef {import('@jangts/agent-core/engine').AgentModelRuntime} AgentModelRuntime */Other public entry points:@jangts/agent-core, @jangts/agent-core/engine, @jangts/agent-core/types.
Definition
Type: AgentModelRuntime
Type expression
type AgentModelRuntime = Pick<
ModelRunner,
'invoke' | 'prepare' | 'execution' | 'remainingCalls' | 'callCount' | 'totalCallCount'
>;Field structure
| Field | Type | Required | Description |
|---|---|---|---|
invoke | { (request: string): Promise<ModelResult<string>>; <Result>(request: ModelCallRequest<never> & { readonly prepared: PreparedModelCall<Result>; }): Promise<ModelResult<Result>>; (request: ModelCallRequest<never>): Promise<ModelResult<string>>; <Result>(request: ModelCallRequest<ModelTransportDefinition<Result>> & { transport: ModelTransportDefinition<Result>; }): Promise<ModelResult<Result>>; <const Id extends string>(request: ModelCallRequest<Id> & { readonly transport: Id; }): Promise<ModelResult<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>>; (request: ModelCallRequest<string | ModelTransportDefinition<unknown>>): Promise<ModelResult<unknown>>; } | Required | Invoke one model call. Named and shorthand input share the same lifecycle: validation, measurement, budget charge, streaming, commit. A caller-supplied signal only shortens the call lifetime. Invoke a prepared call whose settings cannot be replaced. Invoke with the default transport and a plain-text result. Invoke with a transport instance supplied at the call site. Invoke with a transport id registered on this runner. Invoke without narrowing the transport type. |
prepare | { (request?: import("../structs/model/runtime.js").ModelPrepareRequest<never>): import("../structs/model/runtime.js").PreparedModelCall<string>; <Result>(request: ModelPrepareRequest<ModelTransportDefinition<Result>> & { readonly transport: ModelTransportDefinition<Result>; }): PreparedModelCall<Result>; <const Id extends string>(request: ModelPrepareRequest<Id> & { readonly transport: Id; }): PreparedModelCall<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>; (request: import("../structs/model/runtime.js").ModelPrepareRequest<string | ModelTransportDefinition>): import("../structs/model/runtime.js").PreparedModelCall; } | Required | Prepare a call and measure it before invocation. A prepared call is single-use and bound to the stage, output tokens and transport it was measured with; invoke rejects any attempt to replace those settings. Prepare a call for a transport instance supplied at the call site. Prepare a call for a transport id, typed by the runner's registered transports. Prepare a call without narrowing the transport type. |
execution | ExecutionContext | Required | Read-only. See the type definition and usage context. |
remainingCalls | number | Required | Read-only. Calls still available to this runner after the parent's reserve is applied. |
callCount | number | Required | Read-only. Completed calls observed by this runner only. |
totalCallCount | number | Required | Read-only. Includes descendant attempts; local callCount and journal remain isolated. |
Member index
| Member | Purpose |
|---|---|
invoke | Invoke one model call. Named and shorthand input share the same lifecycle: validation, measurement, budget charge, streaming, commit. A caller-supplied signal only shortens the call lifetime. Invoke a prepared call whose settings cannot be replaced. Invoke with the default transport and a plain-text result. Invoke with a transport instance supplied at the call site. Invoke with a transport id registered on this runner. Invoke without narrowing the transport type. |
prepare | Prepare a call and measure it before invocation. A prepared call is single-use and bound to the stage, output tokens and transport it was measured with; invoke rejects any attempt to replace those settings. Prepare a call for a transport instance supplied at the call site. Prepare a call for a transport id, typed by the runner's registered transports. Prepare a call without narrowing the transport type. |
Member details
invoke
Invoke one model call.
Named and shorthand input share the same lifecycle: validation, measurement, budget charge, streaming, commit. A caller-supplied signal only shortens the call lifetime. Invoke a prepared call whose settings cannot be replaced. Invoke with the default transport and a plain-text result. Invoke with a transport instance supplied at the call site. Invoke with a transport id registered on this runner. Invoke without narrowing the transport type.
AgentModelRuntime.invoke(request: string): Promise<ModelResult<string>>Invoke one model call.
Named and shorthand input share the same lifecycle: validation, measurement, budget charge, streaming, commit. A caller-supplied signal only shortens the call lifetime.
| Parameter | Type | Passing | Description |
|---|---|---|---|
request | string | Required | — |
Returns: Promise<ModelResult<string>>.
Awaited value: ModelResult<string>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
value | string | Required | Read-only. See the type definition and usage context. |
invocation | Readonly<ModelCallRecord> | Required | Read-only. See the type definition and usage context. |
AgentModelRuntime.invoke<Result>(request: ModelCallRequest<never> & { readonly prepared: PreparedModelCall<Result>; }): Promise<ModelResult<Result>>Invoke a prepared call whose settings cannot be replaced.
| Type parameter | Constraint | Default type |
|---|---|---|
Result | — | — |
| Parameter | Type | Passing | Description |
|---|---|---|---|
request | ModelCallRequest<never> & { readonly prepared: PreparedModelCall<Result>; } | Required | — |
Optional shapes of Parameter request: choose one shape; required fields for each branch are listed separately.
Branch 1
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLogger | undefined | Optional | Read-only. Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | Optional | Read-only. Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> & PreparedModelCall<Result> | Required | Read-only. Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | undefined | Optional | Read-only. See the type definition and usage context. |
input | string | Required | See the type definition and usage context. |
instructions | string | undefined | Optional | See the type definition and usage context. |
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLogger | undefined | Optional | Read-only. Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | Optional | Read-only. Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> & PreparedModelCall<Result> | Required | Read-only. Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | undefined | Optional | Read-only. See the type definition and usage context. |
input | readonly ModelMessage[] | BuiltContext | ContextPlan | Required | See the type definition and usage context. |
instructions | undefined | Optional | See the type definition and usage context. |
Returns: Promise<ModelResult<Result>>.
Awaited value: ModelResult<Result>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
value | Result | Required | Read-only. See the type definition and usage context. |
invocation | Readonly<ModelCallRecord> | Required | Read-only. See the type definition and usage context. |
AgentModelRuntime.invoke(request: ModelCallRequest<never>): Promise<ModelResult<string>>Invoke with the default transport and a plain-text result.
| Parameter | Type | Passing | Description |
|---|---|---|---|
request | ModelCallRequest<never> | Required | — |
Optional shapes of Parameter request: choose one shape; required fields for each branch are listed separately.
Branch 1
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLogger | undefined | Optional | Read-only. Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | Optional | Read-only. Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | Optional | Read-only. Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | undefined | Optional | Read-only. See the type definition and usage context. |
input | string | Required | See the type definition and usage context. |
instructions | string | undefined | Optional | See the type definition and usage context. |
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLogger | undefined | Optional | Read-only. Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | Optional | Read-only. Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | Optional | Read-only. Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | undefined | Optional | Read-only. See the type definition and usage context. |
input | readonly ModelMessage[] | BuiltContext | ContextPlan | Required | See the type definition and usage context. |
instructions | undefined | Optional | See the type definition and usage context. |
Returns: Promise<ModelResult<string>>.
Awaited value: ModelResult<string>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
value | string | Required | Read-only. See the type definition and usage context. |
invocation | Readonly<ModelCallRecord> | Required | Read-only. See the type definition and usage context. |
AgentModelRuntime.invoke<Result>(request: ModelCallRequest<ModelTransportDefinition<Result>> & { transport: ModelTransportDefinition<Result>; }): Promise<ModelResult<Result>>Invoke with a transport instance supplied at the call site.
| Type parameter | Constraint | Default type |
|---|---|---|
Result | — | — |
| Parameter | Type | Passing | Description |
|---|---|---|---|
request | ModelCallRequest<ModelTransportDefinition<Result>> & { transport: ModelTransportDefinition<Result>; } | Required | — |
Optional shapes of Parameter request: choose one shape; required fields for each branch are listed separately.
Branch 1
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLogger | undefined | Optional | Read-only. Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | Optional | Read-only. Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | Optional | Read-only. Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | ModelTransportDefinition<Result> | Required | Read-only. See the type definition and usage context. |
input | string | Required | See the type definition and usage context. |
instructions | string | undefined | Optional | See the type definition and usage context. |
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLogger | undefined | Optional | Read-only. Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | Optional | Read-only. Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | Optional | Read-only. Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | ModelTransportDefinition<Result> | Required | Read-only. See the type definition and usage context. |
input | readonly ModelMessage[] | BuiltContext | ContextPlan | Required | See the type definition and usage context. |
instructions | undefined | Optional | See the type definition and usage context. |
Returns: Promise<ModelResult<Result>>.
Awaited value: ModelResult<Result>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
value | Result | Required | Read-only. See the type definition and usage context. |
invocation | Readonly<ModelCallRecord> | Required | Read-only. See the type definition and usage context. |
AgentModelRuntime.invoke<const Id extends string>(request: ModelCallRequest<Id> & { readonly transport: Id; }): Promise<ModelResult<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>>Invoke with a transport id registered on this runner.
| Type parameter | Constraint | Default type |
|---|---|---|
Id | string | — |
| Parameter | Type | Passing | Description |
|---|---|---|---|
request | ModelCallRequest<Id> & { readonly transport: Id; } | Required | — |
Optional shapes of Parameter request: choose one shape; required fields for each branch are listed separately.
Branch 1
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLogger | undefined | Optional | Read-only. Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | Optional | Read-only. Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | Optional | Read-only. Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | Id | Required | Read-only. See the type definition and usage context. |
input | string | Required | See the type definition and usage context. |
instructions | string | undefined | Optional | See the type definition and usage context. |
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLogger | undefined | Optional | Read-only. Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | Optional | Read-only. Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | Optional | Read-only. Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | Id | Required | Read-only. See the type definition and usage context. |
input | readonly ModelMessage[] | BuiltContext | ContextPlan | Required | See the type definition and usage context. |
instructions | undefined | Optional | See the type definition and usage context. |
Returns: Promise<ModelResult<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>>.
Awaited value: ModelResult<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
value | RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id> | Required | Read-only. See the type definition and usage context. |
invocation | Readonly<ModelCallRecord> | Required | Read-only. See the type definition and usage context. |
AgentModelRuntime.invoke(request: ModelCallRequest<string | ModelTransportDefinition<unknown>>): Promise<ModelResult<unknown>>Invoke without narrowing the transport type.
| Parameter | Type | Passing | Description |
|---|---|---|---|
request | ModelCallRequest<string | ModelTransportDefinition<unknown>> | Required | — |
Optional shapes of Parameter request: choose one shape; required fields for each branch are listed separately.
Branch 1
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLogger | undefined | Optional | Read-only. Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | Optional | Read-only. Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | Optional | Read-only. Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | string | ModelTransportDefinition<unknown> | undefined | Optional | Read-only. See the type definition and usage context. |
input | string | Required | See the type definition and usage context. |
instructions | string | undefined | Optional | See the type definition and usage context. |
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLogger | undefined | Optional | Read-only. Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | Optional | Read-only. Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | Optional | Read-only. Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | string | ModelTransportDefinition<unknown> | undefined | Optional | Read-only. See the type definition and usage context. |
input | readonly ModelMessage[] | BuiltContext | ContextPlan | Required | See the type definition and usage context. |
instructions | undefined | Optional | See the type definition and usage context. |
Returns: Promise<ModelResult<unknown>>.
Awaited value: ModelResult<unknown>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
value | unknown | Required | Read-only. See the type definition and usage context. |
invocation | Readonly<ModelCallRecord> | Required | Read-only. See the type definition and usage context. |
prepare
Prepare a call and measure it before invocation.
A prepared call is single-use and bound to the stage, output tokens and transport it was measured with; invoke rejects any attempt to replace those settings. Prepare a call for a transport instance supplied at the call site. Prepare a call for a transport id, typed by the runner's registered transports. Prepare a call without narrowing the transport type.
AgentModelRuntime.prepare(request?: import("../structs/model/runtime.js").ModelPrepareRequest<never>): import("../structs/model/runtime.js").PreparedModelCall<string>Prepare a call and measure it before invocation.
A prepared call is single-use and bound to the stage, output tokens and transport it was measured with; invoke rejects any attempt to replace those settings.
| Parameter | Type | Passing | Description |
|---|---|---|---|
request | ModelPrepareRequest<never> | undefined | Optional | — |
Optional shapes of Parameter request: choose one shape; required fields for each branch are listed separately.
Branch 1
undefined
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | undefined | Optional | Read-only. See the type definition and usage context. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: PreparedModelCall<string>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
modelId | string | undefined | Optional | Read-only. Model binding the call was prepared with. |
stageId | string | Required | Read-only. See the type definition and usage context. |
transportId | string | Required | Read-only. See the type definition and usage context. |
maxOutputTokens | number | Required | Read-only. See the type definition and usage context. |
remainingCalls | number | Required | Read-only. Calls still available; a live value, so later spends are visible. |
measure | (input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurement | Required | Preflight measurement of one input shape. Never marks the call used and never charges the budget. |
options | Pick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature"> | Required | Read-only. See the type definition and usage context. |
schemaChars | number | Required | Read-only. See the type definition and usage context. |
instruction | string | undefined | Optional | Read-only. See the type definition and usage context. |
createResponse | () => ModelResponseCollector<string> | Required | See the type definition and usage context. |
AgentModelRuntime.prepare<Result>(request: ModelPrepareRequest<ModelTransportDefinition<Result>> & { readonly transport: ModelTransportDefinition<Result>; }): PreparedModelCall<Result>Prepare a call for a transport instance supplied at the call site.
| Type parameter | Constraint | Default type |
|---|---|---|
Result | — | — |
| Parameter | Type | Passing | Description |
|---|---|---|---|
request | ModelPrepareRequest<ModelTransportDefinition<Result>> & { readonly transport: ModelTransportDefinition<Result>; } | Required | — |
Fields of request
| Field | Type | Required | Description |
|---|---|---|---|
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | ModelTransportDefinition<Result> | Required | Read-only. See the type definition and usage context. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: PreparedModelCall<Result>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
modelId | string | undefined | Optional | Read-only. Model binding the call was prepared with. |
stageId | string | Required | Read-only. See the type definition and usage context. |
transportId | string | Required | Read-only. See the type definition and usage context. |
maxOutputTokens | number | Required | Read-only. See the type definition and usage context. |
remainingCalls | number | Required | Read-only. Calls still available; a live value, so later spends are visible. |
measure | (input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurement | Required | Preflight measurement of one input shape. Never marks the call used and never charges the budget. |
options | Pick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature"> | Required | Read-only. See the type definition and usage context. |
schemaChars | number | Required | Read-only. See the type definition and usage context. |
instruction | string | undefined | Optional | Read-only. See the type definition and usage context. |
createResponse | () => ModelResponseCollector<Result> | Required | See the type definition and usage context. |
AgentModelRuntime.prepare<const Id extends string>(request: ModelPrepareRequest<Id> & { readonly transport: Id; }): PreparedModelCall<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>Prepare a call for a transport id, typed by the runner's registered transports.
| Type parameter | Constraint | Default type |
|---|---|---|
Id | string | — |
| Parameter | Type | Passing | Description |
|---|---|---|---|
request | ModelPrepareRequest<Id> & { readonly transport: Id; } | Required | — |
Fields of request
| Field | Type | Required | Description |
|---|---|---|---|
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | Id | Required | Read-only. See the type definition and usage context. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: PreparedModelCall<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
modelId | string | undefined | Optional | Read-only. Model binding the call was prepared with. |
stageId | string | Required | Read-only. See the type definition and usage context. |
transportId | string | Required | Read-only. See the type definition and usage context. |
maxOutputTokens | number | Required | Read-only. See the type definition and usage context. |
remainingCalls | number | Required | Read-only. Calls still available; a live value, so later spends are visible. |
measure | (input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurement | Required | Preflight measurement of one input shape. Never marks the call used and never charges the budget. |
options | Pick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature"> | Required | Read-only. See the type definition and usage context. |
schemaChars | number | Required | Read-only. See the type definition and usage context. |
instruction | string | undefined | Optional | Read-only. See the type definition and usage context. |
createResponse | () => ModelResponseCollector<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>> | Required | See the type definition and usage context. |
AgentModelRuntime.prepare(request: import("../structs/model/runtime.js").ModelPrepareRequest<string | ModelTransportDefinition>): import("../structs/model/runtime.js").PreparedModelCallPrepare a call without narrowing the transport type.
| Parameter | Type | Passing | Description |
|---|---|---|---|
request | ModelPrepareRequest<string | ModelTransportDefinition<unknown>> | Required | — |
Fields of request
| Field | Type | Required | Description |
|---|---|---|---|
stageId | string | undefined | Optional | Read-only. See the type definition and usage context. |
transport | string | ModelTransportDefinition<unknown> | undefined | Optional | Read-only. See the type definition and usage context. |
maxOutputTokens | number | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: PreparedModelCall<unknown>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
modelId | string | undefined | Optional | Read-only. Model binding the call was prepared with. |
stageId | string | Required | Read-only. See the type definition and usage context. |
transportId | string | Required | Read-only. See the type definition and usage context. |
maxOutputTokens | number | Required | Read-only. See the type definition and usage context. |
remainingCalls | number | Required | Read-only. Calls still available; a live value, so later spends are visible. |
measure | (input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurement | Required | Preflight measurement of one input shape. Never marks the call used and never charges the budget. |
options | Pick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature"> | Required | Read-only. See the type definition and usage context. |
schemaChars | number | Required | Read-only. See the type definition and usage context. |
instruction | string | undefined | Optional | Read-only. See the type definition and usage context. |
createResponse | () => ModelResponseCollector<unknown> | Required | See the type definition and usage context. |
Examples
- 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.
- 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.
- 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.
- Real tool invocation and in-request runtime: Core registers and executes real tools and returns receipts carrying an invocation; business authorization is owned by the implementation registered by the App.
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: '访客' }));Related policy source
- Execution implementation of the bounded loop, commit, and cancellation
- Check order for tool input, execution, output, and late results