Writing Tool Schemas for Claude
Introduction & Goals
Welcome to your first lesson in developing Claude agents with tool integration! In this lesson, you'll learn the foundational skill of preparing function schemas that enable Claude to understand and request the use of your custom tools through a process called function calling.
By the end of this lesson, you'll understand how to write Ruby methods in functions.rb and create JSON schemas in schemas.json that describe these methods to Claude. You'll also learn how to wire everything together in main.rb using a tool registry that maps schema names to Ruby Method objects. These schemas are the bridge that allows Claude to understand what your methods do and how to call them, even though Claude never sees your actual Ruby code. This foundational step is essential before you can build a complete Claude agent system that can execute tools and use their results.
How Claude Uses Tools Through Function Calling
Function calling is the mechanism that allows Claude to use external tools and capabilities beyond text generation. Here is how the process works conceptually:
- You provide
Claudewithfunction schemas(JSONdescriptions of your tools). Claudeanalyzes user requests and determines if any of your tools would be helpful.- If
Claudedecides a tool is needed, it responds with a tool use request that includes the function name and specific parameters. - Your system receives this
tool use request, looks up the correspondingRubymethod in yourtool registry, and executes it with the provided parameters. - Your system sends the method result back to
Claude. Claudeincorporates this result into its response to the user or decides to use additional tools if needed.
The key insight is that Claude only sees the schemas (JSON descriptions), never your actual Ruby code. The schemas must contain all the information Claude needs to understand what each tool does and how to use it correctly. This separation means you can organize your Ruby methods however you like — Claude relies entirely on the schema descriptions to make decisions about tool usage.
In this lesson, we'll focus on preparing the schemas, creating the tool registry, and verifying that your local tool dispatch works correctly. This prepares you for integrating with the Anthropic API's tool-calling capabilities in future lessons.
