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.
| Parameter | Type | Description |
|---|---|---|
input | type | None | Pydantic schema validated against the first positional argument. Coerces dicts. |
output | type | None | Pydantic schema validated against the body's return value. |
model | str | None | Default model for steps inside the body. See model resolution. |
system | str | None | System prompt inherited by inner steps. A per-call step(..., system=...) overrides it. |
token_budget | int | None | Soft per-agent token cap. Resets usage for this subtree. |
name | str | None | Trace 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
inputis a Pydantic model and the first arg isn't an instance, Bridle coerces it viamodel_validate. - If
outputis a Pydantic model and the body returns a non-instance, Bridle coerces it viamodel_validate. modelandtoken_budgetare 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 innerCallworks transparently.
Raises during resolution:
pydantic.ValidationError—inputoroutputfailed.ConfigurationError— no callable in the call's options (only happens if you construct theCallby 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: ...| Parameter | Type | Description |
|---|---|---|
name | str | None | Tool name shown to the model. Defaults to fn.__name__. |
description | str | None | Description shown to the model. Defaults to the first paragraph of the docstring, or the function name. |
raise_on_error | bool | If 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. *argsand**kwargsare 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