关于 Convex Agents Workflows
Convex Agents Workflows 是用于在 Convex 中持久执行多步骤 Agent 流程的技能,帮助开发者协调多个 Agent,并使流程可安全重试且能应对服务器重启。
主要功能
- 01持久执行多步骤流程
- 02通过幂等性安全重试
- 03工作流步骤具备原子性
- 04组合步骤、操作或工作流
- 05协调多个 Agent
适用场景
- 01运行研究、分析和报告流程
- 02协调多个 Agent 的工作
- 03服务器重启后继续长时间操作
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ sstobo/ convex-skills --skill convex-agents-workflows安装后在 Claude Code 中输入/convex-agents-workflows确认已加载。
详细介绍
用途
为复杂的 Agent 工作流提供持久、可靠的执行。工作流可确保多步操作可靠完成、在服务故障后仍能继续,并保持幂等性。
何时使用此技能
- 构建多步 Agent 操作(研究 → 分析 → 报告)
- 协调多个 Agent 协同工作
- 需要在服务重启后仍能继续的长时间运行操作
- 确保幂等性(即使重试也不会产生重复工作)
- 需要持久执行保证的复杂应用
设置
在 convex.config.ts 中配置 Workflow 组件:
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;
},
});
多 Agent 工作流
编排多个 Agent:
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 };
},
});
核心原则
- 持久性:工作流在服务重启后仍能继续
- 幂等性:同一工作流可以安全重试
- 原子性:每个步骤要么完全完成,要么重试
- 可组合性:步骤可以调用其他工作流或操作
后续步骤
- 查看 fundamentals 了解 Agent 设置
- 查看 tools 了解会调用函数的 Agent
- 查看 context 了解具备工作流感知能力的上下文
评论
支持 Markdown