home / skills / sstobo / convex-skills / 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-workflowsReview the files below or copy the command above to add this skill to your agents.
---
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
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.
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.
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.