SKILL.md
Anthropic Tool Use (Function Calling)
Overview
Tool use lets Claude call functions you define — query databases, hit APIs, read files, do math. Claude decides when to call a tool, you execute it, and feed the result back. This is how you build Claude-powered agents.
Note: Anthropic does not offer an embeddings API. For embeddings + vector search, pair Claude with a dedicated embedding model (OpenAI, Cohere, or Voyage).
Prerequisites
- Completed
clade-model-inference - Understanding of JSON Schema for tool definitions
Instructions
Step 1: Define Tools
import Anthropic from '@claude-ai/sdk';
const client = new Anthropic();
const tools: Anthropic.Tool[] = [
{
name: 'get_weather',
description: 'Get current weather for a city. Call this when the user asks about weather.',
input_schema: {
type: 'object',
properties: {
city: { type: 'string', description: 'City name, e.g. "San Francisco"' },
unit: { type: 'string', enum: ['celsius', 'fahrenheit'], description: 'Temperature unit' },
},
required: ['city'],
},
},
];
Step 2: Send Message with Tools
const response = await client.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
tools,
messages: [{ role: 'user', content: "What's the weather in San Francisco?" }],
});
// Claude responds with stop_reason: 'tool_use'
// response.content includes a tool_use block:
// { type: 'tool_use', id: 'toolu_01...', name: 'get_weather', input: { city: 'San Francisco' } }
Step 3: Execute Tool and Return Result
// Find the tool use block
const toolUse = response.content.find(block => block.type === 'tool_use');
// Execute your function
const weatherData = await fetchWeather(toolUse.input.city);
// Send result back to Claude
const finalResponse = await client.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
tools,
messages: [
{ role: 'user', content: "What's the weather in San Francisco?" },
{ role: 'assistant', content: response.content },
{
role: 'user',
content: [{
type: 'tool_result',
tool_use_id: toolUse.id,
content: JSON.stringify(weatherData),
}],
},
],
});
console.log(finalResponse.content[0].text);
// "The weather in San Francisco is currently 65°F and partly cloudy."
