Bridle
Reference

Decorators

@agent and @tool. Signatures, parameters, returns.

Two decorators in bridle.

agent

bridle.agent(
    *,
    input: type | None = None,
    output: type | None = None,
    model: str | None = None,
    system: str | None = None,
    token_budget: int | None = None,
    name: str | None = None,
)

Mark a function as an agent. Each call to the decorated function returns a Call of kind "agent". The body runs when the call is resolved.

ParameterTypeDescription
inputtype | NonePydantic schema validated against the first positional argument. Coerces dicts.
outputtype | NonePydantic schema validated against the body's return value.
modelstr | NoneDefault model for steps inside the body. See model resolution.
systemstr | NoneSystem prompt inherited by inner steps. A per-call step(..., system=...) overrides it.
token_budgetint | NoneSoft per-agent token cap. Resets usage for this subtree.
namestr | NoneTrace label. Defaults to fn.__name__.

Returns: a decorator that takes a callable and returns a wrapper. The wrapper, when called, returns a Call.

Behavior:

  • If input is a Pydantic model and the first arg isn't an instance, Bridle coerces it via model_validate.
  • If output is a Pydantic model and the body returns a non-instance, Bridle coerces it via model_validate.
  • model and token_budget are pushed into context at the agent boundary; nested agents inherit and may override.
  • The body's return value is resolve()'d before being returned, so returning an inner Call works transparently.

Raises during resolution:

  • pydantic.ValidationErrorinput or output failed.
  • ConfigurationError — no callable in the call's options (only happens if you construct the Call by hand).
  • Anything the body raises.

tool

bridle.tool(
    fn: Callable | None = None,
    /,
    *,
    name: str | None = None,
    description: str | None = None,
    raise_on_error: bool = False,
) -> Tool | Callable[[Callable], Tool]

Wrap a typed Python function as a Tool. Use bare or with arguments:

@tool
def search(query: str) -> list[str]: ...

@tool(name="lookup", raise_on_error=True)
def lookup(record_id: str) -> Record: ...
ParameterTypeDescription
namestr | NoneTool name shown to the model. Defaults to fn.__name__.
descriptionstr | NoneDescription shown to the model. Defaults to the first paragraph of the docstring, or the function name.
raise_on_errorboolIf True, exceptions become ToolExecutionError and abort the step. If False (default), exceptions are fed back to the model as recoverable tool results.

Behavior:

  • Type hints become the parameter schema via pydantic.create_model.
  • *args and **kwargs are skipped.
  • A parameter with a default value becomes optional in the schema.

Returns: a Tool (when used bare) or a decorator producing a Tool.

Tool class

@dataclass(frozen=True)
class Tool:
    name: str
    description: str
    parameters_schema: dict[str, Any]
    fn: Callable[..., Any]
    raise_on_error: bool = False
    metadata: dict[str, Any] = ...

A Tool is callable — Tool.__call__ forwards to fn. Useful for unit-testing tools as plain functions:

@tool
def add(x: int, y: int) -> int:
    """Add two numbers."""
    return x + y

assert add(2, 3) == 5

On this page