dragon.ai.agent.tools.registry.ToolRegistry

class ToolRegistry[source]

Bases: object

Registry of BaseTool instances available to an agent.

Usage:

registry = ToolRegistry()
registry.register(MyTool())
tool = registry.get("my_tool")
schemas = registry.list_tools()   # OpenAI-compatible function schemas
__init__() None [source]

Methods

__init__()

get(name)

Return the tool registered under name.

has(name)

Return True if a tool with name is registered.

list_tools()

Return a list of OpenAI-compatible tool/function schemas.

register(tool)

Register a tool.

tool(fn)

Decorator that wraps fn as a FunctionTool and registers it.

tool_names()

Return sorted list of registered tool names.

unregister(name)

Remove a tool by name.

__init__() None [source]
register(tool: BaseTool | Callable ) None [source]

Register a tool.

tool can be a BaseTool instance or a plain callable (sync or async). Callables are automatically wrapped in FunctionTool.

Overwrites any existing tool with the same name.

unregister(name: str ) None [source]

Remove a tool by name. No-op if not present.

get(name: str ) BaseTool[source]

Return the tool registered under name.

Raises

KeyError

If no tool with that name is registered.

has(name: str ) bool [source]

Return True if a tool with name is registered.

list_tools() list [dict [str , Any ]][source]

Return a list of OpenAI-compatible tool/function schemas.

These schemas are injected into the LLM system prompt so the model can decide which tools to call.

tool_names() list [str ][source]

Return sorted list of registered tool names.

__len__() int [source]
tool(fn: Callable) FunctionTool[source]

Decorator that wraps fn as a FunctionTool and registers it.

Works with both sync and async functions:

registry = ToolRegistry()

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

@registry.tool
async def fetch_data(url: str) -> dict:
    """Fetch data from a URL."""
    return await do_fetch(url)
Returns:

The created FunctionTool instance.