Skip to content

Commit 768b40f

Browse files
arcaelaclaude
andcommitted
docs: add comprehensive API reference for Providers and Built-in Tools
- Complete Providers API with OpenAI, Anthropic, Groq examples - Complete Built-in Tools API (RemoteTool and TimeTool) - Added multi-provider failover patterns - Included HTTP integration and timezone handling - Best practices for API security and error handling All API Reference pages are now complete! 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 08ab5e9 commit 768b40f

2 files changed

Lines changed: 649 additions & 4 deletions

File tree

docs/api/built-in-tools.md

Lines changed: 369 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,370 @@
1-
# built-in-tools.md
1+
# Built-in Tools
22

3-
Documentation coming soon. Check back later or contribute at [GitHub](https://github.com/arcaelas/agent).
3+
@arcaelas/agent includes two production-ready tools: **RemoteTool** for HTTP requests and **TimeTool** for time/date operations.
4+
5+
## RemoteTool
6+
7+
**RemoteTool** wraps HTTP API calls as agent tools. Supports GET, POST, PUT, DELETE, and PATCH methods.
8+
9+
### Constructor
10+
11+
```typescript
12+
new RemoteTool(name: string, options: RemoteToolOptions)
13+
```
14+
15+
### RemoteToolOptions
16+
17+
```typescript
18+
interface RemoteToolOptions {
19+
description: string;
20+
parameters?: Record<string, string>;
21+
http: {
22+
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
23+
headers: Record<string, string>;
24+
url: string;
25+
};
26+
}
27+
```
28+
29+
### Examples
30+
31+
**GET Request:**
32+
33+
```typescript
34+
import { RemoteTool } from '@arcaelas/agent';
35+
36+
const weather_api = new RemoteTool("get_weather", {
37+
description: "Get current weather from external API",
38+
parameters: {
39+
city: "City name to query",
40+
units: "Temperature units (celsius or fahrenheit)"
41+
},
42+
http: {
43+
method: "GET",
44+
headers: {
45+
"X-API-Key": process.env.WEATHER_API_KEY!,
46+
"Accept": "application/json"
47+
},
48+
url: "https://api.weather.com/v1/current"
49+
}
50+
});
51+
```
52+
53+
**POST Request:**
54+
55+
```typescript
56+
const create_ticket = new RemoteTool("create_support_ticket", {
57+
description: "Create customer support ticket",
58+
parameters: {
59+
subject: "Ticket subject",
60+
description: "Detailed description",
61+
priority: "Priority level (low, medium, high)"
62+
},
63+
http: {
64+
method: "POST",
65+
headers: {
66+
"Authorization": `Bearer ${process.env.SUPPORT_API_TOKEN}`,
67+
"Content-Type": "application/json"
68+
},
69+
url: "https://support.example.com/api/tickets"
70+
}
71+
});
72+
```
73+
74+
**Usage in Agent:**
75+
76+
```typescript
77+
const agent = new Agent({
78+
name: "Weather_Assistant",
79+
description: "Provides weather information",
80+
tools: [weather_api],
81+
providers: [openai_provider]
82+
});
83+
84+
await agent.call("What's the weather in Madrid?");
85+
// Agent automatically calls weather_api tool with { city: "Madrid", units: "celsius" }
86+
```
87+
88+
### Behavior Notes
89+
90+
- Parameters are sent as JSON in request body (for ALL methods including GET)
91+
- Returns response as plain text
92+
- Automatic error handling by agent
93+
- Headers support dynamic values from environment variables
94+
95+
## TimeTool
96+
97+
**TimeTool** provides current date and time with timezone support.
98+
99+
### Constructor
100+
101+
```typescript
102+
new TimeTool(options?: { time_zone?: string })
103+
```
104+
105+
**Options:**
106+
- **time_zone**: Optional IANA timezone (e.g., "Europe/Madrid", "America/New_York", "Asia/Tokyo")
107+
108+
### Examples
109+
110+
**System Timezone:**
111+
112+
```typescript
113+
import { TimeTool } from '@arcaelas/agent';
114+
115+
const time_tool = new TimeTool({});
116+
117+
// Returns current time in system timezone
118+
// Format: "12/27/2024, 3:45:30 PM"
119+
```
120+
121+
**Specific Timezone:**
122+
123+
```typescript
124+
const tokyo_time = new TimeTool({
125+
time_zone: "Asia/Tokyo"
126+
});
127+
128+
const madrid_time = new TimeTool({
129+
time_zone: "Europe/Madrid"
130+
});
131+
132+
const utc_time = new TimeTool({
133+
time_zone: "UTC"
134+
});
135+
```
136+
137+
**Usage in Agent:**
138+
139+
```typescript
140+
const agent = new Agent({
141+
name: "Time_Assistant",
142+
description: "Provides time information",
143+
tools: [
144+
new TimeTool({ time_zone: "Europe/Madrid" })
145+
],
146+
providers: [openai_provider]
147+
});
148+
149+
await agent.call("What time is it in Madrid?");
150+
// Agent calls get_time tool, returns: "12/27/2024, 2:45:30 PM"
151+
```
152+
153+
**Multi-Timezone Agent:**
154+
155+
```typescript
156+
const world_clock_agent = new Agent({
157+
name: "World_Clock",
158+
description: "Provides time in multiple timezones",
159+
tools: [
160+
new TimeTool({ time_zone: "America/New_York" }),
161+
new TimeTool({ time_zone: "Europe/London" }),
162+
new TimeTool({ time_zone: "Asia/Tokyo" })
163+
],
164+
providers: [openai_provider]
165+
});
166+
```
167+
168+
### Output Format
169+
170+
All times are returned in `en-US` locale format regardless of timezone:
171+
172+
```
173+
"MM/DD/YYYY, HH:MM:SS AM/PM"
174+
175+
Examples:
176+
- "12/27/2024, 3:45:30 PM"
177+
- "01/01/2025, 12:00:00 AM"
178+
- "06/15/2024, 11:23:45 PM"
179+
```
180+
181+
### Supported Timezones
182+
183+
Uses IANA timezone database. Common timezones:
184+
185+
- **Americas**: `America/New_York`, `America/Los_Angeles`, `America/Chicago`, `America/Toronto`, `America/Sao_Paulo`
186+
- **Europe**: `Europe/London`, `Europe/Paris`, `Europe/Berlin`, `Europe/Madrid`, `Europe/Rome`
187+
- **Asia**: `Asia/Tokyo`, `Asia/Shanghai`, `Asia/Dubai`, `Asia/Kolkata`, `Asia/Singapore`
188+
- **Pacific**: `Pacific/Auckland`, `Australia/Sydney`, `Pacific/Honolulu`
189+
- **Special**: `UTC`
190+
191+
[Full list of IANA timezones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
192+
193+
## Usage Patterns
194+
195+
### Pattern: API Integration
196+
197+
```typescript
198+
const github_api = new RemoteTool("search_github_repos", {
199+
description: "Search GitHub repositories",
200+
parameters: {
201+
query: "Search query",
202+
language: "Programming language filter",
203+
min_stars: "Minimum number of stars"
204+
},
205+
http: {
206+
method: "GET",
207+
headers: {
208+
"Authorization": `Bearer ${process.env.GITHUB_TOKEN}`,
209+
"Accept": "application/vnd.github.v3+json"
210+
},
211+
url: "https://api.github.com/search/repositories"
212+
}
213+
});
214+
```
215+
216+
### Pattern: Multi-Service Agent
217+
218+
```typescript
219+
const multi_service_agent = new Agent({
220+
name: "Multi_Service_Assistant",
221+
description: "Integrates multiple external services",
222+
tools: [
223+
new RemoteTool("get_weather", {...}),
224+
new RemoteTool("search_news", {...}),
225+
new RemoteTool("create_task", {...}),
226+
new TimeTool({})
227+
],
228+
providers: [openai_provider]
229+
});
230+
```
231+
232+
### Pattern: Time-Aware Agents
233+
234+
```typescript
235+
const business_hours_agent = new Agent({
236+
name: "Business_Hours_Assistant",
237+
description: "Provides time-aware responses",
238+
tools: [
239+
new TimeTool({ time_zone: "America/New_York" })
240+
],
241+
rules: [
242+
new Rule("Inform about business hours", {
243+
when: async (agent) => {
244+
// Agent can use time tool to check current time
245+
const hour = new Date().getHours();
246+
return hour < 9 || hour > 17;
247+
}
248+
})
249+
],
250+
providers: [openai_provider]
251+
});
252+
```
253+
254+
## Best Practices
255+
256+
### 1. Secure API Keys
257+
258+
```typescript
259+
// ✅ Good: Use environment variables
260+
const secure_tool = new RemoteTool("api_call", {
261+
description: "Make API call",
262+
http: {
263+
method: "POST",
264+
headers: {
265+
"Authorization": `Bearer ${process.env.API_KEY}`
266+
},
267+
url: process.env.API_URL!
268+
}
269+
});
270+
271+
// ❌ Bad: Hardcode credentials
272+
const insecure_tool = new RemoteTool("api_call", {
273+
description: "Make API call",
274+
http: {
275+
method: "POST",
276+
headers: {
277+
"Authorization": "Bearer sk-hardcoded-key-12345" // Never do this!
278+
},
279+
url: "https://api.example.com"
280+
}
281+
});
282+
```
283+
284+
### 2. Clear Parameter Descriptions
285+
286+
```typescript
287+
// ✅ Good: Detailed parameter descriptions
288+
new RemoteTool("search_products", {
289+
description: "Search product catalog with filters",
290+
parameters: {
291+
query: "Product search query (e.g., 'red shoes', 'laptop')",
292+
category: "Product category ID (optional, e.g., 'electronics')",
293+
max_price: "Maximum price in USD (optional, e.g., '99.99')"
294+
},
295+
http: {...}
296+
});
297+
298+
// ❌ Bad: Vague descriptions
299+
new RemoteTool("search_products", {
300+
description: "Search",
301+
parameters: {
302+
query: "Query",
303+
category: "Category",
304+
max_price: "Price"
305+
},
306+
http: {...}
307+
});
308+
```
309+
310+
### 3. Use Appropriate HTTP Methods
311+
312+
```typescript
313+
// ✅ Good: GET for queries
314+
new RemoteTool("get_user", {
315+
description: "Retrieve user information",
316+
http: { method: "GET", ... }
317+
});
318+
319+
// ✅ Good: POST for creation
320+
new RemoteTool("create_user", {
321+
description: "Create new user",
322+
http: { method: "POST", ... }
323+
});
324+
325+
// ✅ Good: PUT/PATCH for updates
326+
new RemoteTool("update_user", {
327+
description: "Update user information",
328+
http: { method: "PATCH", ... }
329+
});
330+
331+
// ✅ Good: DELETE for removal
332+
new RemoteTool("delete_user", {
333+
description: "Delete user account",
334+
http: { method: "DELETE", ... }
335+
});
336+
```
337+
338+
## Type Safety
339+
340+
Both tools are fully typed with TypeScript:
341+
342+
```typescript
343+
import { RemoteTool, TimeTool } from '@arcaelas/agent';
344+
345+
// Type-safe RemoteTool
346+
const api_tool: RemoteTool = new RemoteTool("api_call", {
347+
description: "Call external API",
348+
http: {
349+
method: "POST", // ✅ Type-checked: only valid HTTP methods
350+
headers: { "Content-Type": "application/json" },
351+
url: "https://api.example.com"
352+
}
353+
});
354+
355+
// Type-safe TimeTool
356+
const time_tool: TimeTool = new TimeTool({
357+
time_zone: "Europe/Madrid" // ✅ String type, validated at runtime
358+
});
359+
```
360+
361+
## Related
362+
363+
- **[Tool](tool.md)** - Base Tool class
364+
- **[Agent](agent.md)** - Uses tools for capabilities
365+
- **[Custom Tools Example](../examples/custom-tools.md)** - Creating custom tools
366+
- **[API Integration](../examples/advanced-patterns.md#api-integration)** - Advanced patterns
367+
368+
---
369+
370+
**Congratulations!** You've completed the API Reference. Next, explore the [Examples](../examples/basic-agent.md) for practical implementations.

0 commit comments

Comments
 (0)