dragon.ai.agent.tools.function_tool.FunctionTool

class FunctionTool[source]

Bases: BaseTool

Wrap any plain Python callable as a BaseTool.

The tool name, description, and parameter schema are derived automatically from the function’s __name__, __doc__, and type annotations — no manual schema writing required.

Parameter descriptions are extracted from the docstring when written in :param name: description format (Sphinx-style).

Parameters

fn:

The callable to wrap.

name:

Override the tool name (defaults to fn.__name__).

description:

Override the description (defaults to the first line of fn.__doc__, or the function name if no docstring).

Example

def calculate_magic_addition(a: int, b: int) -> int:
    """Add two numbers with a magic twist."""
    return a + b + 5

registry = ToolRegistry()
registry.register(calculate_magic_addition)

Or using the decorator shortcut:

@registry.tool
def calculate_magic_addition(a: int, b: int) -> int:
    """Add two numbers with a magic twist."""
    return a + b + 5

Async functions work identically:

@registry.tool
async def fetch_data(url: str) -> dict:
    """Fetch data from a URL."""
    return await do_fetch(url)
__init__(fn: Callable , name: str | None = None, description: str | None = None) None [source]

Methods

__init__(fn[, name, description])

run(input)

Call the wrapped function with input as keyword arguments.

to_schema()

Build an OpenAI-compatible schema from type hints and signature.

Attributes

name

description

__init__(fn: Callable , name: str | None = None, description: str | None = None) None [source]
name: str
description: str
run(input: dict [str , Any ]) Any [source]

Call the wrapped function with input as keyword arguments.

to_schema() dict [str , Any ][source]

Build an OpenAI-compatible schema from type hints and signature.