Skip to content

Tools Reference

The unified container for callable tools and their JSON-schema specifications.

@dataclass(slots=True)
class ToolBank:
functions: dict[str, Callable[..., Any]]
schema: list[ToolSchema]
async def execute(
self,
name: str,
parameters: dict[str, Any] | None = None,
context: dict[str, Any] | None = None,
) -> Any: ...

Load tools from a Python module. Functions are discovered via inspect.getmembers. Docstrings are parsed with numpydoc to generate JSON schemas.

bank = ToolBank.from_module("my_tools.search")

Requires the [tools] extra: pip install alquimia-core[tools].

Load tools from an MCP server.

bank = await ToolBank.from_mcp({
"url": "http://my-mcp-server:8000",
"auth": "Bearer my-token",
})

Load tools from a Llama Stack instance.

bank = await ToolBank.from_llama_stack({
"tool_group_id": "my-tools",
})

Execute a tool by name.

result = await bank.execute(
"search_web",
parameters={"query": "capital of France"},
context={"user_id": "user-1"},
)

Raises ToolsUnknownName if the tool is not in the bank.


ToolConfig is a discriminated union on provider_id:

ToolConfig = Annotated[
MCPToolConfig | LlamaStackToolConfig | A2AConfig,
Field(discriminator="provider_id"),
]

class MCPToolConfig(BaseToolConfig):
provider_id: Literal["mcp"] = "mcp"
url: str | SecretRef | None = None
auth: str | SecretRef | None = None
args: list[SecretStr] | None = None
env: dict[str, SecretStr] | None = None
headers: dict[str, SecretStr] | None = None
command: str | None = None
transport: str | None = None
FieldTypeDescription
provider_id"mcp"Required
urlstring | SecretRefMCP server URL (HTTP transport)
authstring | SecretRefBearer token or auth method
commandstringCommand to launch (stdio transport)
argsstring[]Arguments for the command
envdict[str, string]Environment variables
headersdict[str, string]Additional HTTP headers
transportstringTransport type
human_approval"NONE" | "LAZY" | "REQUIRED"Approval requirement

class LlamaStackToolConfig(BaseToolConfig):
provider_id: Literal["llama-stack"] = "llama-stack"
tool_group_id: str | None = None
authorization: str | SecretRef | None = None
extra_headers: dict[str, SecretStr] | None = None
FieldTypeDescription
provider_id"llama-stack"Required
tool_group_idstringFilter tools by group
authorizationstring | SecretRefProvider authorization header
extra_headersdict[str, string]Additional headers

Environment variables used by Llama Stack:

VariableDescription
LLAMA_STACK_BASE_URLLlama Stack server URL
LLAMA_STACK_API_KEYAPI key
LLAMA_STACK_TIMEOUTRequest timeout
LLAMA_STACK_MAX_RETRIESMax retries (default: 3)

class A2AConfig(BaseToolConfig):
provider_id: Literal["a2a"] = "a2a"
context: dict[str, Any] | None = None
selector: dict[str, Any]
FieldTypeDescription
provider_id"a2a"Required
selectordictTinyDB-style filter to find agents
contextdictExtra context passed to discovered agents

Represents an agent exposed as a tool:

class A2ASchema(BaseModel):
assistant_id: str
nickname: str
description: str
@property
def as_toolname(self) -> str: ... # "agent_{nickname}"
def to_spec(self) -> ToolSchema: ...

The input schema for A2A tool calls:

FieldTypeDescription
querystringThe full task to send to the other agent
hands_offboolIf true, the other agent responds directly to the user

The JSON schema representation of a tool:

class ToolSchema(BaseModel):
name: str # serialized as "title"
description: str | None = ""
type: str | None = None
properties: dict[str, Any] | None = None
required: list[str] | None = None
parameters: dict[str, Any] | None = None

When an MCP tool requires fields that are not in the call parameters, the elicitation handler automatically fills them from runtime_context:

async def elicitation_handler(
runtime_context: dict[str, Any],
message: str,
response_type: type,
params: Any,
context: dict[str, Any],
) -> ElicitResult | dict[str, Any]: ...

If a required field cannot be found in runtime_context, the handler returns ElicitResult(action="cancel") to abort the tool call.


VariableDefaultDescription
TOOLS_BANK_BASE_MODULE"tools"Python module path for built-in tools
ALQUIMIA_A2A_TOOLNAME_PREFIX"agent-"Prefix for A2A tool names
LLAMA_STACK_BASE_URLLlama Stack server URL
LLAMA_STACK_API_KEYLlama Stack API key
LLAMA_STACK_TIMEOUTRequest timeout
LLAMA_STACK_MAX_RETRIES3Max retries