mcpField
C
Convex Agents Tools

Convex Agents Tools

github.com/sstoboAgent workflows24200 installsUpdated 40w ago
Repository

About Convex Agents Tools

Convex Agents Tools is a skill for building Convex-aware tools that let agents call Convex functions, external APIs, and multi-step operations. It is intended for developers adding validated, optionally autonomous actions to agents, with tool history saved in the thread.

Key features

  1. 01Define Convex-aware tools
  2. 02Validate arguments with Zod
  3. 03Call external APIs
  4. 04Save tool calls in thread
  5. 05Enable automatic multi-step calls

Use cases

  1. 01Query or modify database data
  2. 02Connect agents to external APIs
  3. 03Build human-in-the-loop workflows
  4. 04Chain operations across tool calls

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/sstobo/convex-skills --skill convex-agents-tools

After installing, type/convex-agents-toolsin Claude Code to confirm it loaded.

Details

From the project README

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

Comments

Markdown supported