Skip to content

Usage limits

Each agent defines a USAGE_LIMITS constant passed to every run — a guardrail against runaway agentic loops. request_limit caps model round-trips (each tool-call iteration is one request); total_tokens_limit caps overall tokens. An optional spend cap in USD comes from AGENT_COST_LIMIT (off by default). Exceeding any of them raises UsageLimitExceeded instead of silently burning tokens. Tune the values in your agent module to fit your task; the supervisor shares its budget with its workers so the limit bounds the whole delegation tree.

Every agent also carries the RaiseContentFilterError capability, so a response the provider filters (safety block or refusal) raises ContentFilterError instead of being retried or returned half-finished. Like UsageLimitExceeded, it propagates out of run_* for the caller to handle:

from pydantic_ai.exceptions import ContentFilterError

try:
    result = await run_supervisor(user_input)  # whichever run_* your agent has
except ContentFilterError as e:
    ...  # e.message has the reason; e.body has the filtered response