Skip to main content

Tool Authoring

Tools are the primary way agents access external capabilities — databases, APIs, file storage, computation environments. Getting tools right is critical: poorly specified tools are the leading cause of agent errors, context bloat, and cost overruns.

Function Tools

Function tools are Python functions that the LLM can call directly. Every supported framework converts them to the appropriate wire format for the underlying model.

Writing a Good Tool

A well-authored function tool has four properties:
  1. A descriptive docstring — the LLM reads this to decide when to call the tool
  2. Typed parameters — every parameter has an explicit type annotation and docstring description
  3. A bounded return type — string, dict, or a typed Pydantic model; never untyped or variable-shape
  4. Minimal side effects — each call does one thing; avoid tools that “do everything”

Schema Discipline

The tool’s parameter schema is sent to the LLM on every call. Verbose or inaccurate schemas degrade routing quality and inflate cost.
Prefer Literal["postgres", "redshift", "bigquery"] over str when the set of valid values is known. The LLM will hallucinate less when the schema constrains choices.
Use Optional[T] with a sensible default. Never use Union[T, None] without a default — the LLM will try to supply a value when it shouldn’t.
Raise only for truly unrecoverable situations. For expected failures (table not found, invalid SQL), return a structured error dict so the LLM can understand and recover.

MCP Tools via FastMCPToolset

CRAFT exposes platform capabilities through em-runtime-mcp — an MCP server. Pydantic AI connects to it via FastMCPToolset; Google ADK can connect via a MCPToolset wrapper.

Pydantic AI — FastMCPToolset

A production-grade pattern for connecting a Pydantic AI agent to the CRAFT MCP server:

Google ADK — MCP Tool Integration

Google ADK connects to the CRAFT MCP server using StreamableHTTPConnectionParams:
The older import from google.adk.toolsets.mcp import MCPToolset is deprecated. Use from google.adk.tools.mcp_tool import MCPToolset, StreamableHTTPConnectionParams (ADK v1.0+).

Claude Agent SDK — MCP Tool Integration

The Anthropic API’s mcp_servers connector only supports authorization_token — it cannot pass X-Project-ID as a separate header. Use the mcp Python SDK with a session-aware client to call CRAFT tools from a standard function-tool loop:

LangGraph — MCP Tool Integration

LangGraph connects to CRAFT via MultiServerMCPClient from langchain-mcp-adapters (install: pip install langchain-mcp-adapters):
langchain-mcp-adapters supports headers for static auth values. If the access token expires mid-session, reinitialise the client — dynamic per-request token injection is a known limitation.

Cross-Framework Tool Comparison

FeatureGoogle ADKClaude Agent SDKPydantic AILangGraph
Function toolstools=[my_fn]tools=[{name, description, input_schema}]@agent.tool decorator or tools=[my_fn]bind_tools([my_fn])
CRAFT MCP connectionMCPToolset + StreamableHTTPConnectionParamsmcp SDK streamablehttp_client + function toolsFastMCPToolset + StreamableHttpTransport (first-class)MultiServerMCPClient (transport="http")
Parallel tool callsYes (automatic)Yes (with betas=["interleaved-thinking"])parallel_tool_calls=True in ModelSettingsNode-level parallelism
Tool retry on failureADK handles automaticallyManual in tool loopModelRetry exceptionConditional edges
Context injectionToolContextManual in tool dispatchRunContext[Deps]RunnableConfig

Limiting Iteration and Cost

Unbounded tool call loops are the leading cause of cost overruns. Implement iteration limits defensively.
Return structured error dicts (not raise ModelRetry) when you have hit an iteration limit. ModelRetry with the default max_retries=1 already consumed will raise UnexpectedModelBehavior and produce a generic failure message instead of the clarifying ask you wanted the model to emit.

Pre-Flight Validation

Validate tool inputs before making expensive network calls. A FastMCPToolset subclass can run a lint pass before code execution:

Next Steps

Multi-Agent Patterns

Use tools and sub-agents together in orchestrated workflows.

Debugging Agents

Inspect tool call traces and diagnose tool failures.