Skip to content

InvokeModelContext

Defined in: src/middleware/stages.ts:75

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.

readonly agent: LocalAgent;

Defined in: src/middleware/stages.ts:77

The agent instance (escape hatch for advanced use cases).


readonly model: Model;

Defined in: src/middleware/stages.ts:79

The model this call invokes. Initialized from agent.model and replaceable per call.


readonly messages: readonly Message[];

Defined in: src/middleware/stages.ts:81

The messages to send to the model.


readonly optional systemPrompt?: SystemPrompt;

Defined in: src/middleware/stages.ts:83

System prompt to guide the model’s behavior.


readonly toolSpecs: readonly ToolSpec[];

Defined in: src/middleware/stages.ts:85

Tool specifications available to the model.


readonly optional toolChoice?: ToolChoice;

Defined in: src/middleware/stages.ts:87

Controls how the model selects tools.


readonly invocationState: InvocationState;

Defined in: src/middleware/stages.ts:89

Per-invocation state. Shared by reference — mutations are visible to hooks, tools, and AgentResult.


readonly optional projectedInputTokens?: number;

Defined in: src/middleware/stages.ts:91

Estimated input token count for this model call, or undefined if estimation failed.


readonly optional dynamicTrailingBlocks?: number;

Defined in: src/middleware/stages.ts:100

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.