mcpField
C
Convex Agents Threads

Convex Agents Threads

github.com/sstoboAgent workflows24197 installsUpdated 40w ago
Repository

About Convex Agents Threads

Convex Agents Threads is a skill for developers organizing agent conversations with Convex. It covers creating, continuing, listing, and deleting threads, with user associations and metadata for organization.

Key features

  1. 01Create conversation threads
  2. 02Continue existing threads
  3. 03List threads by user
  4. 04Track thread metadata
  5. 05Delete threads synchronously or asynchronously

Use cases

  1. 01Start conversations for users
  2. 02Resume an existing conversation
  3. 03Find a user's conversation history
  4. 04Remove completed or outdated threads

Install

Copy the command and run it in a terminal.

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

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

Details

From the project README

Purpose

Threads group related messages into organized, linear conversation histories. Every message in the Agent component belongs to a thread.

When to Use This Skill

  • Creating new conversations for users
  • Managing conversation history and metadata
  • Continuing existing conversations
  • Querying message history within a thread
  • Organizing conversations by user or context
  • Cleaning up old or completed conversations

Create a Thread

import { createThread } from "@convex-dev/agent";

export const startNewThread = mutation({
  args: { userId: v.string() },
  handler: async (ctx, { userId }) => {
    const threadId = await createThread(ctx, components.agent, {
      userId,
      title: "New Conversation",
      summary: "Conversation summary",
    });
    return { threadId };
  },
});

Continue a Thread (Actions Only)

In actions, get a thread object:

export const continueConversation = action({
  args: { threadId: v.string(), prompt: v.string() },
  handler: async (ctx, { threadId, prompt }) => {
    const { thread } = await myAgent.continueThread(ctx, { threadId });

    const metadata = thread.getMetadata();
    const response = await thread.generateText({ prompt });

    return response.text;
  },
});

List Threads for a User

export const getUserThreads = query({
  args: { userId: v.string(), paginationOpts: paginationOptsValidator },
  handler: async (ctx, { userId, paginationOpts }) => {
    return await ctx.runQuery(
      components.agent.threads.listThreadsByUserId,
      { userId, paginationOpts }
    );
  },
});

Delete Threads

// Async deletion (non-blocking)
await myAgent.deleteThreadAsync(ctx, { threadId });

// Sync deletion (atomic)
await myAgent.deleteThreadSync(ctx, { threadId });

// Delete all for user
await ctx.runMutation(components.agent.users.deleteAllForUserId, { userId });

Key Principles

  • User association: Threads associated with userId
  • Metadata: Use title and summary for organization
  • Message ordering: Messages within thread maintain order
  • Async vs sync: Use async for non-blocking, sync for atomic ops

Next Steps

  • See messages for saving and retrieving messages
  • See fundamentals for basic agent setup

Comments

Markdown supported