tool_manager¶
The ToolManager manages a list of tools, context, and all ways to execute functions.
Functions
|
Run async function in a new event loop. |
Classes
Contains other unit gradcomponent such as calling a FunctionTool |
|
|
"Manage a list of tools, context, and all ways to execute functions. |
- class CallFunctionTool[source]¶
Bases:
Component
Contains other unit gradcomponent such as calling a FunctionTool
- forward(func: Parameter, context: Dict[str, object])[source]¶
User must override this for the training scenario if bicall is not defined.
- call(func: Function, context: Dict[str, object]) FunctionOutput [source]¶
User must override this for the inference scenario if bicall is not defined.
- bicall(func: Function | Parameter, context: Dict[str, object] = {})[source]¶
If the user provides a bicall method, then __call__ will automatically dispatch here for both training and inference scenarios. This can internally decide how to handle training vs. inference, or just produce a single unified output type.
- class ToolManager(tools: List[FunctionTool | Callable[[...], Any] | Awaitable[Callable[[...], Any]]] = [], additional_context: Dict[str, object] | None = {})[source]¶
Bases:
Component
“Manage a list of tools, context, and all ways to execute functions.
ToolManager is a task component that does not need its own backward function.
yaml and json definitions are for quick access to the definitions of the tools. If you need more specification, such as using exclude field, you can use the function_definitions.
- property yaml_definitions: List[str]¶
- property json_definitions: List[str]¶
- property function_definitions: List[FunctionDefinition]¶
- parse_func_expr(expr: ~adalflow.core.types.FunctionExpression | ~adalflow.optim.parameter.Parameter, map_fn: ~typing.Callable = <function ToolManager.<lambda>>) Function | Parameter [source]¶
Parse the function call expression.
- call(*, expr_or_fun: FunctionExpression, step: Literal['parse'] = 'parse') Function [source]¶
- call(*, expr_or_fun: FunctionExpression, step: Literal['execute'] = 'execute') FunctionOutput
- call(*, expr_or_fun: Function, step: Literal['execute'] = 'parse') Function
- call(*, expr_or_fun: Function, step: Literal['execute'] = 'execute') FunctionOutput
User must override this for the inference scenario if bicall is not defined.
- forward(*, expr_or_fun: ~adalflow.core.types.FunctionExpression | ~adalflow.core.types.Function | ~adalflow.optim.parameter.Parameter, step: ~typing.Literal['parse', 'execute'] = 'execute', map_fn: ~typing.Callable = <function ToolManager.<lambda>>) FunctionOutput | Function | Parameter [source]¶
Run a forward pass on the tool manager such as parsing function expression or executing function.
- execute_func(func: ~adalflow.core.types.Function | ~adalflow.optim.parameter.Parameter, map_fn: ~typing.Callable = <function ToolManager.<lambda>>) FunctionOutput | Parameter [source]¶
Execute the function. If the function is async, use asyncio.run to execute it.
- async execute_func_async(func: Function) FunctionOutput [source]¶
Execute the function. If the function is sync, use await to execute it.
- execute_func_expr(expr: ~adalflow.core.types.FunctionExpression | ~adalflow.optim.parameter.Parameter, map_fn: ~typing.Callable = <function ToolManager.<lambda>>) FunctionOutput | Parameter [source]¶
Execute the function expression. Support both sync and async functions.
- async execute_func_expr_async(expr: FunctionExpression) FunctionOutput [source]¶
Execute the function expression. Support both sync and async functions.