LlamaIndex (v1.0.0)
toolbox_llamaindex.client
ToolboxClient Objects
class ToolboxClient()
__init__
def __init__(url: str,
client_headers: Optional[Mapping[str,
Union[Callable[[], str],
Callable[[],
Awaitable[str]],
str]]] = None,
protocol: Protocol = Protocol.MCP,
telemetry_enabled: bool = False) -> None
Initializes the ToolboxClient for the Toolbox service at the given URL.
Arguments:
url- The base URL of the Toolbox service.telemetry_enabled- Whether to enable OpenTelemetry tracing and metrics. (Default: False)
aload_tool
async def aload_tool(
tool_name: str,
auth_token_getters: dict[str, Callable[[], str]] = {},
auth_tokens: Optional[dict[str, Callable[[], str]]] = None,
auth_headers: Optional[dict[str, Callable[[], str]]] = None,
bound_params: dict[str, Union[Any, Callable[[],
Any]]] = {}) -> ToolboxTool
Loads the tool with the given tool name from the Toolbox service.
Arguments:
tool_name- The name of the tool to load.auth_token_getters- An optional mapping of authentication source names to functions that retrieve ID tokens.auth_tokens- Deprecated. Useauth_token_gettersinstead.auth_headers- Deprecated. Useauth_token_gettersinstead.bound_params- An optional mapping of parameter names to their bound values.
Returns:
A tool loaded from the Toolbox.
aload_toolset
async def aload_toolset(toolset_name: Optional[str] = None,
auth_token_getters: dict[str, Callable[[], str]] = {},
auth_tokens: Optional[dict[str, Callable[[],
str]]] = None,
auth_headers: Optional[dict[str,
Callable[[], str]]] = None,
bound_params: dict[str, Union[Any,
Callable[[], Any]]] = {},
strict: bool = False) -> list[ToolboxTool]
Loads tools from the Toolbox service, optionally filtered by toolset name.
Arguments:
toolset_name- The name of the toolset to load. If not provided, all tools are loaded.auth_token_getters- An optional mapping of authentication source names to functions that retrieve ID tokens.auth_tokens- Deprecated. Useauth_token_gettersinstead.auth_headers- Deprecated. Useauth_token_gettersinstead.bound_params- An optional mapping of parameter names to their bound values.strict- If True, raises an error if any loaded tool instance fails to utilize at least one provided parameter or auth token (if any provided). If False (default), raises an error only if a user-provided parameter or auth token cannot be applied to any loaded tool across the set.
Returns:
A list of all tools loaded from the Toolbox.
load_tool
def load_tool(
tool_name: str,
auth_token_getters: dict[str, Callable[[], str]] = {},
auth_tokens: Optional[dict[str, Callable[[], str]]] = None,
auth_headers: Optional[dict[str, Callable[[], str]]] = None,
bound_params: dict[str, Union[Any, Callable[[],
Any]]] = {}) -> ToolboxTool
Loads the tool with the given tool name from the Toolbox service.
Arguments:
tool_name- The name of the tool to load.auth_token_getters- An optional mapping of authentication source names to functions that retrieve ID tokens.auth_tokens- Deprecated. Useauth_token_gettersinstead.auth_headers- Deprecated. Useauth_token_gettersinstead.bound_params- An optional mapping of parameter names to their bound values.
Returns:
A tool loaded from the Toolbox.
load_toolset
def load_toolset(toolset_name: Optional[str] = None,
auth_token_getters: dict[str, Callable[[], str]] = {},
auth_tokens: Optional[dict[str, Callable[[], str]]] = None,
auth_headers: Optional[dict[str, Callable[[], str]]] = None,
bound_params: dict[str, Union[Any, Callable[[], Any]]] = {},
strict: bool = False) -> list[ToolboxTool]
Loads tools from the Toolbox service, optionally filtered by toolset name.
Arguments:
toolset_name- The name of the toolset to load. If not provided, all tools are loaded.auth_token_getters- An optional mapping of authentication source names to functions that retrieve ID tokens.auth_tokens- Deprecated. Useauth_token_gettersinstead.auth_headers- Deprecated. Useauth_token_gettersinstead.bound_params- An optional mapping of parameter names to their bound values.strict- If True, raises an error if any loaded tool instance fails to utilize at least one provided parameter or auth token (if any provided). If False (default), raises an error only if a user-provided parameter or auth token cannot be applied to any loaded tool across the set.
Returns:
A list of all tools loaded from the Toolbox.
close
def close()
Close the underlying synchronous client.
__aenter__
async def __aenter__()
Enter the runtime context related to this client instance.
Allows the client to be used as an asynchronous context manager
(e.g., async with ToolboxClient(...) as client:).
Returns:
self- The client instance itself.
__aexit__
async def __aexit__(exc_type, exc_val, exc_tb)
Exit the runtime context and close the internally managed session.
Allows the client to be used as an asynchronous context manager
(e.g., async with ToolboxClient(...) as client:).
__enter__
def __enter__()
Enter the runtime context related to this client instance.
Allows the client to be used as a context manager
(e.g., with ToolboxClient(...) as client:).
Returns:
self- The client instance itself.
__exit__
def __exit__(exc_type, exc_val, exc_tb)
Exit the runtime context and close the internally managed session.
Allows the client to be used as a context manager
(e.g., with ToolboxClient(...) as client:).
toolbox_llamaindex.tools
ToolboxTool Objects
class ToolboxTool(AsyncBaseTool)
A subclass of LlamaIndex’s AsyncBaseTool that supports features specific to Toolbox, like bound parameters and authenticated tools.
__init__
def __init__(core_tool: ToolboxCoreSyncTool) -> None
Initializes a ToolboxTool instance.
Arguments:
core_tool- The underlying core sync ToolboxTool instance.
add_auth_token_getters
def add_auth_token_getters(
auth_token_getters: dict[str, Callable[[], str]]) -> "ToolboxTool"
Registers functions to retrieve ID tokens for the corresponding authentication sources.
Arguments:
auth_token_getters- A dictionary of authentication source names to the functions that return corresponding ID token.
Returns:
A new ToolboxTool instance that is a deep copy of the current instance, with added auth token getters.
Raises:
ValueError- If any of the provided auth parameters is already registered.
add_auth_token_getter
def add_auth_token_getter(auth_source: str,
get_id_token: Callable[[], str]) -> "ToolboxTool"
Registers a function to retrieve an ID token for a given authentication source.
Arguments:
auth_source- The name of the authentication source.get_id_token- A function that returns the ID token.
Returns:
A new ToolboxTool instance that is a deep copy of the current instance, with added auth token getter.
Raises:
ValueError- If the provided auth parameter is already registered.
bind_params
def bind_params(
bound_params: dict[str, Union[Any, Callable[[],
Any]]]) -> "ToolboxTool"
Registers values or functions to retrieve the value for the corresponding bound parameters.
Arguments:
bound_params- A dictionary of the bound parameter name to the value or function of the bound value.
Returns:
A new ToolboxTool instance that is a deep copy of the current instance, with added bound params.
Raises:
ValueError- If any of the provided bound params is already bound.
bind_param
def bind_param(param_name: str,
param_value: Union[Any, Callable[[], Any]]) -> "ToolboxTool"
Registers a value or a function to retrieve the value for a given bound parameter.
Arguments:
param_name- The name of the bound parameter.param_value- The value of the bound parameter, or a callable that returns the value.
Returns:
A new ToolboxTool instance that is a deep copy of the current instance, with added bound param.
Raises:
ValueError- If the provided bound param is already bound.
toolbox_llamaindex.async_client
AsyncToolboxClient Objects
class AsyncToolboxClient()
__init__
def __init__(url: str,
session: ClientSession,
client_headers: Optional[Mapping[str,
Union[Callable[[], str],
Callable[[],
Awaitable[str]],
str]]] = None,
protocol: Protocol = Protocol.MCP,
telemetry_enabled: bool = False)
Initializes the AsyncToolboxClient for the Toolbox service at the given URL.
Arguments:
url- The base URL of the Toolbox service.session- An HTTP client session.telemetry_enabled- Whether to enable OpenTelemetry tracing and metrics. (Default: False)
aload_tool
async def aload_tool(
tool_name: str,
auth_token_getters: dict[str, Callable[[], str]] = {},
auth_tokens: Optional[dict[str, Callable[[], str]]] = None,
auth_headers: Optional[dict[str, Callable[[], str]]] = None,
bound_params: dict[str, Union[Any, Callable[[], Any]]] = {}
) -> AsyncToolboxTool
Loads the tool with the given tool name from the Toolbox service.
Arguments:
tool_name- The name of the tool to load.auth_token_getters- An optional mapping of authentication source names to functions that retrieve ID tokens.auth_tokens- Deprecated. Useauth_token_gettersinstead.auth_headers- Deprecated. Useauth_token_gettersinstead.bound_params- An optional mapping of parameter names to their bound values.
Returns:
A tool loaded from the Toolbox.
aload_toolset
async def aload_toolset(toolset_name: Optional[str] = None,
auth_token_getters: dict[str, Callable[[], str]] = {},
auth_tokens: Optional[dict[str, Callable[[],
str]]] = None,
auth_headers: Optional[dict[str,
Callable[[], str]]] = None,
bound_params: dict[str, Union[Any,
Callable[[], Any]]] = {},
strict: bool = False) -> list[AsyncToolboxTool]
Loads tools from the Toolbox service, optionally filtered by toolset name.
Arguments:
toolset_name- The name of the toolset to load. If not provided, all tools are loaded.auth_token_getters- An optional mapping of authentication source names to functions that retrieve ID tokens.auth_tokens- Deprecated. Useauth_token_gettersinstead.auth_headers- Deprecated. Useauth_token_gettersinstead.bound_params- An optional mapping of parameter names to their bound values.strict- If True, raises an error if any loaded tool instance fails to utilize at least one provided parameter or auth token (if any provided). If False (default), raises an error only if a user-provided parameter or auth token cannot be applied to any loaded tool across the set.
Returns:
A list of all tools loaded from the Toolbox.
close
async def close()
Close the underlying synchronous client.
__aenter__
async def __aenter__()
Enter the runtime context related to this client instance.
Allows the client to be used as an asynchronous context manager
(e.g., async with AsyncToolboxClient(...) as client:).
Returns:
self- The client instance itself.
__aexit__
async def __aexit__(exc_type, exc_val, exc_tb)
Exit the runtime context and close the internally managed session.
Allows the client to be used as an asynchronous context manager
(e.g., async with AsyncToolboxClient(...) as client:).
toolbox_llamaindex.async_tools
AsyncToolboxTool Objects
class AsyncToolboxTool(AsyncBaseTool)
A subclass of LlamaIndex’s AsyncBaseTool that supports features specific to Toolbox, like bound parameters and authenticated tools.
__init__
def __init__(core_tool: ToolboxCoreTool) -> None
Initializes an AsyncToolboxTool instance.
Arguments:
core_tool- The underlying core async ToolboxTool instance.
acall
async def acall(**kwargs: Any) -> ToolOutput
The coroutine that invokes the tool with the given arguments.
Arguments:
**kwargs- The arguments to the tool.
Returns:
A dictionary containing the parsed JSON response from the tool invocation.
add_auth_token_getters
def add_auth_token_getters(
auth_token_getters: dict[str, Callable[[],
str]]) -> "AsyncToolboxTool"
Registers functions to retrieve ID tokens for the corresponding authentication sources.
Arguments:
auth_token_getters- A dictionary of authentication source names to the functions that return corresponding ID token getters.
Returns:
A new AsyncToolboxTool instance that is a deep copy of the current instance, with added auth token getters.
Raises:
ValueError- If any of the provided auth parameters is already registered.
add_auth_token_getter
def add_auth_token_getter(
auth_source: str, get_id_token: Callable[[],
str]) -> "AsyncToolboxTool"
Registers a function to retrieve an ID token for a given authentication source.
Arguments:
auth_source- The name of the authentication source.get_id_token- A function that returns the ID token.
Returns:
A new ToolboxTool instance that is a deep copy of the current instance, with added auth token getter.
Raises:
ValueError- If the provided auth parameter is already registered.
bind_params
def bind_params(
bound_params: dict[str, Union[Any, Callable[[],
Any]]]) -> "AsyncToolboxTool"
Registers values or functions to retrieve the value for the corresponding bound parameters.
Arguments:
bound_params- A dictionary of the bound parameter name to the value or function of the bound value.
Returns:
A new AsyncToolboxTool instance that is a deep copy of the current instance, with added bound params.
Raises:
ValueError- If any of the provided bound params is already bound.
bind_param
def bind_param(
param_name: str,
param_value: Union[Any, Callable[[], Any]]) -> "AsyncToolboxTool"
Registers a value or a function to retrieve the value for a given bound parameter.
Arguments:
param_name- The name of the bound parameter.param_value- The value of the bound parameter, or a callable that returns the value.
Returns:
A new ToolboxTool instance that is a deep copy of the current instance, with added bound param.
Raises:
ValueError- If the provided bound param is already bound.