home / skills / sstobo / convex-skills / convex-agents-workflows

convex-agents-workflows skill

/convex-agents-workflows

This skill orchestrates durable, multi-step agent workflows with automatic retries and recovery, ensuring idempotent operations across server restarts.

npx playbooks add skill sstobo/convex-skills --skill convex-agents-workflows

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.0 KB
---
name: "Convex Agents Workflows"
description: "Orchestrates multi-step agent operations with durable execution, automatic retries, and recovery from failures. Use this for complex workflows that need to survive server restarts or coordinate multiple agents."
---

## Purpose

Provides durable, reliable execution of complex agent workflows. Workflows ensure multi-step operations complete reliably, survive server failures, and maintain idempotency.

## When to Use This Skill

- Building multi-step agent operations (research → analysis → report)
- Coordinating multiple agents working together
- Long-running operations that need to survive server restarts
- Ensuring idempotency (no duplicate work even if retried)
- Complex applications requiring durable execution guarantees

## Setup

Configure Workflow component in `convex.config.ts`:

```typescript
import { defineApp } from "convex/server";
import agent from "@convex-dev/agent/convex.config";
import workflow from "@convex-dev/workflow/convex.config";

const app = defineApp();
app.use(agent);
app.use(workflow);

export default app;
```

## Define a Workflow

```typescript
import { WorkflowManager } from "@convex-dev/workflow";

const workflow = new WorkflowManager(components.workflow);

export const simpleAgentFlow = workflow.define({
  id: "simple-flow",
  args: { userId: v.string(), prompt: v.string() },
  handler: async (step, { userId, prompt }) => {
    // Step 1: Create thread
    const { threadId } = await step.runMutation(
      internal.agents.createThreadMutation,
      { userId }
    );

    // Step 2: Generate response
    const response = await step.runAction(
      internal.agents.generateTextAction,
      { threadId, prompt }
    );

    return response;
  },
});
```

## Multi-Agent Workflows

Orchestrate multiple agents:

```typescript
export const researchFlow = workflow.define({
  id: "research",
  args: { topic: v.string(), userId: v.string() },
  handler: async (step, { topic, userId }) => {
    const { threadId: researchId } = await step.runMutation(
      internal.agents.createThreadMutation,
      { userId, title: `Research: ${topic}` }
    );

    const research = await step.runAction(
      internal.agents.generateTextAction,
      { threadId: researchId, prompt: `Research: ${topic}` }
    );

    const { threadId: analysisId } = await step.runMutation(
      internal.agents.createThreadMutation,
      { userId, title: `Analysis: ${topic}` }
    );

    const analysis = await step.runAction(
      internal.agents.generateTextAction,
      { threadId: analysisId, prompt: `Analyze: ${research}` }
    );

    return { research, analysis };
  },
});
```

## Key Principles

- **Durability**: Workflows survive server restarts
- **Idempotency**: Same workflow can be safely retried
- **Atomicity**: Each step either completes fully or retries
- **Composability**: Steps can call other workflows or actions

## Next Steps

- See **fundamentals** for agent setup
- See **tools** for agents that call functions
- See **context** for workflow-aware context

Overview

This skill orchestrates multi-step agent workflows with durable execution, automatic retries, and failure recovery. It guarantees idempotent, long-running operations that survive server restarts and coordinate multiple agents. Use it to build reliable, composable pipelines where each step is atomic and repeatable.

How this skill works

The workflow manager defines named workflows that accept typed arguments and run a handler composed of ordered steps. Each step can run actions, mutations, or call other workflows; the system records progress durably so execution can resume after crashes. Automatic retry and idempotency semantics ensure steps either complete fully or safely retry without duplicating work.

When to use it

  • Coordinating multiple agents to complete a single task (e.g., research → analysis → report)
  • Long-running workflows that must survive server restarts or deployments
  • Ensuring idempotent execution when operations can be retried
  • Composing complex logic where each step must be atomic and recoverable
  • Orchestrating workflows that call external actions, database mutations, or other workflows

Best practices

  • Define clear, small steps so failures and retries are localized
  • Make handlers idempotent—assume a step can run more than once safely
  • Use typed args and validation to catch errors early
  • Persist essential outputs with mutations so resumed runs have required state
  • Call other workflows for reusable subroutines and to keep top-level flows simple

Example use cases

  • Research workflow: spawn a research agent, collect findings, then run an analysis agent and combine results
  • Customer onboarding: sequence verification, profile creation, and welcome message delivery with retries on transient failures
  • Data processing pipeline: ingest → normalize → enrich → store, with each stage able to resume after interruption
  • Coordinated multi-agent task: delegate subtasks to different agents, aggregate their outputs, and produce a final report
  • Long-running human-in-the-loop tasks where a workflow waits for external input and resumes when available

FAQ

How does the system avoid duplicate work on retries?

Workflows are durable and support idempotency: steps should persist key outputs and operations are designed so re-running a step does not duplicate side effects.

Can a workflow call another workflow?

Yes. Workflows are composable: a step can invoke other workflows to reuse logic and simplify orchestration.