ToolData
The ToolData class is the data model for registering Tools.
Properties
data(ToolFunctionSchema): Tool metadata (function definition, type, strict mode)func: The tool function. EitherCallable[[dict[str, Any]], Awaitable[str]]orCallable[[ToolContext], Awaitable[str | None]]custom_run(bool): DefaultFalse. Whether to customize execution; if enabled, passes Context class instead of dict and does not enforce a return valueenable_if(Callable[[], bool]): Defaultlambda: True. Whether to enable this toolconcurrency_safe(bool | Callable[[dict[str, Any]], bool]): DefaultTrue. Whether calls of this tool may overlap sibling calls of the same tool round. A callable decides per call from the parsed arguments and must return a literalTrue; a raised exception counts as unsafe.
Methods
is_concurrency_safe(arguments): Resolve the flag for one call. Aboolis returned as is, a callable is invoked with the arguments; an exception or any return value other than a literalTrueis unsafe, so an undeclared, mis-declared or failing classifier isolates the call instead of letting it race.
Description
The ToolData class inherits from BaseModel and wraps a tool's metadata together with its implementation function. It is the unit registered in MultiToolsManager and queried via get_tool(name).
Example
python
from amrita_core.tools.models import (
ToolData,
ToolFunctionSchema,
FunctionDefinitionSchema,
)
tool_data = ToolData(
data=ToolFunctionSchema(
function=FunctionDefinitionSchema(
name="get_weather",
description="Get weather for a city",
parameters={"type": "object", "properties": {"city": {"type": "string"}}},
)
),
func=my_async_weather_func,
concurrency_safe=False,
)