1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
---
allowed-tools: Read, Write, Edit, MultiEdit, Bash
description: Create AI tools and function calling capabilities
argument-hint: "[simple|database|api|multimodal|agent]"
---
## Set up AI Tools and Function Calling
Create comprehensive AI tool integrations with the Vercel AI SDK for: $ARGUMENTS
### Current Project Analysis
Existing tool implementations: !`grep -r "import.*tool" . --include="*.ts" --include="*.tsx" | head -5`
API integrations: !`grep -r "fetch\|axios" . --include="*.ts" | head -5`
Database setup: !`find . -name "*schema*" -o -name "*db*" -o -name "*database*" | grep -v node_modules | head -5`
### Tool Type Requirements
**Simple Tools**: Basic utility functions (calculator, formatter, validator)
**Database Tools**: Safe database queries, data retrieval, analytics
**API Tools**: External service integrations, webhooks, data fetching
**Multimodal Tools**: Image processing, document analysis, file handling
**Agent Tools**: Complex workflows, multi-step operations, decision making
### Your Task
1. **Analyze the project needs** and identify appropriate tool types
2. **Design tool schemas** with proper Zod validation
3. **Implement secure execution logic** with error handling
4. **Set up proper authentication** and authorization
5. **Add comprehensive input validation** and sanitization
6. **Implement rate limiting** and usage monitoring
7. **Create tool testing suite** for reliability
8. **Document tool usage** and examples
### Implementation Guidelines
#### Tool Definition Patterns
```typescript
// Basic tool structure
const toolName = tool({
description: 'Clear description of what the tool does',
inputSchema: z.object({
param: z.string().describe('Parameter description'),
}),
execute: async ({ param }) => {
// Implementation with proper error handling
try {
const result = await performOperation(param);
return { success: true, data: result };
} catch (error) {
return { success: false, error: error.message };
}
},
});
```
#### Security Considerations
- Input validation and sanitization
- Authentication and authorization checks
- Rate limiting and abuse prevention
- Secure API key management
- Output filtering and validation
- Audit logging for sensitive operations
#### Error Handling
- Graceful failure modes
- Informative error messages
- Retry mechanisms for transient failures
- Fallback strategies
- Circuit breaker patterns
- Monitoring and alerting
### Expected Deliverables
1. **Tool definitions** with proper schemas and validation
2. **Execution implementations** with robust error handling
3. **Agent integration** with multi-step capabilities
4. **Security middleware** for authentication and rate limiting
5. **Testing suite** covering all tool scenarios
6. **Usage analytics** and monitoring
7. **Documentation** with examples and best practices
### Tool Categories to Implement
#### Data & Analytics Tools
- Database query execution
- Data aggregation and analysis
- Report generation
- Chart and visualization creation
#### External Integration Tools
- REST API clients
- Webhook handlers
- File processing and storage
- Email and notification services
#### Utility Tools
- Text processing and formatting
- Mathematical calculations
- Data validation and transformation
- Code generation and analysis
#### Advanced Agent Tools
- Multi-step workflow orchestration
- Decision tree navigation
- Dynamic tool selection
- Context-aware processing
### Testing Requirements
- Unit tests for each tool execution path
- Integration tests with external services
- Security tests for input validation
- Performance tests under load
- Error scenario testing
- End-to-end agent workflow tests
### Monitoring and Observability
- Tool usage metrics and analytics
- Performance monitoring and latency tracking
- Error rate monitoring and alerting
- Cost tracking for external API usage
- Security audit logging
- User behavior analysis
Focus on building secure, reliable, and well-tested tool integrations that enhance AI capabilities while maintaining proper security and monitoring practices.
|