---
sidebar:
  hidden: true
title: roboto.ai.agent_thread.client_tool
---
## Module Contents

### ClientTool

```python
class roboto.ai.agent_thread.client_tool.ClientTool(
    fn: collections.abc.Callable[..., Any],
    *,
    name: str,
    description: str,
    input_schema: dict[str, Any],
)
```

`from roboto import ClientTool`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/ai/agent_thread/client_tool.py#L21-L147)

A client tool together with the Python function that runs it when Roboto's AI requests the tool.

Pass client tools to [`start()`](/docs/reference/python-sdk/roboto/ai/agent_thread/agent_thread#roboto.ai.agent_thread.agent_thread.AgentThread.start) or [`send()`](/docs/reference/python-sdk/roboto/ai/agent_thread/agent_thread#roboto.ai.agent_thread.agent_thread.AgentThread.send) as `client_tools`, or add one to a thread with [`register_client_tool()`](/docs/reference/python-sdk/roboto/ai/agent_thread/agent_thread#roboto.ai.agent_thread.agent_thread.AgentThread.register_client_tool). When the AI requests the tool, [`run()`](/docs/reference/python-sdk/roboto/ai/agent_thread/agent_thread#roboto.ai.agent_thread.agent_thread.AgentThread.run) calls the function with the AI's input as keyword arguments and submits what it returns: a dictionary as it is, `None` as an empty dictionary, and any other value as `{"result": <value>}`. If the function raises an exception, `run` submits the exception's type and message as an error result instead.

Most callers build a client tool with `client_tool` or `from_function`, which infer the input schema from the function's type hints and docstring. A tool's name must match `^client_[a-z][a-z0-9_]*$`, so name the function `client_<name>` or pass `name`.

**Parameters**

- **fn** (`collections.abc.Callable[..., Any]`): Function to call when the AI requests the tool.
- **name** (`str`): Name of the tool, which the AI uses to request it.
- **description** (`str`): Human-readable description of what the tool does, which the AI reads to decide when to use it.
- **input_schema** (`dict[str, Any]`): JSON Schema of the tool's input.

**Raises**

- `pydantic.ValidationError`: `name` does not match `^client_[a-z][a-z0-9_]*$`.

**Properties**

- **ClientTool.name** (`str`): Name of the tool, which the AI uses to request it.

  See [`name`](/docs/reference/python-sdk/roboto/ai/core/record#roboto.ai.core.record.ClientToolSpec.name) for the form a name must take.

- **ClientTool.spec** (`roboto.ai.agent_thread.record.ClientToolSpec`): Specification of the tool, which the SDK sends to Roboto so that Roboto offers the tool to the AI.

#### ClientTool.from_function()

```python
@classmethod
def from_function(
    fn: collections.abc.Callable[..., Any],
    *,
    name: Optional[str] = None,
    description: Optional[str] = None,
    input_schema: Optional[dict[str, Any]] = None,
) -> ClientTool
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/ai/agent_thread/client_tool.py#L62-L130)

Build a client tool from a Python function.

Each parameter of `fn` becomes a property of the inferred input schema. Its description comes from the `Args:` section of `fn`'s docstring, unless the parameter's type hint is `typing.Annotated[T, pydantic.Field(description="...")]` or its default is `pydantic.Field(description="...")`, which take precedence. Only a section headed `Args:` is read.

**Parameters**

- **fn** (`collections.abc.Callable[..., Any]`): Function to call when the AI requests the tool.
- **name** (`Optional[str]`): Name of the tool, which the AI uses to request it. `None` uses `fn.__name__`.
- **description** (`Optional[str]`): Human-readable description of what the tool does, which the AI reads to decide when to use it. `None` uses `fn`'s docstring up to its first section header, such as `Args:`.
- **input_schema** (`Optional[dict[str, Any]]`): JSON Schema of the tool's input. `None` infers it from `fn`'s signature, type hints, and docstring.

**Raises**

- `ValueError`: The description is empty, because `description` is empty or is `None` and `fn` has no docstring text before its first section header; or `input_schema` is `None` and `fn` takes `*args` or `**kwargs`.
- `pydantic.ValidationError`: The tool's name does not match `^client_[a-z][a-z0-9_]*$`.
- `pydantic.errors.PydanticSchemaGenerationError`: `input_schema` is `None` and a parameter's type hint has no JSON Schema form, such as a class that is not a pydantic model or dataclass.

**Returns**

- `ClientTool`

**Usage**

Take the parameter's description from `Annotated` instead of the docstring:

```python
from typing import Annotated
from pydantic import Field
def client_recall(
    query: Annotated[str, Field(description="Substring to search for.")],
) -> str:
    """Search long-term memory."""
    ...
tool = ClientTool.from_function(client_recall)
```

Set the name and description explicitly:

```python
def store(fact: str) -> str: ...
tool = ClientTool.from_function(
    store,
    name="client_store_fact",
    description="Store a fact in long-term memory.",
)
tool.name
# 'client_store_fact'
```

### client_tool()

```python
def roboto.ai.agent_thread.client_tool.client_tool(fn: collections.abc.Callable[..., Any], /) -> ClientTool
def roboto.ai.agent_thread.client_tool.client_tool(*, name: str | None = None, description: str | None = None, input_schema: dict[str, Any] | None = None) -> collections.abc.Callable[[collections.abc.Callable[..., Any]], ClientTool]
```

`from roboto import client_tool`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/ai/agent_thread/client_tool.py#L154-L154)

Build a `ClientTool` from a function, as a decorator or a direct call.

Use it bare (`@client_tool`) to infer the tool's name, description, and input schema from the function, or with keyword arguments (`@client_tool(name="...")`) to set some of them. Either way, the decorated name holds the `ClientTool`. `ClientTool.from_function` builds the tool and says how each value is inferred; the exceptions it lists also apply, raised when the decorator is applied to the function.

**Parameters**

- **fn**: Function to build the tool from. `None` returns a decorator that takes it.
- **name**: Name of the tool, which the AI uses to request it. `None` uses the function's name.
- **description**: Human-readable description of what the tool does, which the AI reads to decide when to use it. `None` uses the function's docstring up to its first section header, such as `Args:`.
- **input_schema**: JSON Schema of the tool's input. `None` infers it from the function's signature, type hints, and docstring.

**Returns**

- The client tool, or, when `fn` is `None`, a decorator that builds one from the function it decorates.

**Usage**

Infer everything from the function, including each parameter's description from its docstring's `Args:` section:

```python
@client_tool
def client_remember(fact: str) -> str:
    """Store a fact in long-term memory.

    Args:
        fact: A standalone sentence worth remembering.
    """
    ...
```

Set the name and description explicitly:

```python
@client_tool(name="client_store_fact", description="Persist a fact.")
def store(fact: str) -> str: ...
store.name
# 'client_store_fact'
```
