> For the complete documentation index, see [llms.txt](/llms.txt). Every page on this site is also available as markdown at `<path>.md`.

# Tools

Tool specification and decorator. `define_tool(...)` is callable, so the
returned [`ToolSpec`](#flowai_harness.tools.ToolSpec) can be used as a
decorator to attach a Python handler.

<span id="flowai_harness.tools.define_tool"></span>

## `define_tool`

`define_tool(name: 'str', input_schema: 'Any', description: 'str' = '', approval: 'str | Mapping[str, Any] | Callable[..., bool]' = 'never', output_schema: 'Any | None' = None, binding_id: 'str | None' = None) -> 'ToolSpec'`

<table>
<thead>
<tr>
<th>Parameter</th>
<th>Type</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>name</code></td>
<td><code>str</code></td>
<td>required</td>
</tr>
<tr>
<td><code>input_schema</code></td>
<td><code>Any</code></td>
<td>required</td>
</tr>
<tr>
<td><code>description</code></td>
<td><code>str</code></td>
<td><code>''</code></td>
</tr>
<tr>
<td><code>approval</code></td>
<td><code>str | Mapping[str, Any] | Callable[..., bool]</code></td>
<td><code>'never'</code></td>
</tr>
<tr>
<td><code>output_schema</code></td>
<td><code>Any | None</code></td>
<td><code>None</code></td>
</tr>
<tr>
<td><code>binding_id</code></td>
<td><code>str | None</code></td>
<td><code>None</code></td>
</tr>
</tbody>
</table>

<p><strong>Returns:</strong> <code>ToolSpec</code></p>

Create a validated Flow AI tool spec.

The returned value is callable, so it can be used as a decorator:

``@define_tool(name="search", input_schema={"query": str})``.

Args:
    name: Tool name presented to the model.
    input_schema: Tool input schema: a JSON Schema mapping, a Pydantic
        model class, a simple type map such as ``{"query": str}``, or
        any type hint Pydantic can export.
    description: Tool description presented to the model.
    approval: Approval policy: ``"never"`` (default), ``"always"``, a
        mapping ``{"kind": "dynamic", "value": predicate_id}``, or a
        callable predicate. A callable becomes a dynamic policy whose id
        is ``binding_id`` or ``"<name>_approval"``, with the callable
        attached as the approval handler.
    output_schema: Optional output schema, normalized like
        ``input_schema``.
    binding_id: Stable binding key for handler registration; defaults to
        the tool name.

Returns:
    A frozen ``ToolSpec``. Bind a Python handler with ``.bind(handler)``
    or by calling the spec as a decorator.

Raises:
    ValueError: If ``approval`` is not a recognized policy, or a
        callable approval is supplied without a tool name.
    TypeError: If a schema input cannot be normalized to JSON Schema.

<span id="flowai_harness.tools.ToolSpec"></span>

## `ToolSpec`

`ToolSpec(*, name: str, description: str = '', inputSchema: dict[str, typing.Any], approval: dict[str, typing.Any] = <factory>, outputSchema: dict[str, typing.Any] | None = None, bindingId: str | None = None, handler: collections.abc.Callable[..., typing.Any] | None = None, approvalHandler: collections.abc.Callable[..., bool] | None = None) -> None`

<table>
<thead>
<tr>
<th>Parameter</th>
<th>Type</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>name</code></td>
<td><code>str</code></td>
<td>required</td>
</tr>
<tr>
<td><code>description</code></td>
<td><code>str</code></td>
<td><code>''</code></td>
</tr>
<tr>
<td><code>inputSchema</code></td>
<td><code>dict</code></td>
<td>required</td>
</tr>
<tr>
<td><code>approval</code></td>
<td><code>dict</code></td>
<td><code>&lt;factory&gt;</code></td>
</tr>
<tr>
<td><code>outputSchema</code></td>
<td><code>dict[str, Any] | None</code></td>
<td><code>None</code></td>
</tr>
<tr>
<td><code>bindingId</code></td>
<td><code>str | None</code></td>
<td><code>None</code></td>
</tr>
<tr>
<td><code>handler</code></td>
<td><code>collections.abc.Callable[..., Any] | None</code></td>
<td><code>None</code></td>
</tr>
<tr>
<td><code>approvalHandler</code></td>
<td><code>collections.abc.Callable[..., bool] | None</code></td>
<td><code>None</code></td>
</tr>
</tbody>
</table>

<p><strong>Returns:</strong> <code>None</code></p>

Language-neutral tool specification plus optional Python binding.

<span id="flowai_harness.tools.ToolSpec.bind"></span>

### `bind`

`bind(self, handler: 'Callable[..., Any]') -> 'ToolSpec'`

<table>
<thead>
<tr>
<th>Parameter</th>
<th>Type</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>handler</code></td>
<td><code>Callable[..., Any]</code></td>
<td>required</td>
</tr>
</tbody>
</table>

<p><strong>Returns:</strong> <code>ToolSpec</code></p>

Return a copy of this spec with a Python handler attached.

<span id="flowai_harness.tools.ToolSpec.__call__"></span>

### `__call__`

`__call__(self, handler: 'Callable[..., Any]') -> 'ToolSpec'`

<table>
<thead>
<tr>
<th>Parameter</th>
<th>Type</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>handler</code></td>
<td><code>Callable[..., Any]</code></td>
<td>required</td>
</tr>
</tbody>
</table>

<p><strong>Returns:</strong> <code>ToolSpec</code></p>
