dragon.ai.agent.tools.function_tool.FunctionTool
- class FunctionTool[source]
Bases:
BaseToolWrap 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: descriptionformat (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)
Methods
__init__(fn[, name, description])run(input)Call the wrapped function with
inputas keyword arguments.Build an OpenAI-compatible schema from type hints and signature.
Attributes