Call tracking middleware for agents.
Base middleware class for an agent.
Subclass this and implement any of the defined methods to customize agent behavior between steps in the main agent loop.
State schema for the agent.
State schema for ModelCallLimitMiddleware.
Extends AgentState with model call tracking fields.
Exception raised when model call limits are exceeded.
This exception is raised when the configured exit behavior is 'error' and either
the thread or run model call limit has been exceeded.
Tracks model call counts and enforces limits.
This middleware monitors the number of model calls made during agent execution and can terminate the agent when specified limits are reached. It supports both thread-level and run-level call counting with configurable exit behaviors.
Thread-level: The middleware tracks the number of model calls and persists call count across multiple runs (invocations) of the agent.
Run-level: The middleware tracks the number of model calls made during a single run (invocation) of the agent.