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

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 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.

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. Args:

property yaml_definitions: List[str]#
property json_definitions: List[str]#
property function_definitions: List[FunctionDefinition]#
parse_func_expr(expr: FunctionExpression) Function[source]#

Parse the function call expression.

execute_func(func: Function) FunctionOutput[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: FunctionExpression) FunctionOutput[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.