AgentModelRuntime
CORE · type · 类型合同
The subset of a runner an engine may drive; kept small so the App can supply it.
导入
import type { AgentModelRuntime } from '@jangts/agent-core/engine';/** @typedef {import('@jangts/agent-core/engine').AgentModelRuntime} AgentModelRuntime */其他公开入口:@jangts/agent-core、@jangts/agent-core/engine、@jangts/agent-core/types。
定义
类型: AgentModelRuntime
类型表达式
type AgentModelRuntime = Pick<
ModelRunner,
'invoke' | 'prepare' | 'execution' | 'remainingCalls' | 'callCount' | 'totalCallCount'
>;字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
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>>; } | 必需 | 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; } | 必需 | 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 | 必需 | 只读。见类型定义及调用场景。 |
remainingCalls | number | 必需 | 只读。Calls still available to this runner after the parent's reserve is applied. |
callCount | number | 必需 | 只读。Completed calls observed by this runner only. |
totalCallCount | number | 必需 | 只读。Includes descendant attempts; local callCount and journal remain isolated. |
成员目录
| 成员 | 用途 |
|---|---|
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. |
成员详情
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.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | string | 必需 | — |
返回: Promise<ModelResult<string>>。
等待后的值: ModelResult<string>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
value | string | 必需 | 只读。见类型定义及调用场景。 |
invocation | Readonly<ModelCallRecord> | 必需 | 只读。见类型定义及调用场景。 |
AgentModelRuntime.invoke<Result>(request: ModelCallRequest<never> & { readonly prepared: PreparedModelCall<Result>; }): Promise<ModelResult<Result>>Invoke a prepared call whose settings cannot be replaced.
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Result | — | — |
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | ModelCallRequest<never> & { readonly prepared: PreparedModelCall<Result>; } | 必需 | — |
参数 request的可选结构: 选择其中一种结构,各分支的字段要求分别列出。
分支 1
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | 可省略 | 只读。Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> & PreparedModelCall<Result> | 必需 | 只读。Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | undefined | 可省略 | 只读。见类型定义及调用场景。 |
input | string | 必需 | 见类型定义及调用场景。 |
instructions | string | undefined | 可省略 | 见类型定义及调用场景。 |
分支 2
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | 可省略 | 只读。Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> & PreparedModelCall<Result> | 必需 | 只读。Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | undefined | 可省略 | 只读。见类型定义及调用场景。 |
input | readonly ModelMessage[] | BuiltContext | ContextPlan | 必需 | 见类型定义及调用场景。 |
instructions | undefined | 可省略 | 见类型定义及调用场景。 |
返回: Promise<ModelResult<Result>>。
等待后的值: ModelResult<Result>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
value | Result | 必需 | 只读。见类型定义及调用场景。 |
invocation | Readonly<ModelCallRecord> | 必需 | 只读。见类型定义及调用场景。 |
AgentModelRuntime.invoke(request: ModelCallRequest<never>): Promise<ModelResult<string>>Invoke with the default transport and a plain-text result.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | ModelCallRequest<never> | 必需 | — |
参数 request的可选结构: 选择其中一种结构,各分支的字段要求分别列出。
分支 1
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | 可省略 | 只读。Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | 可省略 | 只读。Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | undefined | 可省略 | 只读。见类型定义及调用场景。 |
input | string | 必需 | 见类型定义及调用场景。 |
instructions | string | undefined | 可省略 | 见类型定义及调用场景。 |
分支 2
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | 可省略 | 只读。Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | 可省略 | 只读。Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | undefined | 可省略 | 只读。见类型定义及调用场景。 |
input | readonly ModelMessage[] | BuiltContext | ContextPlan | 必需 | 见类型定义及调用场景。 |
instructions | undefined | 可省略 | 见类型定义及调用场景。 |
返回: Promise<ModelResult<string>>。
等待后的值: ModelResult<string>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
value | string | 必需 | 只读。见类型定义及调用场景。 |
invocation | Readonly<ModelCallRecord> | 必需 | 只读。见类型定义及调用场景。 |
AgentModelRuntime.invoke<Result>(request: ModelCallRequest<ModelTransportDefinition<Result>> & { transport: ModelTransportDefinition<Result>; }): Promise<ModelResult<Result>>Invoke with a transport instance supplied at the call site.
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Result | — | — |
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | ModelCallRequest<ModelTransportDefinition<Result>> & { transport: ModelTransportDefinition<Result>; } | 必需 | — |
参数 request的可选结构: 选择其中一种结构,各分支的字段要求分别列出。
分支 1
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | 可省略 | 只读。Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | 可省略 | 只读。Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | ModelTransportDefinition<Result> | 必需 | 只读。见类型定义及调用场景。 |
input | string | 必需 | 见类型定义及调用场景。 |
instructions | string | undefined | 可省略 | 见类型定义及调用场景。 |
分支 2
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | 可省略 | 只读。Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | 可省略 | 只读。Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | ModelTransportDefinition<Result> | 必需 | 只读。见类型定义及调用场景。 |
input | readonly ModelMessage[] | BuiltContext | ContextPlan | 必需 | 见类型定义及调用场景。 |
instructions | undefined | 可省略 | 见类型定义及调用场景。 |
返回: Promise<ModelResult<Result>>。
等待后的值: ModelResult<Result>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
value | Result | 必需 | 只读。见类型定义及调用场景。 |
invocation | Readonly<ModelCallRecord> | 必需 | 只读。见类型定义及调用场景。 |
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.
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Id | string | — |
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | ModelCallRequest<Id> & { readonly transport: Id; } | 必需 | — |
参数 request的可选结构: 选择其中一种结构,各分支的字段要求分别列出。
分支 1
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | 可省略 | 只读。Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | 可省略 | 只读。Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | Id | 必需 | 只读。见类型定义及调用场景。 |
input | string | 必需 | 见类型定义及调用场景。 |
instructions | string | undefined | 可省略 | 见类型定义及调用场景。 |
分支 2
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | 可省略 | 只读。Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | 可省略 | 只读。Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | Id | 必需 | 只读。见类型定义及调用场景。 |
input | readonly ModelMessage[] | BuiltContext | ContextPlan | 必需 | 见类型定义及调用场景。 |
instructions | undefined | 可省略 | 见类型定义及调用场景。 |
返回: Promise<ModelResult<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>>。
等待后的值: ModelResult<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
value | RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id> | 必需 | 只读。见类型定义及调用场景。 |
invocation | Readonly<ModelCallRecord> | 必需 | 只读。见类型定义及调用场景。 |
AgentModelRuntime.invoke(request: ModelCallRequest<string | ModelTransportDefinition<unknown>>): Promise<ModelResult<unknown>>Invoke without narrowing the transport type.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | ModelCallRequest<string | ModelTransportDefinition<unknown>> | 必需 | — |
参数 request的可选结构: 选择其中一种结构,各分支的字段要求分别列出。
分支 1
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | 可省略 | 只读。Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | 可省略 | 只读。Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | string | ModelTransportDefinition<unknown> | undefined | 可省略 | 只读。见类型定义及调用场景。 |
input | string | 必需 | 见类型定义及调用场景。 |
instructions | string | undefined | 可省略 | 见类型定义及调用场景。 |
分支 2
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。Record this call in the supplied logger; omission adds no sub-flow record. |
signal | AbortSignal | undefined | 可省略 | 只读。Additional cancellation can shorten, never replace, the Runner lifetime. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Parent observation scope for this invocation; never changes execution budget or signal. |
prepared | PreparedModelCall<unknown> | undefined | 可省略 | 只读。Reuse a prepared call; its stage, transport and output reservation then take precedence. |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | string | ModelTransportDefinition<unknown> | undefined | 可省略 | 只读。见类型定义及调用场景。 |
input | readonly ModelMessage[] | BuiltContext | ContextPlan | 必需 | 见类型定义及调用场景。 |
instructions | undefined | 可省略 | 见类型定义及调用场景。 |
返回: Promise<ModelResult<unknown>>。
等待后的值: ModelResult<unknown>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
value | unknown | 必需 | 只读。见类型定义及调用场景。 |
invocation | Readonly<ModelCallRecord> | 必需 | 只读。见类型定义及调用场景。 |
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.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | ModelPrepareRequest<never> | undefined | 可省略 | — |
参数 request的可选结构: 选择其中一种结构,各分支的字段要求分别列出。
分支 1
undefined
分支 2
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | undefined | 可省略 | 只读。见类型定义及调用场景。 |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
返回: PreparedModelCall<string>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
modelId | string | undefined | 可省略 | 只读。Model binding the call was prepared with. |
stageId | string | 必需 | 只读。见类型定义及调用场景。 |
transportId | string | 必需 | 只读。见类型定义及调用场景。 |
maxOutputTokens | number | 必需 | 只读。见类型定义及调用场景。 |
remainingCalls | number | 必需 | 只读。Calls still available; a live value, so later spends are visible. |
measure | (input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurement | 必需 | Preflight measurement of one input shape. Never marks the call used and never charges the budget. |
options | Pick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature"> | 必需 | 只读。见类型定义及调用场景。 |
schemaChars | number | 必需 | 只读。见类型定义及调用场景。 |
instruction | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
createResponse | () => ModelResponseCollector<string> | 必需 | 见类型定义及调用场景。 |
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.
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Result | — | — |
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | ModelPrepareRequest<ModelTransportDefinition<Result>> & { readonly transport: ModelTransportDefinition<Result>; } | 必需 | — |
request 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | ModelTransportDefinition<Result> | 必需 | 只读。见类型定义及调用场景。 |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
返回: PreparedModelCall<Result>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
modelId | string | undefined | 可省略 | 只读。Model binding the call was prepared with. |
stageId | string | 必需 | 只读。见类型定义及调用场景。 |
transportId | string | 必需 | 只读。见类型定义及调用场景。 |
maxOutputTokens | number | 必需 | 只读。见类型定义及调用场景。 |
remainingCalls | number | 必需 | 只读。Calls still available; a live value, so later spends are visible. |
measure | (input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurement | 必需 | Preflight measurement of one input shape. Never marks the call used and never charges the budget. |
options | Pick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature"> | 必需 | 只读。见类型定义及调用场景。 |
schemaChars | number | 必需 | 只读。见类型定义及调用场景。 |
instruction | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
createResponse | () => ModelResponseCollector<Result> | 必需 | 见类型定义及调用场景。 |
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.
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Id | string | — |
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | ModelPrepareRequest<Id> & { readonly transport: Id; } | 必需 | — |
request 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | Id | 必需 | 只读。见类型定义及调用场景。 |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
返回: PreparedModelCall<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
modelId | string | undefined | 可省略 | 只读。Model binding the call was prepared with. |
stageId | string | 必需 | 只读。见类型定义及调用场景。 |
transportId | string | 必需 | 只读。见类型定义及调用场景。 |
maxOutputTokens | number | 必需 | 只读。见类型定义及调用场景。 |
remainingCalls | number | 必需 | 只读。Calls still available; a live value, so later spends are visible. |
measure | (input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurement | 必需 | Preflight measurement of one input shape. Never marks the call used and never charges the budget. |
options | Pick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature"> | 必需 | 只读。见类型定义及调用场景。 |
schemaChars | number | 必需 | 只读。见类型定义及调用场景。 |
instruction | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
createResponse | () => ModelResponseCollector<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>> | 必需 | 见类型定义及调用场景。 |
AgentModelRuntime.prepare(request: import("../structs/model/runtime.js").ModelPrepareRequest<string | ModelTransportDefinition>): import("../structs/model/runtime.js").PreparedModelCallPrepare a call without narrowing the transport type.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | ModelPrepareRequest<string | ModelTransportDefinition<unknown>> | 必需 | — |
request 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
stageId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
transport | string | ModelTransportDefinition<unknown> | undefined | 可省略 | 只读。见类型定义及调用场景。 |
maxOutputTokens | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
返回: PreparedModelCall<unknown>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
modelId | string | undefined | 可省略 | 只读。Model binding the call was prepared with. |
stageId | string | 必需 | 只读。见类型定义及调用场景。 |
transportId | string | 必需 | 只读。见类型定义及调用场景。 |
maxOutputTokens | number | 必需 | 只读。见类型定义及调用场景。 |
remainingCalls | number | 必需 | 只读。Calls still available; a live value, so later spends are visible. |
measure | (input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurement | 必需 | Preflight measurement of one input shape. Never marks the call used and never charges the budget. |
options | Pick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature"> | 必需 | 只读。见类型定义及调用场景。 |
schemaChars | number | 必需 | 只读。见类型定义及调用场景。 |
instruction | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
createResponse | () => ModelResponseCollector<unknown> | 必需 | 见类型定义及调用场景。 |
使用示例
- Agent:先运行,再逐步绑定 Tool 与依赖:Engine 执行有界循环;绑定 Workflow 后,每次只传状态中变化的数据。
- 复用基础 Workflow 与 Agent 分支:add 保留旧 Workflow,生成组合后的新 Workflow;fork 继承已有绑定及分支来源。
- 一次绑定,单次多模型与跨次切换:构造时提供稳定模型配置;请求用配置 ID 选择,不反复注入 Provider。
- 真实工具调用与请求内运行时:Core 注册并执行真实工具,返回带 invocation 的回执;业务授权由 App 注册的实现拥有。
一个普通步骤即可运行
入门 · 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);增加显式 Workflow,仍然调用 run
配置 · 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: '访客' }));