InvokeModelContext
Defined in: src/middleware/stages.ts:77
Context passed to model-stage middleware. All inputs to the model call are explicit — middleware can inspect and transform any of them by passing a modified context to next(). Collection fields are defensive copies; invocationState and model are shared references.
Properties
Section titled “Properties”readonly agent: LocalAgent;Defined in: src/middleware/stages.ts:79
The agent instance (escape hatch for advanced use cases).
readonly model: Model;Defined in: src/middleware/stages.ts:81
The model this call invokes. Initialized from agent.model and replaceable per call.
messages
Section titled “messages”readonly messages: readonly Message[];Defined in: src/middleware/stages.ts:83
The messages to send to the model.
systemPrompt?
Section titled “systemPrompt?”readonly systemPrompt?: SystemPrompt;Defined in: src/middleware/stages.ts:85
System prompt to guide the model’s behavior.
toolSpecs
Section titled “toolSpecs”readonly toolSpecs: readonly ToolSpec[];Defined in: src/middleware/stages.ts:87
Tool specifications available to the model.
toolChoice?
Section titled “toolChoice?”readonly toolChoice?: ToolChoice;Defined in: src/middleware/stages.ts:89
Controls how the model selects tools.
invocationState
Section titled “invocationState”readonly invocationState: InvocationState;Defined in: src/middleware/stages.ts:91
Per-invocation state. Shared by reference — mutations are visible to hooks, tools, and AgentResult.
projectedInputTokens?
Section titled “projectedInputTokens?”readonly projectedInputTokens?: number;Defined in: src/middleware/stages.ts:93
Estimated input token count for this model call, or undefined if estimation failed.
dynamicTrailingBlocks?
Section titled “dynamicTrailingBlocks?”readonly dynamicTrailingBlocks?: number;Defined in: src/middleware/stages.ts:102
How many trailing blocks of the last user message are rebuilt on every call.
Producers add to this; a provider placing cache points keeps its own ahead of the count, since a prefix that changes every call is never read back. Counted from the end of the message so it survives a provider’s content cleaning, which only drops earlier blocks.
structuredOutputSchema?
Section titled “structuredOutputSchema?”readonly structuredOutputSchema?: ZodSchema;Defined in: src/middleware/stages.ts:105
Schema this call must produce, set on the structured output retry and passed to the provider.
invocationContext?
Section titled “invocationContext?”readonly invocationContext?: InvocationContext;Defined in: src/middleware/stages.ts:108
The request this model call belongs to, if any. See InvokeOptions.invocationContext.