clawflows
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseclawflows
Clawflows
Purpose
用途
This skill automates workflows in OpenClaw by defining multi-step task chains, incorporating conditional logic, triggers, and scheduling to streamline complex operations.
该技能通过定义多步骤任务链、整合条件逻辑、触发器和调度功能,实现OpenClaw中的工作流自动化,从而简化复杂操作。
When to Use
适用场景
Use this skill for repetitive task sequences, like processing data pipelines, conditional decision-making (e.g., if a file exists, then execute), event-driven triggers (e.g., on API call), or scheduled jobs (e.g., daily reports). Apply it in scenarios requiring orchestration, such as integrating multiple OpenClaw tools or external services.
当你需要处理重复性任务序列时使用该技能,例如数据管道处理、条件决策(如:如果文件存在则执行)、事件驱动触发器(如:API调用触发)或定时任务(如:每日报表)。适用于需要编排的场景,比如整合多个OpenClaw工具或外部服务。
Key Capabilities
核心功能
- Define task chains: Specify steps in a JSON config, e.g., {"steps": [{"name": "step1", "action": "run_script"}, {"name": "step2", "action": "send_email"}]}
- Conditional logic: Use if-else in configs, e.g., {"condition": "if status == 'success' then next: step2 else: abort"}
- Triggers: Set event-based triggers like webhooks or file changes, e.g., via {"trigger": {"type": "http", "endpoint": "/webhook"}}
- Scheduling: Use cron-style schedules, e.g., {"schedule": "0 0 * * *"} for midnight daily runs
- Error recovery: Built-in retries for failed steps, configurable per step
- 定义任务链:在JSON配置中指定步骤,例如:{"steps": [{"name": "step1", "action": "run_script"}, {"name": "step2", "action": "send_email"}]}
- 条件逻辑:在配置中使用if-else语句,例如:{"condition": "if status == 'success' then next: step2 else: abort"}
- 触发器:设置基于事件的触发器,如webhook或文件变更,例如:通过{"trigger": {"type": "http", "endpoint": "/webhook"}}
- 调度功能:使用cron风格的调度表达式,例如:{"schedule": "0 0 * * *"} 表示每日午夜运行
- 错误恢复:为失败步骤提供内置重试机制,可按步骤配置
Usage Patterns
使用模式
To create and run a workflow, start by defining a config file (JSON/YAML), then use CLI or API to execute. For simple flows, use CLI directly; for programmatic use, integrate via API. Always set environment variables for authentication, e.g., export CLAWFLOWS_API_KEY=$SERVICE_API_KEY. Test flows in isolation before scheduling. Common pattern: Load config, validate, run, and monitor output.
要创建并运行工作流,首先定义配置文件(JSON/YAML格式),然后使用CLI或API执行。对于简单工作流,直接使用CLI;对于程序化使用场景,通过API集成。请务必设置环境变量进行身份验证,例如:export CLAWFLOWS_API_KEY=$SERVICE_API_KEY。在调度前单独测试工作流。常见流程:加载配置、验证、运行、监控输出。
Common Commands/API
常用命令/API
Use the OpenClaw CLI for quick operations:
- Create a flow:
clawflows create --name myworkflow --config path/to/config.json --cluster community - Run a flow: (outputs status JSON)
clawflows run --flow-id 123 --env VAR=VALUE - Schedule a flow:
clawflows schedule --flow-id 123 --cron "0 9 * * *" --trigger-type http - API endpoints: POST /api/workflows to create (body: {"name": "myworkflow", "steps": [...] }), GET /api/workflows/{id} to retrieve Code snippet for API call in Python:
python
import requests
headers = {"Authorization": f"Bearer {os.environ['CLAWFLOWS_API_KEY']}"}
response = requests.post("https://api.openclaw.com/api/workflows", headers=headers, json={"name": "test", "steps": [{"action": "echo hello"}]})
print(response.json())Config format example (JSON):
{
"steps": [
{"name": "step1", "action": "run_command", "command": "ls -l"},
{"name": "step2", "condition": "step1.success", "action": "log_message", "message": "Success!"}
]
}
使用OpenClaw CLI执行快速操作:
- 创建工作流:
clawflows create --name myworkflow --config path/to/config.json --cluster community - 运行工作流:(输出状态JSON)
clawflows run --flow-id 123 --env VAR=VALUE - 调度工作流:
clawflows schedule --flow-id 123 --cron "0 9 * * *" --trigger-type http - API端点:使用POST /api/workflows创建工作流(请求体:{"name": "myworkflow", "steps": [...] }),使用GET /api/workflows/{id}获取工作流信息 Python API调用代码片段:
python
import requests
headers = {"Authorization": f"Bearer {os.environ['CLAWFLOWS_API_KEY']}"}
response = requests.post("https://api.openclaw.com/api/workflows", headers=headers, json={"name": "test", "steps": [{"action": "echo hello"}]})
print(response.json())配置格式示例(JSON):
{
"steps": [
{"name": "step1", "action": "run_command", "command": "ls -l"},
{"name": "step2", "condition": "step1.success", "action": "log_message", "message": "Success!"}
]
}
Integration Notes
集成说明
Integrate clawflows with other OpenClaw skills by referencing them in step actions, e.g., {"action": "call_skill", "skill_id": "another_skill"}. For authentication, use env vars like $CLAWFLOWS_API_KEY for API requests. When combining with external tools, map outputs via JSON paths, e.g., in config: {"input_mapping": {"var1": "$.output.data"}}. Ensure compatibility by specifying cluster in commands, e.g., --cluster community. For webhooks, expose an endpoint that triggers flows via POST /api/triggers/{flow-id}.
通过在步骤动作中引用其他OpenClaw技能来集成clawflows,例如:{"action": "call_skill", "skill_id": "another_skill"}。身份验证方面,API请求使用$CLAWFLOWS_API_KEY等环境变量。与外部工具结合时,通过JSON路径映射输出,例如在配置中:{"input_mapping": {"var1": "$.output.data"}}。在命令中指定集群(如--cluster community)以确保兼容性。对于webhooks,暴露一个端点,通过POST /api/triggers/{flow-id}触发工作流。
Error Handling
错误处理
Common errors include authentication failures (HTTP 401), invalid configs (e.g., syntax errors in JSON), or step timeouts. To handle: Check for $CLAWFLOWS_API_KEY before running; use to catch issues early. In code, wrap API calls in try-except blocks:
clawflows validate --config path/to/config.jsonpython
try:
response = requests.post("https://api.openclaw.com/api/workflows", headers=headers, json=data)
response.raise_for_status()
except requests.exceptions.HTTPError as e:
print(f"Error: {e.response.status_code} - {e.response.text}")For runtime errors, configure retries in config, e.g., {"step": {"action": "...", "retries": 3, "timeout": 30}}. Monitor logs with and abort on critical failures using conditional steps.
clawflows logs --flow-id 123常见错误包括身份验证失败(HTTP 401)、无效配置(如JSON语法错误)或步骤超时。处理方法:运行前检查$CLAWFLOWS_API_KEY是否存在;使用提前发现问题。在代码中,将API调用包裹在try-except块中:
clawflows validate --config path/to/config.jsonpython
try:
response = requests.post("https://api.openclaw.com/api/workflows", headers=headers, json=data)
response.raise_for_status()
except requests.exceptions.HTTPError as e:
print(f"Error: {e.response.status_code} - {e.response.text}")对于运行时错误,在配置中设置重试机制,例如:{"step": {"action": "...", "retries": 3, "timeout": 30}}。使用监控日志,并通过条件步骤在发生严重失败时终止工作流。
clawflows logs --flow-id 123Concrete Usage Examples
具体使用示例
Example 1: Automate a data backup flow. Create a config file: {"steps": [{"name": "backup", "action": "run_command", "command": "rsync /data/ backup-server:"}, {"condition": "backup.success", "action": "send_email", "to": "admin@example.com", "subject": "Backup complete"}]} Then run: and schedule:
Example 2: Trigger a workflow on file change. Define: {"trigger": {"type": "file_watch", "path": "/monitored/dir"}, "steps": [{"action": "process_file", "file": "$.trigger.file"}]} Execute via API: POST /api/workflows with the config, then monitor with .
clawflows create --name backupflow --config backup.jsonclawflows schedule --flow-id 456 --cron "0 2 * * *"clawflows run --flow-id 789 --watch示例1:自动化数据备份工作流。创建配置文件:{"steps": [{"name": "backup", "action": "run_command", "command": "rsync /data/ backup-server:"}, {"condition": "backup.success", "action": "send_email", "to": "admin@example.com", "subject": "Backup complete"}]} 然后运行: 并设置调度:
示例2:文件变更触发工作流。定义配置:{"trigger": {"type": "file_watch", "path": "/monitored/dir"}, "steps": [{"action": "process_file", "file": "$.trigger.file"}]} 通过API执行:将配置作为请求体发送POST /api/workflows,然后使用监控。
clawflows create --name backupflow --config backup.jsonclawflows schedule --flow-id 456 --cron "0 2 * * *"clawflows run --flow-id 789 --watchGraph Relationships
关联关系
- Relates to: openclaw-core (for basic task execution), openclaw-triggers (for event handling), community-cluster (as part of the ecosystem)
- Depends on: authentication services for API access
- Integrates with: external APIs via steps, e.g., for data fetching or notifications
- 关联:openclaw-core(用于基础任务执行)、openclaw-triggers(用于事件处理)、community-cluster(作为生态系统的一部分)
- 依赖:API访问的身份验证服务
- 集成:通过步骤与外部API集成,例如数据获取或通知