Bridle
Reference

Runtime

Process and context configuration. configure, set_cache, and the current_* readers.

Bridle's runtime is held in contextvars so concurrent agents in one process carry their own settings. The functions in bridle.runtime push values onto the context; current_* functions read them; primitives consult them when they dispatch.

Most users only need configure, set_cache, and set_model_client (via the Anthropic adapter's install()). The lower-level functions are exposed for tests and advanced wrappers.

configure

bridle.configure(
    *,
    model: str | None = None,
    token_budget: int | None = None,
    cache: CacheBackend | None = None,
    model_client: ModelClient | None = None,
) -> None

Set process-wide defaults. Each parameter is independent and opt-in. Subsequent calls overwrite the corresponding setting.

set_cache

bridle.set_cache(backend: CacheBackend) -> None

Register the active cache backend. The cache wrapper consults it on each evaluation. See cache backends.

set_model_client

bridle.runtime.set_model_client(client: ModelClient) -> None

Register the active model client. The Anthropic adapter calls this from install(); tests use it to register a MockModelClient.

Readers

bridle.current_model() -> str | None
bridle.current_token_budget() -> int | None
bridle.current_cache() -> CacheBackend | None
bridle.runtime.current_model_client() -> ModelClient | None
bridle.current_token_usage() -> int

Returns whatever is set in the current context, or None.

Agent context (advanced)

@agent pushes the model and budget into the context for the duration of the body. The push/reset functions are exported for unusual needs (custom decorators, instrumentation):

bridle.runtime.push_agent_model(model: str | None) -> Token
bridle.runtime.reset_agent_model(token: Token) -> None

bridle.runtime.push_agent_token_budget(budget: int | None) -> Token
bridle.runtime.reset_agent_token_budget(token: Token) -> None

bridle.runtime.push_token_usage(value: int) -> Token
bridle.runtime.reset_token_usage(token: Token) -> None

bridle.runtime.bump_token_usage(delta: int) -> int

bump_token_usage adds non-negative delta and returns the new total. The Anthropic adapter calls it after each turn.

Per-call model context

bridle.runtime.current_per_call_model() -> str | None
bridle.runtime.push_per_call_model(model: str) -> Token
bridle.runtime.reset_per_call_model(token: Token) -> None

with_model uses these. Most users never call them directly.

Model resolution

bridle.runtime.require_model(
    per_call: str | None = None,
    per_agent: str | None = None,
) -> str

Returns the active model name in order: per-call → per-agent → process. Raises ConfigurationError with explicit guidance when nothing is set. See model resolution for the full picture.

bridle.runtime.effective_token_budget() -> int | None

The active budget — agent-level wins over process-level.

On this page