home / skills / sstobo / convex-skills / convex-agents-tools
This skill enables agents to call Convex tools, external APIs, and databases to fetch data, perform actions, and automate workflows.
npx playbooks add skill sstobo/convex-skills --skill convex-agents-toolsReview the files below or copy the command above to add this skill to your agents.
---
name: "Convex Agents Tools"
description: "Enables agents to call external functions, APIs, and database operations through tool definitions. Use this when agents need to fetch data, perform actions, or integrate with external services while maintaining clean separation."
---
## Purpose
Equips agents with the ability to take actions beyond text generation. Tools allow agents to call Convex functions, external APIs, and complex operations.
## When to Use This Skill
- Agents need to query or modify database data
- Integrating with external APIs
- Creating human-in-the-loop workflows
- Agents autonomously deciding what actions to take
- Chaining tool calls for multi-step operations
## Define Tools
Create Convex-aware tools:
```typescript
import { createTool } from "@convex-dev/agent";
import { z } from "zod";
export const getUserDataTool = createTool({
description: "Fetch user information by email",
args: z.object({
email: z.string().email().describe("The user's email address"),
}),
handler: async (ctx, { email }): Promise<string> => {
const user = await ctx.runQuery(api.users.getUserByEmail, { email });
return user ? JSON.stringify(user) : "User not found";
},
});
```
## Configure Agent with Tools
```typescript
const agentWithTools = new Agent(components.agent, {
name: "Database Agent",
languageModel: openai.chat("gpt-4o-mini"),
tools: {
getUserData: getUserDataTool,
},
maxSteps: 5, // Allow tool calls
});
```
## Enable Automatic Tool Calling
```typescript
export const autonomousAgent = action({
args: { threadId: v.string(), request: v.string() },
handler: async (ctx, { threadId, request }) => {
const { thread } = await agentWithTools.continueThread(ctx, { threadId });
const result = await thread.generateText(
{ prompt: request },
{ maxSteps: 10 } // Allow up to 10 tool calls
);
return result.text;
},
});
```
## Key Principles
- **Use Zod for validation**: `.describe()` on fields helps LLMs understand parameters
- **Explicit return types**: Always annotate handler return types
- **Automatic history**: Tool calls and results saved automatically in thread
- **Context binding**: Create tools inside actions where you have access to userId, etc.
## Next Steps
- See **fundamentals** for agent setup
- See **workflows** for orchestrating multi-step operations
- See **context** for tool-aware context management
This skill equips agents to call external functions, APIs, and database operations through explicit tool definitions. It provides a clean separation between language generation and actionable operations so agents can fetch data, make updates, or orchestrate multi-step workflows securely and reliably.
Define Convex-aware tools with typed arguments and handlers that run queries, call APIs, or perform side effects. Register those tools with an agent and enable automatic tool calling so the agent can choose and invoke tools during generation, with calls and results automatically recorded in the conversation thread.
How do tools get access to database and API context?
Create and register tools inside Convex action handlers where the context (ctx) exposes query and action functions and user-specific data.
How does the agent choose which tool to call?
Tools include descriptions and typed arguments; the agent uses that metadata during generation and can be allowed to call tools automatically when maxSteps permits.
How are tool calls recorded?
Tool calls and their results are saved automatically in the agent thread history so subsequent reasoning can reference past actions.