// "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."
| 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. |
Provides durable, reliable execution of complex agent workflows. Workflows ensure multi-step operations complete reliably, survive server failures, and maintain idempotency.
Configure Workflow component in convex.config.ts:
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;
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;
},
});
Orchestrate multiple agents:
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 };
},
});