dragon.ai.agent.tools.registry.ToolRegistry
- class ToolRegistry[source]
Bases:
objectRegistry of
BaseToolinstances available to an agent.Usage:
registry = ToolRegistry() registry.register(MyTool()) tool = registry.get("my_tool") schemas = registry.list_tools() # OpenAI-compatible function schemas
Methods
__init__()get(name)Return the tool registered under name.
has(name)Return
Trueif a tool with name is registered.Return a list of OpenAI-compatible tool/function schemas.
register(tool)Register a tool.
tool(fn)Decorator that wraps fn as a
FunctionTooland registers it.Return sorted list of registered tool names.
unregister(name)Remove a tool by name.
- register(tool: BaseTool | Callable ) None [source]
Register a tool.
tool can be a
BaseToolinstance or a plain callable (sync or async). Callables are automatically wrapped inFunctionTool.Overwrites any existing tool with the same name.
- get(name: str ) BaseTool[source]
Return the tool registered under name.
Raises
- KeyError
If no tool with that 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(fn: Callable) FunctionTool[source]
Decorator that wraps fn as a
FunctionTooland 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
FunctionToolinstance.