Custom Tools
Tool Examples
Common custom tool patterns and examples
1 min read
Documentation
Learn from these example tools to build your own.
API Tools
Weather Lookup
Name: Get Weather
Description: Get current weather conditions for any city
Type: API
Method: GET
Endpoint: https://api.openweathermap.org/data/2.5/weather
Parameters:
city (string, required): "City name, e.g., 'New York'"
units (string, optional): "metric or imperial"
Default: "metric"
Query Parameters:
q: {{city}}
units: {{units}}
appid: {{WEATHER_API_KEY}}Stock Quote
Name: Get Stock Quote
Description: Get current stock price and change
Type: API
Method: GET
Endpoint: https://api.stockdata.com/v1/quote
Parameters:
symbol (string, required): "Stock ticker, e.g., 'AAPL'"
Headers:
X-API-Key: {{STOCK_API_KEY}}
Query Parameters:
symbols: {{symbol}}Send SMS
Name: Send SMS
Description: Send a text message via Twilio
Type: API
Method: POST
Endpoint: https://api.twilio.com/2010-04-01/Accounts/{{TWILIO_SID}}/Messages
Parameters:
to (string, required): "Phone number with country code"
message (string, required): "Message text"
Headers:
Authorization: Basic {{TWILIO_AUTH}}
Content-Type: application/x-www-form-urlencoded
Body:
To={{to}}&From={{TWILIO_NUMBER}}&Body={{message}}Code Tools
Calculate Tip
// Tool: Calculate Tip
// Description: Calculate tip and total for a bill
const bill = params.bill_amount;
const tipPercent = params.tip_percent || 18;
const splitWays = params.split_ways || 1;
const tip = bill * (tipPercent / 100);
const total = bill + tip;
const perPerson = total / splitWays;
return {
bill: bill.toFixed(2),
tip_percent: tipPercent,
tip_amount: tip.toFixed(2),
total: total.toFixed(2),
per_person: splitWays > 1 ? perPerson.toFixed(2) : null
};Format Date
// Tool: Format Date
// Description: Convert date to various formats
const dateStr = params.date;
const format = params.format || "full";
const date = new Date(dateStr);
const formats = {
full: date.toLocaleDateString('en-US', {
weekday: 'long', year: 'numeric',
month: 'long', day: 'numeric'
}),
short: date.toLocaleDateString('en-US'),
iso: date.toISOString().split('T')[0],
relative: getRelativeTime(date)
};
return { formatted: formats[format] || formats.full };Text Analysis
// Tool: Analyze Text
// Description: Get statistics about text
const text = params.text;
const words = text.trim().split(/\s+/);
const sentences = text.split(/[.!?]+/).filter(s => s.trim());
const chars = text.length;
const charsNoSpaces = text.replace(/\s/g, '').length;
return {
word_count: words.length,
sentence_count: sentences.length,
character_count: chars,
characters_no_spaces: charsNoSpaces,
avg_word_length: (charsNoSpaces / words.length).toFixed(1),
reading_time_minutes: Math.ceil(words.length / 200)
};Hybrid Tools
Search and Summarize
Combine API call with processing:
Step 1: API call to search
Step 2: Code tool to summarize results
// Search API returns many results
// Code tool transforms:
const results = params.api_results;
return {
summary: `Found ${results.length} items`,
top_3: results.slice(0, 3).map(r => ({
name: r.name,
price: r.price
}))
};Integration with Agents
Using Tools in Agents
Agent: Price Checker
Trigger: Daily at 9 AM
Tools: Get Stock Quote (custom tool)
Instructions:
1. Use Get Stock Quote tool for AAPL, GOOGL, MSFT
2. Compare to yesterday's close
3. Report any changes > 5%Chaining Tools
Agent: Order Notifier
Tools: Check Order Status, Send SMS (custom tools)
Instructions:
1. Use Check Order Status for order_id
2. If status is "shipped", use Send SMS
to notify customerBest Practices
Clear Descriptions
Help the AI use your tool:
Good: "Get current weather including temperature,
humidity, and conditions for any city worldwide"
Bad: "Weather API"Sensible Defaults
limit: default 10 (not 1000)
format: default "json" (most common)
include_metadata: default false (simpler)Error Handling
Return clear error messages:
if (!params.email.includes('@')) {
return { error: "Invalid email format" };
}Common Questions
Next Steps
Was this page helpful? Let us know!
Report an issue