Interface: MiddlewareContext
@providerprotocol/agents / index / MiddlewareContext
Interface: MiddlewareContext
Section titled “Interface: MiddlewareContext”Defined in: src/middleware/types.ts:18
Context passed to middleware functions during agent execution.
This context object provides access to the agent, input message, current state, and a metadata map for sharing data between middleware functions in the chain.
Remarks
Section titled “Remarks”The metadata map is mutable and can be used to pass data between before and
after hooks of the same middleware, or between different middleware in the chain.
Use namespaced keys (e.g., _myMiddleware_key) to avoid collisions.
Middleware for the middleware interface that receives this context
Properties
Section titled “Properties”agent:
AgentRef
Defined in: src/middleware/types.ts:24
Reference to the agent being executed.
Provides access to agent identity and configuration.
input:
Message
Defined in: src/middleware/types.ts:31
The user input message that triggered this execution.
This is the original message passed to the agent’s generate method.
metadata
Section titled “metadata”metadata:
Map<string,unknown>
Defined in: src/middleware/types.ts:58
Mutable metadata map for sharing data between middleware hooks.
Remarks
Section titled “Remarks”Common uses include storing timing information in before and reading
it in after, or passing computed values down the middleware chain.
Example
Section titled “Example”// In before hookcontext.metadata.set('_myMiddleware_startTime', Date.now());
// In after hookconst startTime = context.metadata.get('_myMiddleware_startTime') as number;state:
AgentState
Defined in: src/middleware/types.ts:40
The current agent state, including conversation history.
Remarks
Section titled “Remarks”While the state object itself is accessible, modifications should be handled through proper state management rather than direct mutation.