Skip to content

Add an external tool

Tools are what turn an agent from a chatbot into a system that does work. This guide explains how to connect an agent to an external capability while keeping the integration governed and observable.

PatternUse when
Built-in providerThe system you need is already supported by the runtime.
MCP serverYou want a standard, reusable tool server that multiple agents can share.
Llama Stack tool groupYou are standardizing on Llama Stack in your environment.
A2A agentThe capability is itself another Alquimia Platform agent.
Custom Python moduleYou need business-specific logic that lives inside the runtime.

Before integrating, define the contract clearly:

  • What does the tool do in one sentence?
  • What are its inputs, outputs, and error conditions?
  • Does it have side effects? Can it be retried safely?
  • What data will it expose to the LLM?
  • Who can invoke it, and under what conditions?

A clear contract makes the tool easier for the agent to choose correctly and easier for you to audit later.

  1. Store any credentials the tool needs as registry secrets.

  2. Add the tool configuration to the agent spec, choosing the appropriate adapter and pointing to the tool endpoint or module.

    For MCP stdio transport, the worker must be allowed to spawn the subprocess. Set ALQUIMIA_MCP_STDIO_ALLOWED=true and, preferably, narrow the allowed commands with ALQUIMIA_MCP_STDIO_ALLOWLIST. In production, run stdio servers as sidecars or separate services and connect over HTTP instead.

  3. Describe the tool well. The agent selects tools based on name and description, so be explicit about inputs, outputs, and side effects.

  4. Test in isolation with a sample prompt that should trigger the tool. Check the worklog for the exact input sent and output returned.

  5. Add governance controls such as shields, role restrictions, or approval gates before exposing the tool to real users.

Not every tool should run automatically. Consider:

  • Role tier — limit sensitive tools to agents with an operator role.
  • Approval gate — require human confirmation before destructive or financial actions.
  • Shield checks — block or flag requests that look like prompt injection or policy violations.
  • Rate limiting — prevent runaway loops or excessive calls to expensive APIs.

Classify operations for Zero Trust authorization

Section titled “Classify operations for Zero Trust authorization”

In production, Alquimia Platform uses a DefaultToolAuthzPolicy(default_deny=True). An unclassified tool denies every operation, so each tool must declare what it can do and who may invoke it.

Classify operations with the CLI:

Terminal window
alquimia registry tools set-operation filesystem-tools "read_*" \
--match glob --severity read-only --tier-grants reader,editor,operator
alquimia registry tools set-operation filesystem-tools "delete_*" \
--match glob --severity destructive --tier-grants operator \
--approval-required

Severity acts as a tier floor:

SeverityMax grantable tier
read-onlyreader, editor, operator
mutating-recoverableeditor, operator
destructiveoperator only

The runtime resolves the most specific matching operation, then checks whether the agent’s role is in tier_grants and not excluded by severity. An agent can further narrow its own access with tier_ceiling in the agent spec, but it can never widen access beyond the registry grants.

Inspect what a tool can do at runtime:

Terminal window
alquimia registry tools inspect filesystem-tools --for-tool "read_file"

Client-managed tools (provider_id: "client") let a caller supply the schema while the runtime governs and audits execution. Register the curated schema, then classify each operation so the controller can enforce role tiers and approvals:

Terminal window
cat > client-tools.json <<'EOF'
[
{
"title": "get_cart",
"description": "Return the caller's shopping cart contents",
"type": "object",
"properties": {},
"required": []
}
]
EOF
alquimia registry tools add sales-tools \
--provider-id client \
--tool-schemas @client-tools.json \
--description "Caller-provided sales actions"
alquimia registry tools set-operation sales-tools "get_cart" \
--match exact --severity read-only --tier-grants reader,editor,operator

When a request includes a matching registered client tool, the runtime strips the request-supplied schema and routes execution through the dedicated ClientToolExecution path, preventing schema collisions.

Every tool invocation is recorded in the worklog with the input, output, error, and latency. Use this to detect drift, audit access, and tune tool descriptions when the agent chooses poorly.