Convex Agents Tools
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:
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
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
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
More from sstobo/convex-skills
betterauth-tanstack-convex
Step-by-step guide for setting up Better Auth authentication with Convex and TanStack Start. This skill should be used when configuring authentication in a Convex + TanStack Start project, troubleshooting auth issues, or implementing sign up/sign in/sign out flows. Covers installation, environment variables, SSR authentication, route handlers, and the expectAuth pattern.
68convex-tanstack
Comprehensive guide for building full-stack applications with Convex and TanStack Start. This skill should be used when working on projects that use Convex as the backend database with TanStack Start (React meta-framework). Covers schema design, queries, mutations, actions, authentication with Better Auth, routing, data fetching patterns, SSR, file storage, scheduling, AI agents, and frontend patterns. Use this when implementing features, debugging issues, or needing guidance on Convex + TanStack Start best practices.
42convex-queries
This skill should be used when implementing Convex query functions. It provides comprehensive guidelines for defining, registering, calling, and optimizing queries, including pagination, full text search, and indexing patterns.
24convex-actions-general
This skill should be used when working with Convex actions, HTTP endpoints, validators, schemas, environment variables, scheduling, file storage, and TypeScript patterns. It provides comprehensive guidelines for function definitions, API design, database limits, and advanced Convex features.
23convex-mutations
This skill should be used when implementing Convex mutation functions. It provides comprehensive guidelines for defining, registering, calling, and scheduling mutations, including database operations, transactions, and scheduled job patterns.
21convex agents rag
Implements Retrieval-Augmented Generation (RAG) patterns to enhance agents with custom knowledge bases. Use this when agents need to search through documents, retrieve context from a knowledge base, or ground responses in specific data.
21