Showing posts with label developer guide. Show all posts
Showing posts with label developer guide. Show all posts

12.9.25

How to Build High-Quality Tools for LLM Agents — Lessons from Anthropic

 As agents become more central to AI workflows, what separates a good agent from a great one often comes down to the tools it has—and how well those tools are designed. In “Writing effective tools for agents — with agents,” Anthropic shares a practical roadmap for building better tools powered by tools themselves, using Claude and the Model Context Protocol (MCP) as real-use labs.


What are “tools” in the agentic context?

Unlike conventional software APIs—deterministic functions that always give the same output for the same input—tools for agents must be built to coexist with non-deterministic systems. Agents like Claude must decide when to use tools, how to parse their output, and how to call them responsibly. A tool here is not just an API call; it's part of an interface contract between predictable software and unpredictable agent behavior. Tools are the mechanisms by which agents expand what they can reliably do. 


Key workflows: prototyping, evaluating, and iterating

Anthropic emphasizes an iterative workflow:

  1. Prototype early: Build simple versions of your tools. Use MCP servers or desktop extensions to connect your tool to Claude Code, allowing rapid experimentation and detection of rough edges. Include clear documentation that the agent can consume. 

  2. Run realistic evaluations: Create evaluation tasks that reflect real-world usage (multiple tool calls, complex chains, integration with other services). Use verifiable outcomes, not just “it seems right.” Capture metrics such as tool calls, token consumption, runtime, errors. Avoid toy tasks that underrepresent complexity. 

  3. Use agents to improve tools: Let Claude analyze transcripts and feedback to suggest refinements—maybe better prompt descriptions, more efficient tool outputs, clearer schemas. Anthropic reports improvements even for tools built by internal experts, purely by letting agents inspect tools’ performance. 


Best practices and guiding principles

Anthropic distills the lessons into a set of design principles. Key among them:

  • Choosing tools selectively: Not every API needs to become a tool. Tools should cover high-impact, repeated workflows—not wrapping every possible existing endpoint. Also, consolidate when possible. 

  • Namespaces and naming clarity: Clear, consistent naming helps agents pick the right tool. Avoid ambiguous names or overlapping functionality. Group related tools under logical prefixes or categories. 

  • Return meaningful, concise context: Tools should return high-signal info. Avoid overwhelming the agent with technical IDs, long metadata unless necessary. Also allow “concise” vs “detailed” response modes. 

  • Optimize for token efficiency: Use truncation, filtering, pagination. Prompt agents to use fewer tool calls or more precise queries. Efficient context limits make downstream tasks more reliable. 

  • Clear tool specs and descriptions: Explicit parameter naming, clear input/output formats, good examples. Prompt engineering of tool descriptions can significantly impact performance. 


Why this matters

Tools shape what agents can do. When tools are poorly described, overly broad, or return huge dumps of irrelevant context, agents waste resources, produce hallucinations, or fail to successfully orchestrate workflows. On the other hand, well-designed tools reduce ambiguity, reduce token use, reduce error, and let agents scale reliably across real-world tasks.

Especially as agents connect to many tools (hundreds via MCP servers), these design principles become the difference between brittle behavior and something that feels reliable and intuitive. Anthropic’s experience shows that many improvements come not from changing the LLM itself but refining the tools around it.


If you’re building agent tools or service/tool APIs for agents, following Anthropic’s workflow—prototype → evaluate → iterate—and using clear naming, context-efficient returns, and good documentation will set you up for tools agents actually use well.

Link: https://www.anthropic.com/engineering/writing-tools-for-agents

9.6.25

Enable Function Calling in Mistral Agents Using Standard JSON Schema

 This updated tutorial guides developers through enabling function calling in Mistral Agents via the standard JSON Schema format Function calling allows agents to invoke external APIs or tools (like weather or flight data services) dynamically during conversation—extending their reasoning capabilities beyond text generation.


🧩 Why Function Calling?

  • Seamless tool orchestration: Enables agents to perform actions—like checking bank interest rates or flight statuses—in real time.

  • Schema-driven clarity: JSON Schema ensures function inputs and outputs are well-defined and type-safe.

  • Leverage MCP Orchestration: Integrates with Mistral's Model Context Protocol for complex workflows 


🛠️ Step-by-Step Implementation

1. Define Your Function

Create a simple API wrapper, e.g.:

python
def get_european_central_bank_interest_rate(date: str) -> dict: # Mock implementation returning a fixed rate return {"date": date, "interest_rate": "2.5%"}

2. Craft the JSON Schema

Define the function parameters so the agent knows how to call it:

python
tool_def = { "type": "function", "function": { "name": "get_european_central_bank_interest_rate", "description": "Retrieve ECB interest rate", "parameters": { "type": "object", "properties": { "date": {"type": "string"} }, "required": ["date"] } } }

3. Create the Agent

Register the agent with Mistral's SDK:

python
agent = client.beta.agents.create( model="mistral-medium-2505", name="ecb-interest-rate-agent", description="Fetch ECB interest rate", tools=[tool_def], )

The agent now recognizes the function and can decide when to invoke it during a conversation.

4. Start Conversation & Execute

Interact with the agent using a prompt like, "What's today's interest rate?"

  • The agent emits a function.call event with arguments.

  • You execute the function and return a function.result back to the agent.

  • The agent continues based on the result.

This demo uses a mocked example, but any external API can be plugged in—flight info, weather, or tooling endpoints 


✅ Takeaways

  • JSON Schema simplifies defining callable tools.

  • Agents can autonomously decide if, when, and how to call your functions.

  • This pattern enhances Mistral Agents’ real-time capabilities across knowledge retrieval, action automation, and dynamic orchestration.

What Claude offers now From Anthropic’s announcements: Creates and edits real files directly in chats or the desktop app: Excel (.xlsx)...