tool_manager

The ToolManager manages a list of tools, context, and all ways to execute functions.

Functions

run_async_in_new_loop(coro)

Run async function in a new event loop.

Classes

CallFunctionTool()

Contains other unit gradcomponent such as calling a FunctionTool

FunctionExperssionToFunction()

ToolManager([tools, additional_context])

"Manage a list of tools, context, and all ways to execute functions.

run_async_in_new_loop(coro)[source]

Run async function in a new event loop.

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 FunctionExperssionToFunction[source]

Bases: GradComponent

call(expr: FunctionExpression, context: Dict[str, object]) Function[source]

User must override this for the inference scenario if bicall is not defined.

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.

static get_context_index(tool: FunctionTool) Dict[str, object][source]
static create_context_map_from_tools(tools: List[FunctionTool]) Dict[str, object][source]
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.

execute_func_expr_via_sandbox(expr: FunctionExpression) FunctionOutput[source]

Execute the function expression via sandbox. Only support sync functions.

execute_func_expr_via_eval(expr: FunctionExpression) FunctionOutput[source]

Execute the function expression via eval. Only support sync functions.