workflow-orchestration-patterns
它能做什么
这个工具可以帮你组织需要分步骤完成的复杂流程,即使这些流程耗时很长或涉及多个系统。即使中途出错,它也能确保一切正常运转。
适用场景
- ✓组织涉及库存、付款和发货的客户订单流程。
- ✓管理可能要花好几天的长时间文档审批流程。
- ✓协调系统的多个部分,确保一笔交易要么完整完成,要么彻底失败。
技能链接
https://github.com/wshobson/agents/blob/main/plugins/backend-development/skills/workflow-orchestration-patterns/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我怎样组织一个酒店预订流程,包括检查房态、确认房间和处理付款?”
每周 5 个新技能,1 分钟读完。
工作原理
它的工作方式是定义一个主“工作流”,由它来协调调用多个较小的“活动”。如果某个活动失败了,工作流可以重试,或者按照恢复方案执行,并且会自动保存进度。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Workflow Orchestration Patterns
Master workflow orchestration architecture with Temporal, covering fundamental design decisions, resilience patterns, and best practices for building reliable distributed systems.
When to Use Workflow Orchestration
Ideal Use Cases (Source: docs.temporal.io)
- Multi-step processes spanning machines/services/databases
- Distributed transactions requiring all-or-nothing semantics
- Long-running workflows (hours to years) with automatic state persistence
- Failure recovery that must resume from last successful step
- Business processes: bookings, orders, campaigns, approvals
- Entity lifecycle management: inventory tracking, account management, cart workflows
- Infrastructure automation: CI/CD pipelines, provisioning, deployments
- Human-in-the-loop systems requiring timeouts and escalations
When NOT to Use
- Simple CRUD operations (use direct API calls)
- Pure data processing pipelines (use Airflow, batch processing)
- Stateless request/response (use standard APIs)
- Real-time streaming (use Kafka, event processors)
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
Workflow Design
- Keep workflows focused - Single responsibility per workflow
- Small workflows - Use child workflows for scalability
- Clear boundaries - Workflow orchestrates, activities execute
- Test locally - Use time-skipping test environment
Activity Design
- Idempotent operations - Safe to retry
- Short-lived - Seconds to minutes, not hours
- Timeout configuration - Always set timeouts
- Heartbeat for long tasks - Report progress
- Error handling - Distinguish retryable vs non-retryable
Common Pitfalls
Workflow Violations:
- Using
datetime.now()instead ofworkflow.now() - Threading or async operations in workflow code
- Calling external APIs directly from workflow
- Non-deterministic logic in workflows
Activity Mistakes:
- Non-idempotent operations (can't handle retries)
- Missing timeouts (activities run forever)
- No error classification (retry validation errors)
- Ignoring payload limits (2MB per argument)
Operational Considerations
Monitoring:
- Workflow execution duration
- Activity failure rates
- Retry attempts and backoff
- Pending workflow counts
Scalability:
- Horizontal scaling with workers
- Task queue partitioning
- Child workflow decomposition
- Activity batching when appropriate
Additional Resources
Official Documentation:
- Temporal Core Concepts: docs.temporal.io/workflows
- Workflow Patterns: docs.temporal.io/evaluate/use-cases-design-patterns
- Best Practices: docs.temporal.io/develop/best-practices
- Saga Pattern: temporal.io/blog/saga-pattern-made-easy
Key Principles:
- Workflows = orchestration, Activities = external calls
- Determinism is non-negotiable for workflows
- Idempotency is critical for activities
- State preservation is automatic
- Design for failure and recovery
常见问题
什么是“工作流”和“活动”?
“工作流”是主配方,规定了按什么顺序做什么事。“活动”则是工作流指示执行的具体任务,比如“检查库存”或“处理付款”。
为什么工作流代码必须是“确定性”的?
“确定性”意味着无论运行多少次,工作流都会以完全相同的顺序做完全相同的事。这很关键,因为这样它才能在出错后恢复,从中断处继续,而不会出问题。
什么情况下不应该使用它?
简单的任务,比如数据的增删改查(CRUD),或者快速的数据处理,都不必使用它。它最适合需要故障恢复的长时间流程,或者涉及多个步骤和系统的流程。
详情
作者的原始描述
Design durable workflows with Temporal for distributed systems. Covers workflow vs activity separation, saga patterns, state management, and determinism constraints. Use when building long-running processes, distributed transactions, or microservice orchestration.
repo: wshobson/agents
热度
- GitHub 星标
- 41k
- 排名
- #6643
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …