1896 words
9 minutes
Writing Effective Tools for Agents

The Model Context Protocol (MCP) can empower LLM agents with potentially hundreds of tools to solve real-world tasks. But how do we make those tools maximally effective?

What is a Tool?#

In computing, deterministic systems produce the same output every time given identical inputs, while non-deterministic systems like agents can generate varied responses even with the same starting conditions.

When we traditionally write software, we are establishing a contract between deterministic systems. For instance, a function call like getWeather("NYC") will always fetch the weather in New York City in the exact same manner every time it is called.

Tools are a new kind of software which reflects a contract between deterministic systems and non-deterministic agents. When a user asks “Should I bring an umbrella today?”, an agent might call the weather tool, answer from general knowledge, or even ask a clarifying question about location first. Occasionally, an agent might hallucinate or even fail to grasp how to use a tool.

This means fundamentally rethinking our approach when writing software for agents: instead of writing tools and MCP servers the way we would write functions and APIs for other developers or systems, we need to design them for agents. The goal is to increase the surface area over which agents can be effective in solving a wide range of tasks by using tools to pursue a variety of successful strategies. Fortunately, it has been found that the tools that are most “ergonomic” for agents also end up being surprisingly intuitive to grasp as humans.

How to Write Tools#

In this section, we describe how we can collaborate with agents both to write and to improve the tools we give them. Start by standing up a quick prototype of our tools and testing them locally. Next, run a comprehensive evaluation to measure subsequent changes. Working alongside agents, we can repeat the process of evaluating and improving our tools until our agents achieve strong performance on real-world tasks.

Building a Prototype#

It can be difficult to anticipate which tools agents will find ergonomic and which tools they won’t without getting hands-on ourselves. Start by standing up a quick prototype of our tools. It helps to give agent documentation for any software libraries, APIs, or SDKs (including potentially the MCP SDK) our tools will rely on. LLM-friendly documentation can commonly be found in flat llms.txt files on official documentation sites.

Wrapping our tools in a local MCP server allows us to connect and test our tools in agent.

TIP

Different agents connect to MCP server differently. Claude Code for example uses claude mcp add <name> <command> [args...]

Test the tools ourselves to identify any rough edges. Collect feedback from our users to build an intuition around the use-cases and prompts we expect our tools to enable.

Running an Evaluation#

Next, we need to measure how well agent uses our tools by running an evaluation. Start by generating lots of evaluation tasks, grounded in real world uses. It is recommended to collaborate with an agent to help analyze our results and determine how to improve our tools. See this process end-to-end in the following notebooks:

Explore in Jupyter notebook Explore in Kaggle

Principles for Writing Effective Tools#

Choosing the Right Tools for Agents#

More tools don’t always lead to better outcomes. A common error is tools that merely wrap existing software functionality or API endpoints, whether or not the tools are appropriate for agents. This is because agents have distinct “affordances” to traditional software, that is, they have different ways of perceiving the potential actions they can take with those tools

LLM agents have limited “context” (that is, there are limits to how much information they can process at once), whereas computer memory is cheap and abundant. Consider the task of searching for a contact in an address book. Traditional software programs can efficiently store and process a list of contacts one at a time, checking each one before moving on. However, if an LLM agent uses a tool that returns ALL contacts and then has to read through each one token-by-token, it’s wasting its limited context space on irrelevant information (imagine searching for a contact in address book by reading each page from top-to-bottom—that is, via brute-force search). The better and more natural approach (for agents and humans alike) is to skip to the relevant page first (perhaps finding it alphabetically).

It is recommended to build a few thoughtful tools targeting specific high-impact workflows, which match our evaluation tasks and scaling up from there. In the address book case, we might choose to implement a search_contacts or message_contact tool instead of a list_contacts tool.

Tools can consolidate functionality, handling potentially multiple discrete operations (or API calls) under the hood. For example, tools can enrich tool responses with related metadata or handle frequently chained, multi-step tasks in a single tool call.

Here are some examples:

  • Instead of implementing a list_users, list_events, and create_event tools, consider implementing a schedule_event tool which finds availability and schedules an event.
  • Instead of implementing a read_logs tool, consider implementing a search_logs tool which only returns relevant log lines and some surrounding context.
  • Instead of implementing get_customer_by_id, list_transactions, and list_notes tools, implement a get_customer_context tool which compiles all of a customer’s recent & relevant information all at once.

Make sure each tool we build has a clear, distinct purpose. Tools should

  1. enable agents to subdivide and solve tasks in much the same way that a human would, given access to the same underlying resources, and
  2. simultaneously reduce the context that would have otherwise been consumed by intermediate outputs.

Separate scheduling calls fill the agent&#x27;s context with contact records, calendar data, and an event record. A single scheduling tool handles those steps internally and returns only a short meeting confirmation.

Too many tools or overlapping tools can also distract agents from pursuing efficient strategies. Careful, selective planning of the tools we build (or don’t build) can really pay off.

Namespacing Tools#

Our AI agents will potentially gain access to dozens of MCP servers and hundreds of different tools, including those by other developers. When tools overlap in function or have a vague purpose, agents can get confused about which ones to use.

Namespacing (grouping related tools under common prefixes) can help delineate boundaries between lots of tools; MCP clients sometimes do this by default. For example, namespacing tools by service (e.g., asana_search, jira_search) and by resource (e.g., asana_projects_search, asana_users_search), can help agents select the right tools at the right time.

An agent asked to find Asana projects selects asana_projects_search from tools grouped by service prefix.

TIP

It has been found that selecting between prefix- and suffix-based namespacing has non-trivial effects on tool-use evaluations for som LLM’s

Agents might call the wrong tools, call the right tools with the wrong parameters, call too few tools, or process tool responses incorrectly. By selectively implementing tools whose names reflect natural subdivisions of tasks, we simultaneously reduce the number of tools and tool descriptions loaded into the agent’s context and offload agentic computation from the agent’s context back into the tool calls themselves. This reduces an agent’s overall risk of making mistakes.

Returning Meaningful Context from Tools#

In the same vein, tool implementations should take care to return only high signal information back to agents. They should prioritize contextual relevance over flexibility, and eschew low-level technical identifiers (for example: uuid, 256px_image_url, mime_type). Fields like name, image_url, and file_type are much more likely to directly inform agents’ downstream actions and responses.

Agents also tend to grapple with natural language names, terms, or identifiers significantly more successfully than they do with cryptic identifiers. It has been found that merely resolving arbitrary alphanumeric UUIDs to more semantically meaningful and interpretable language (or even a 0-indexed ID scheme) significantly improves agent’s precision in retrieval tasks by reducing hallucinations.

In some instances, however, agents may require the flexibility to interact with both natural language and technical identifiers outputs, if only to trigger downstream tool calls (for example, search_user(name='jane') → send_message(id=12345)). We can enable both by exposing a simple response_format enum parameter in our tool like

enum ResponseFormat {
DETAILED = "detailed",
CONCISE = "concise"
}

which allows our agent to control whether tools return “concise” or “detailed” responses. We can add more formats for even greater flexibility, similar to GraphQL where we can choose exactly which pieces of information we want to receive.

Here is an example of a detailed tool response (206 tokens):

Here is an example of a concise tool response (72 tokens):

Slack threads and thread replies are identified by unique thread_ts which are required to fetch thread replies. thread_ts and other IDs (channel_id, user_id) can be retrieved from a “detailed” tool response to enable further tool calls that require these. “concise” tool responses return only thread content and exclude IDs. In this example, we use roughly 13\frac{1}{3} of the tokens with “concise” tool responses.

Even our tool response structure, for example XML, JSON, or Markdown, can have an impact on evaluation performance. There is no one-size-fits-all solution. This is because LLMs are trained on next-token prediction and tend to perform better with formats that match their training data. The optimal response structure will vary widely by task and agent. It is encouraged to select the best response structure based on our own evaluation.

Optimizing Tool Responses for Token Efficiency#

Optimizing the quality of context is important. But so is optimizing the quantity of context returned back to agents in tool responses.

We suggest implementing some combination of

  • pagination
  • range selection
  • filtering
  • truncation

with sensible default parameter values for any tool responses that could use up lots of context. A good practice it to restrict tool responses to some pre-defined value like 25,000 tokens by default. We expect the effective context length of agents to grow over time, but the need for context-efficient tools to remain. Here’s an example of a truncated tool response:

If we choose to truncate responses, be sure to steer agents with helpful instructions. We can directly encourage agents to pursue more token-efficient strategies, like making many small and targeted searches instead of a single, broad search for a knowledge retrieval task. Similarly, if a tool call raises an error (for example, during input validation), we can prompt-engineer our error responses to clearly communicate specific and actionable improvements, rather than opaque error codes or tracebacks. Here’s an example of an unhelpful error response:

Here’s an example of a helpful error response:

TIP

Tool truncation and error responses can steer agents towards more token-efficient tool-use behaviors (using filters or pagination) or give examples of correctly formatted tool inputs.

Prompt-Engineering Tool Descriptions#

We now come to one of the most effective methods for improving tools: prompt-engineering our tool descriptions and specs. Because these are loaded into our agents’ context, they can collectively steer agents toward effective tool-calling behaviors.

When writing tool descriptions and specs, think of how we would describe our tool to a new hire on our team. Consider

  • the context that we might implicitly bring, such as specialized query formats, definitions of niche terminology, relationships between underlying resources, and
  • make it explicit; avoid ambiguity by clearly describing (and enforcing with strict data models) expected inputs and outputs. In particular, input parameters should be unambiguously named: instead of a parameter named user, try a parameter named user_id.

A vague user parameter leaves the agent guessing between name, email, and ID. An explicit spec defines an integer user_id and a user profile response, guiding the agent to a valid call.

With our evaluation we can measure the impact of our prompt engineering with greater confidence. Even small refinements to tool descriptions can yield dramatic improvements.

Writing Effective Tools for Agents
https://blogs.openml.io/posts/agent-tools/
Author
OpenML Blogs
Published at
2026-11-29
License
CC BY-NC-SA 4.0