AI Agent Tool Design: Writing Tools Your Agent Can Actually Call

AI agent tool design is a contract between code and a non-deterministic caller. Learn Anthropic's five principles and LangChain tool patterns.

By Galactic News Editorial · Published 2026-11-20T16:30:28+00:00 · Updated 2026-11-20T16:30:28+00:00

AI agent tool design guide for developers building agents

AI Agent Tool Design: Writing Tools Your Agent Can Actually Call

AI agent tool design decides whether an agent succeeds or flails. A tool is the contract between deterministic code and a non-deterministic caller. The model never runs your code. It reads a name, a description, and a JSON schema, then asks for a call. Design for that caller, not for a human developer reading your API docs.

What a Tool Really Is

Every tool reaches the model as three things: a name, a description, and a JSON schema for its arguments. The model returns a structured tool call with a name, arguments, and an ID. Your runtime executes the call and returns the result as a tool result message carrying the same ID. The model then decides what to do next.

This means the description is the user interface. A vague description produces vague calls. A precise description produces correct calls. Anthropic makes the point directly in its guidance on writing effective tools: tools should be designed for agents, not wrapped around an existing API as-is.

Five Principles for AI Agent Tool Design

Anthropic's engineering guidance distils tool design into five principles, developed from building agentic systems with real teams.

Building Tools in LangChain

LangChain offers two main ways to define a tool. The @tool decorator turns a typed Python function into a tool. The docstring becomes the description. The type hints become the input schema. This is the fastest path for simple tools.

from langchain_core.tools import tool

@tool
def get_weather(city: str) -> str:
    '''Get the current weather for a city.

    Args:
        city: The city name, e.g. 'Lahore'.
    '''
    return lookup_weather(city)

For tools with several inputs, use StructuredTool with a Pydantic schema. Pydantic validates inputs before your function runs, which stops malformed calls from reaching your code. Field descriptions guide the model on what each parameter expects. Use Literal types for enums instead of free strings the model must guess.

from langchain_core.tools import StructuredTool
from pydantic import BaseModel, Field

class SearchInput(BaseModel):
    query: str = Field(description="Search query text")
    limit: int = Field(default=5, description="Max results to return")

search_tool = StructuredTool.from_function(
    func=search_database,
    name="search_database",
    description="Search the product database by keyword.",
    args_schema=SearchInput,
)

LangChain v1 adds a third path. The create_agent constructor from langchain.agents takes a list of tools and runs the standard model-to-tool loop on a LangGraph runtime. Use it for the normal agent loop. Use bind_tools when you want to run the loop yourself.

Design Rules That Prevent Bad Calls

Keep each tool narrow. One tool should do one thing an agent would naturally want. Prefer a few purpose-built tools, such as docs_search and docs_get_page, over one generic docs_api tool that takes a method, a path, and a body. A generic passthrough forces the model to know your API surface, which it does not.

Make arguments typed and constrained. Enums beat free strings. Required fields beat optional ones with magic defaults. If an argument has a small set of valid values, say so in the schema, not just in the description.

Handle errors inside the tool. Return a clear error message the model can act on, such as "No results for that query, try a broader term." Never let an exception crash the agent loop. LangChain's BaseTool supports handle_tool_error for this purpose.

Keep responses short by default. Return a summary plus a way to fetch detail. A search tool can return titles and short snippets, with a second tool to fetch the full page. This keeps the context window free for reasoning.

Test Tools Like a Product, Not a Function

Anthropic recommends an iterative loop: build a quick prototype, test it locally, run evaluations, and repeat. Evaluations should use tasks drawn from real usage, not toy examples. Run the agent against those tasks, collect the transcripts, and study where the model chose the wrong tool or passed bad arguments. Then fix the description or the schema, not the model.

Track three failure modes. Wrong tool chosen means the descriptions overlap. Bad arguments mean the schema or the field descriptions are unclear. Unnecessary calls mean a tool returns too little context, so the agent keeps digging. Each failure points at a specific fix in the tool definition.

The Bottom Line

Write tools for the model that reads them. Give each tool a clear name, a precise description, and a tight typed schema. Keep tools narrow, responses short, and errors helpful. Prototype fast, evaluate on real tasks, and iterate on the descriptions. The agent is only as capable as the tools you hand it.