Skip to content
中文

AgentModelRuntime ​

CORE · type · Type contract

The subset of a runner an engine may drive; kept small so the App can supply it.

Import ​

ts
import type { AgentModelRuntime } from '@jangts/agent-core/engine';
js
/** @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
ts
type AgentModelRuntime = Pick<
  ModelRunner,
  'invoke' | 'prepare' | 'execution' | 'remainingCalls' | 'callCount' | 'totalCallCount'
>;

Field structure ​

FieldTypeRequiredDescription
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>>; }RequiredInvoke 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; }RequiredPrepare 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.
executionExecutionContextRequiredRead-only. See the type definition and usage context.
remainingCallsnumberRequiredRead-only. Calls still available to this runner after the parent's reserve is applied.
callCountnumberRequiredRead-only. Completed calls observed by this runner only.
totalCallCountnumberRequiredRead-only. Includes descendant attempts; local callCount and journal remain isolated.

Member index ​

MemberPurpose
invokeInvoke 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.
preparePrepare 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.

ts
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.

ParameterTypePassingDescription
requeststringRequired—

Returns: Promise<ModelResult<string>>.

Awaited value: ModelResult<string>.

Return value structure
FieldTypeRequiredDescription
valuestringRequiredRead-only. See the type definition and usage context.
invocationReadonly<ModelCallRecord>RequiredRead-only. See the type definition and usage context.
ts
AgentModelRuntime.invoke<Result>(request: ModelCallRequest<never> & { readonly prepared: PreparedModelCall<Result>; }): Promise<ModelResult<Result>>

Invoke a prepared call whose settings cannot be replaced.

Type parameterConstraintDefault type
Result——
ParameterTypePassingDescription
requestModelCallRequest<never> & { readonly prepared: PreparedModelCall<Result>; }Required—

Optional shapes of Parameter request: choose one shape; required fields for each branch are listed separately.

Branch 1
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefinedOptionalRead-only. Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> & PreparedModelCall<Result>RequiredRead-only. Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportundefinedOptionalRead-only. See the type definition and usage context.
inputstringRequiredSee the type definition and usage context.
instructionsstring | undefinedOptionalSee the type definition and usage context.
Branch 2
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefinedOptionalRead-only. Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> & PreparedModelCall<Result>RequiredRead-only. Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportundefinedOptionalRead-only. See the type definition and usage context.
inputreadonly ModelMessage[] | BuiltContext | ContextPlanRequiredSee the type definition and usage context.
instructionsundefinedOptionalSee the type definition and usage context.

Returns: Promise<ModelResult<Result>>.

Awaited value: ModelResult<Result>.

Return value structure
FieldTypeRequiredDescription
valueResultRequiredRead-only. See the type definition and usage context.
invocationReadonly<ModelCallRecord>RequiredRead-only. See the type definition and usage context.
ts
AgentModelRuntime.invoke(request: ModelCallRequest<never>): Promise<ModelResult<string>>

Invoke with the default transport and a plain-text result.

ParameterTypePassingDescription
requestModelCallRequest<never>Required—

Optional shapes of Parameter request: choose one shape; required fields for each branch are listed separately.

Branch 1
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefinedOptionalRead-only. Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefinedOptionalRead-only. Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportundefinedOptionalRead-only. See the type definition and usage context.
inputstringRequiredSee the type definition and usage context.
instructionsstring | undefinedOptionalSee the type definition and usage context.
Branch 2
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefinedOptionalRead-only. Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefinedOptionalRead-only. Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportundefinedOptionalRead-only. See the type definition and usage context.
inputreadonly ModelMessage[] | BuiltContext | ContextPlanRequiredSee the type definition and usage context.
instructionsundefinedOptionalSee the type definition and usage context.

Returns: Promise<ModelResult<string>>.

Awaited value: ModelResult<string>.

Return value structure
FieldTypeRequiredDescription
valuestringRequiredRead-only. See the type definition and usage context.
invocationReadonly<ModelCallRecord>RequiredRead-only. See the type definition and usage context.
ts
AgentModelRuntime.invoke<Result>(request: ModelCallRequest<ModelTransportDefinition<Result>> & { transport: ModelTransportDefinition<Result>; }): Promise<ModelResult<Result>>

Invoke with a transport instance supplied at the call site.

Type parameterConstraintDefault type
Result——
ParameterTypePassingDescription
requestModelCallRequest<ModelTransportDefinition<Result>> & { transport: ModelTransportDefinition<Result>; }Required—

Optional shapes of Parameter request: choose one shape; required fields for each branch are listed separately.

Branch 1
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefinedOptionalRead-only. Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefinedOptionalRead-only. Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportModelTransportDefinition<Result>RequiredRead-only. See the type definition and usage context.
inputstringRequiredSee the type definition and usage context.
instructionsstring | undefinedOptionalSee the type definition and usage context.
Branch 2
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefinedOptionalRead-only. Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefinedOptionalRead-only. Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportModelTransportDefinition<Result>RequiredRead-only. See the type definition and usage context.
inputreadonly ModelMessage[] | BuiltContext | ContextPlanRequiredSee the type definition and usage context.
instructionsundefinedOptionalSee the type definition and usage context.

Returns: Promise<ModelResult<Result>>.

Awaited value: ModelResult<Result>.

Return value structure
FieldTypeRequiredDescription
valueResultRequiredRead-only. See the type definition and usage context.
invocationReadonly<ModelCallRecord>RequiredRead-only. See the type definition and usage context.
ts
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 parameterConstraintDefault type
Idstring—
ParameterTypePassingDescription
requestModelCallRequest<Id> & { readonly transport: Id; }Required—

Optional shapes of Parameter request: choose one shape; required fields for each branch are listed separately.

Branch 1
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefinedOptionalRead-only. Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefinedOptionalRead-only. Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportIdRequiredRead-only. See the type definition and usage context.
inputstringRequiredSee the type definition and usage context.
instructionsstring | undefinedOptionalSee the type definition and usage context.
Branch 2
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefinedOptionalRead-only. Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefinedOptionalRead-only. Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportIdRequiredRead-only. See the type definition and usage context.
inputreadonly ModelMessage[] | BuiltContext | ContextPlanRequiredSee the type definition and usage context.
instructionsundefinedOptionalSee 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
FieldTypeRequiredDescription
valueRegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>RequiredRead-only. See the type definition and usage context.
invocationReadonly<ModelCallRecord>RequiredRead-only. See the type definition and usage context.
ts
AgentModelRuntime.invoke(request: ModelCallRequest<string | ModelTransportDefinition<unknown>>): Promise<ModelResult<unknown>>

Invoke without narrowing the transport type.

ParameterTypePassingDescription
requestModelCallRequest<string | ModelTransportDefinition<unknown>>Required—

Optional shapes of Parameter request: choose one shape; required fields for each branch are listed separately.

Branch 1
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefinedOptionalRead-only. Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefinedOptionalRead-only. Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportstring | ModelTransportDefinition<unknown> | undefinedOptionalRead-only. See the type definition and usage context.
inputstringRequiredSee the type definition and usage context.
instructionsstring | undefinedOptionalSee the type definition and usage context.
Branch 2
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefinedOptionalRead-only. Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefinedOptionalRead-only. Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportstring | ModelTransportDefinition<unknown> | undefinedOptionalRead-only. See the type definition and usage context.
inputreadonly ModelMessage[] | BuiltContext | ContextPlanRequiredSee the type definition and usage context.
instructionsundefinedOptionalSee the type definition and usage context.

Returns: Promise<ModelResult<unknown>>.

Awaited value: ModelResult<unknown>.

Return value structure
FieldTypeRequiredDescription
valueunknownRequiredRead-only. See the type definition and usage context.
invocationReadonly<ModelCallRecord>RequiredRead-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.

ts
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.

ParameterTypePassingDescription
requestModelPrepareRequest<never> | undefinedOptional—

Optional shapes of Parameter request: choose one shape; required fields for each branch are listed separately.

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportundefinedOptionalRead-only. See the type definition and usage context.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.

Returns: PreparedModelCall<string>.

Return value structure
FieldTypeRequiredDescription
modelIdstring | undefinedOptionalRead-only. Model binding the call was prepared with.
stageIdstringRequiredRead-only. See the type definition and usage context.
transportIdstringRequiredRead-only. See the type definition and usage context.
maxOutputTokensnumberRequiredRead-only. See the type definition and usage context.
remainingCallsnumberRequiredRead-only. Calls still available; a live value, so later spends are visible.
measure(input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurementRequiredPreflight measurement of one input shape. Never marks the call used and never charges the budget.
optionsPick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature">RequiredRead-only. See the type definition and usage context.
schemaCharsnumberRequiredRead-only. See the type definition and usage context.
instructionstring | undefinedOptionalRead-only. See the type definition and usage context.
createResponse() => ModelResponseCollector<string>RequiredSee the type definition and usage context.
ts
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 parameterConstraintDefault type
Result——
ParameterTypePassingDescription
requestModelPrepareRequest<ModelTransportDefinition<Result>> & { readonly transport: ModelTransportDefinition<Result>; }Required—
Fields of request
FieldTypeRequiredDescription
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportModelTransportDefinition<Result>RequiredRead-only. See the type definition and usage context.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.

Returns: PreparedModelCall<Result>.

Return value structure
FieldTypeRequiredDescription
modelIdstring | undefinedOptionalRead-only. Model binding the call was prepared with.
stageIdstringRequiredRead-only. See the type definition and usage context.
transportIdstringRequiredRead-only. See the type definition and usage context.
maxOutputTokensnumberRequiredRead-only. See the type definition and usage context.
remainingCallsnumberRequiredRead-only. Calls still available; a live value, so later spends are visible.
measure(input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurementRequiredPreflight measurement of one input shape. Never marks the call used and never charges the budget.
optionsPick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature">RequiredRead-only. See the type definition and usage context.
schemaCharsnumberRequiredRead-only. See the type definition and usage context.
instructionstring | undefinedOptionalRead-only. See the type definition and usage context.
createResponse() => ModelResponseCollector<Result>RequiredSee the type definition and usage context.
ts
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 parameterConstraintDefault type
Idstring—
ParameterTypePassingDescription
requestModelPrepareRequest<Id> & { readonly transport: Id; }Required—
Fields of request
FieldTypeRequiredDescription
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportIdRequiredRead-only. See the type definition and usage context.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.

Returns: PreparedModelCall<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>.

Return value structure
FieldTypeRequiredDescription
modelIdstring | undefinedOptionalRead-only. Model binding the call was prepared with.
stageIdstringRequiredRead-only. See the type definition and usage context.
transportIdstringRequiredRead-only. See the type definition and usage context.
maxOutputTokensnumberRequiredRead-only. See the type definition and usage context.
remainingCallsnumberRequiredRead-only. Calls still available; a live value, so later spends are visible.
measure(input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurementRequiredPreflight measurement of one input shape. Never marks the call used and never charges the budget.
optionsPick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature">RequiredRead-only. See the type definition and usage context.
schemaCharsnumberRequiredRead-only. See the type definition and usage context.
instructionstring | undefinedOptionalRead-only. See the type definition and usage context.
createResponse() => ModelResponseCollector<RegisteredTransportOutput<readonly ModelTransportDefinition<unknown>[], Id>>RequiredSee the type definition and usage context.
ts
AgentModelRuntime.prepare(request: import("../structs/model/runtime.js").ModelPrepareRequest<string | ModelTransportDefinition>): import("../structs/model/runtime.js").PreparedModelCall

Prepare a call without narrowing the transport type.

ParameterTypePassingDescription
requestModelPrepareRequest<string | ModelTransportDefinition<unknown>>Required—
Fields of request
FieldTypeRequiredDescription
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportstring | ModelTransportDefinition<unknown> | undefinedOptionalRead-only. See the type definition and usage context.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.

Returns: PreparedModelCall<unknown>.

Return value structure
FieldTypeRequiredDescription
modelIdstring | undefinedOptionalRead-only. Model binding the call was prepared with.
stageIdstringRequiredRead-only. See the type definition and usage context.
transportIdstringRequiredRead-only. See the type definition and usage context.
maxOutputTokensnumberRequiredRead-only. See the type definition and usage context.
remainingCallsnumberRequiredRead-only. Calls still available; a live value, so later spends are visible.
measure(input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurementRequiredPreflight measurement of one input shape. Never marks the call used and never charges the budget.
optionsPick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature">RequiredRead-only. See the type definition and usage context.
schemaCharsnumberRequiredRead-only. See the type definition and usage context.
instructionstring | undefinedOptionalRead-only. See the type definition and usage context.
createResponse() => ModelResponseCollector<unknown>RequiredSee the type definition and usage context.

Examples ​

A single ordinary step is enough to run ​

Beginner · Node.js

ts
import { AgentCoreEngine } from '@jangts/agent-core/engine';

const agent = new AgentCoreEngine<string>();
const answer = await agent.run(() => ({ type: 'complete', value: '你好,Core' }));
console.log(answer);
js
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

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 agent = new AgentCoreEngine({ workflow });
console.log(await agent.run({ name: 'Ivan' }));
console.log(await agent.run({ name: '访客' }));
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 agent = new AgentCoreEngine({ workflow });
console.log(await agent.run({ name: 'Ivan' }));
console.log(await agent.run({ name: '访客' }));

API reference, usage examples and developer guides.