Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
A comprehensive collection of Agent Skills for context engineering, multi-agent architectures, and production agent systems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
examples/llm-as-judge-skills/skills/tool-design/tool-design.md
1# Agent Tool Design Skill23## Overview45Tools are the foundation of an agent's capabilities. An agent's ability to take meaningful actions depends entirely on how reliably it can generate valid tool inputs, how well those inputs align with user intent, and how effectively tool outputs inform next steps.67## Design Principles89### 1. Single Responsibility1011Each tool should do one thing well. Complex operations should be composed from multiple tools.1213```typescript14// Bad: Tool does too much15const analyzeAndSummarizeAndSend = { ... }1617// Good: Separate concerns18const analyzeDocument = { ... }19const summarizeContent = { ... }20const sendEmail = { ... }21```2223### 2. Clear Input Schemas2425Use explicit, validated schemas with descriptive field names and constraints.2627```typescript28const searchTool = tool({29description: "Search for documents by semantic similarity",30parameters: z.object({31query: z.string().describe("Natural language search query"),32limit: z.number().min(1).max(100).default(10)33.describe("Maximum number of results to return"),34filters: z.object({35dateAfter: z.string().optional()36.describe("ISO date string, only return docs after this date"),37source: z.enum(["internal", "external", "all"]).default("all")38}).optional()39}),40execute: async (input) => { ... }41});42```4344### 3. Predictable Output Structure4546Return consistent, typed output that the model can reliably parse.4748```typescript49interface ToolResult<T> {50success: boolean;51data?: T;52error?: {53code: string;54message: string;55retryable: boolean;56};57metadata: {58executionTimeMs: number;59source?: string;60};61}62```6364### 4. Graceful Error Handling6566Tools should never throw unhandled exceptions. Always return structured errors.6768```typescript69execute: async (input) => {70try {71const result = await performAction(input);72return { success: true, data: result };73} catch (error) {74return {75success: false,76error: {77code: error.code ?? "UNKNOWN_ERROR",78message: error.message,79retryable: isRetryable(error)80}81};82}83}84```8586## Tool Categories8788### Read-Only Tools89- Database queries90- API fetches91- File reads92- Search operations9394Safe to execute without approval. Return data but don't mutate state.9596### State-Modifying Tools97- Database writes98- File modifications99- API POST/PUT/DELETE100- System configuration changes101102May require human approval. Consider `needsApproval` flag.103104### Dangerous Tools105- File deletion106- Payment processing107- Production deployments108- Sending external communications109110Should always require approval and audit logging.111112## AI SDK 6 Tool Features113114### Tool Execution Approval115```typescript116const deleteTool = tool({117description: "Delete a file from the system",118parameters: z.object({119path: z.string()120}),121needsApproval: true, // Requires human approval122execute: async ({ path }) => { ... }123});124125// Dynamic approval based on input126const commandTool = tool({127description: "Execute a shell command",128parameters: z.object({129command: z.string()130}),131needsApproval: ({ command }) => {132return command.includes("rm") || command.includes("delete");133},134execute: async ({ command }) => { ... }135});136```137138### Strict Mode139Enable native strict mode for guaranteed schema compliance:140```typescript141const strictTool = tool({142description: "...",143parameters: schema,144strict: true, // Enable strict mode145execute: async (input) => { ... }146});147```148149### Input Examples150Help the model understand expected input format:151```typescript152const complexTool = tool({153description: "Create a calendar event",154parameters: eventSchema,155inputExamples: [156{157title: "Team Standup",158date: "2024-01-15",159time: "09:00",160duration: 30,161attendees: ["[email protected]", "[email protected]"]162}163],164execute: async (input) => { ... }165});166```167168### toModelOutput169Control what gets sent back to the model:170```typescript171const readFileTool = tool({172description: "Read file contents",173parameters: z.object({ path: z.string() }),174execute: async ({ path }) => {175const content = await fs.readFile(path, 'utf-8');176return { path, content, size: content.length };177},178toModelOutput: (result) => {179// Only send truncated content to model180return {181path: result.path,182content: result.content.slice(0, 5000),183truncated: result.content.length > 5000184};185}186});187```188189## Best Practices1901911. **Descriptive Names**: Tool names should clearly indicate their function1922. **Comprehensive Descriptions**: Include usage examples in tool descriptions1933. **Reasonable Defaults**: Provide sensible defaults for optional parameters1944. **Idempotency**: Design tools to be safely re-executable when possible1955. **Timeout Handling**: Implement timeouts for external operations1966. **Rate Limiting**: Protect against runaway tool execution1977. **Logging**: Log all tool invocations for debugging and audit198199