ワンクリックで
workflow-engine
工作流引擎 - 通用规则引擎,用于编排跨系统自动化流程(邮件→AI 意图识别→规则匹配→动作执行)。支持事件驱动、规则匹配、动作编排、分支循环控制流。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
工作流引擎 - 通用规则引擎,用于编排跨系统自动化流程(邮件→AI 意图识别→规则匹配→动作执行)。支持事件驱动、规则匹配、动作编排、分支循环控制流。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
动态定价引擎,铜价/数量阶梯/客户等级/汇率计算
审批流程引擎,报价审批 + 异常处理
邮件智能回复系统,自动识别客户意图并生成个性化回复草稿
订单管理系统,状态跟踪 + 客户通知
生成专业收款通知,支持 HTML/PDF 格式,自动集成银行账户信息
Use when a sales workflow needs single-company customer background research, buyer/contact discovery, email verification, lead-fit scoring, source-backed outreach angles, or company dossier generation.
| name | workflow-engine |
| description | 工作流引擎 - 通用规则引擎,用于编排跨系统自动化流程(邮件→AI 意图识别→规则匹配→动作执行)。支持事件驱动、规则匹配、动作编排、分支循环控制流。 |
workflow-engine 是一个通用的工作流规则引擎,用于编排跨系统自动化流程。
核心能力:
适用场景:
/path/to/your/.openclaw/workspace/monorepo/super-sales-agent/skills/workflow-engine/
cd /path/to/your/.openclaw/workspace/monorepo/super-sales-agent/skills/workflow-engine
npm install
ajv - JSON Schema 验证config/rules/*.json - 规则配置文件
示例: config/rules/email-rules.json
[
{
"id": "vip-inquiry-auto-reply",
"name": "VIP 客户询盘自动回复",
"priority": 90,
"enabled": true,
"trigger": {
"event_type": "email_received",
"conditions": {
"type": "all",
"checks": [
{"field": "payload.intent", "operator": "equals", "value": "inquiry"},
{"field": "payload.customer.tier", "operator": "equals", "value": "vip"}
]
}
},
"actions": [
{"type": "generate_quotation", "config": {...}},
{"type": "send_email", "config": {...}},
{"type": "create_okki_trail", "config": {...}}
]
}
]
# .env 文件
WORKFLOW_RULES_DIR=./config/rules
WORKFLOW_SCHEMAS_DIR=./schemas
WORKFLOW_DRY_RUN=false
const { RuleEngine } = require('./lib/rule-engine');
// 创建引擎实例
const engine = new RuleEngine({
rulesDir: './config/rules',
schemasDir: './schemas',
dryRun: false
});
// 初始化(加载规则)
await engine.initialize();
// 处理事件
const event = {
type: 'email_received',
payload: {
intent: 'inquiry',
customer: { tier: 'vip', id: 'okki_123' },
from: 'vip@customer.com'
}
};
const result = await engine.handleEvent(event);
console.log(`Matched: ${result.matched}, Executed: ${result.executed}`);
# 运行规则引擎
node cli/workflow-cli.js run --event event.json
# 验证规则配置
node cli/workflow-cli.js validate --rules config/rules/
# 列出已加载的规则
node cli/workflow-cli.js list-rules
# Dry-run 测试
node cli/workflow-cli.js run --event event.json --dry-run
// 在 OpenClaw Agent 中使用
const { RuleEngine } = require('workflow-engine');
const engine = new RuleEngine();
await engine.initialize();
// 监听邮件事件
engine.on('event:received', (event) => {
if (event.type === 'email_received') {
// 自动处理邮件
}
});
触发规则执行的业务事件。
5 种核心事件类型:
| 事件类型 | 说明 | 触发场景 |
|---|---|---|
email_received | 收到邮件 | IMAP 收到新邮件 |
quotation_sent | 报价单已发送 | 报价单生成并发送 |
customer_created | 客户创建 | OKKI 创建新客户 |
order_updated | 订单更新 | OKKI 订单状态变更 |
trail_created | 跟进记录创建 | OKKI 创建跟进记录 |
定义何时触发和执行什么动作。
规则结构:
{
"id": "rule-id",
"name": "规则名称",
"priority": 50,
"enabled": true,
"trigger": {
"event_type": "email_received",
"conditions": {...}
},
"actions": [...]
}
规则匹配后执行的具体操作。
8 种核心动作类型:
| 动作类型 | 说明 | 配置参数 |
|---|---|---|
send_email | 发送邮件 | to, template, variables |
create_okki_trail | 创建 OKKI 跟进 | customer_id, trail_type, content |
generate_quotation | 生成报价单 | customer_id, template, items |
update_customer | 更新客户 | customer_id, fields |
call_api | 调用 API | url, method, headers, body |
wait | 等待 | duration_minutes |
branch | 分支 | condition, true_actions, false_actions |
loop | 循环 | items, action |
支持的运算符:
| 运算符 | 说明 | 示例 |
|---|---|---|
equals | 等于 | {"field": "payload.intent", "operator": "equals", "value": "inquiry"} |
not_equals | 不等于 | {"field": "payload.tier", "operator": "not_equals", "value": "vip"} |
greater_than | 大于 | {"field": "payload.amount", "operator": "greater_than", "value": 10000} |
less_than | 小于 | {"field": "payload.amount", "operator": "less_than", "value": 1000} |
contains | 包含 | {"field": "payload.subject", "operator": "contains", "value": "urgent"} |
regex | 正则匹配 | {"field": "payload.from", "operator": "regex", "value": ".*@vip\\.com$"} |
exists | 字段存在 | {"field": "payload.attachments", "operator": "exists", "value": true} |
{
"type": "all", // AND 逻辑
"checks": [
{"field": "payload.intent", "operator": "equals", "value": "inquiry"},
{"field": "payload.customer.tier", "operator": "equals", "value": "vip"}
]
}
{
"type": "any", // OR 逻辑
"checks": [
{"field": "payload.amount", "operator": "greater_than", "value": 50000},
{"field": "payload.customer.tier", "operator": "equals", "value": "vip"}
]
}
${payload.customer.email}
${context.last_contact_days}
${actions[0].quotation_no}
daysSince("2026-01-01") // 计算天数
contains("Hello", "ell") // 检查包含
matches("abc123", "\\d+") // 正则匹配
{
"id": "vip-inquiry-auto-reply",
"name": "VIP 客户询盘自动回复",
"priority": 90,
"enabled": true,
"trigger": {
"event_type": "email_received",
"conditions": {
"type": "all",
"checks": [
{"field": "payload.intent", "operator": "equals", "value": "inquiry"},
{"field": "payload.customer.tier", "operator": "equals", "value": "vip"}
]
}
},
"actions": [
{
"type": "generate_quotation",
"config": {
"customer_id": "${payload.customer.id}",
"template": "vip-standard"
}
},
{
"type": "send_email",
"config": {
"to": "${payload.from}",
"template": "vip-inquiry-ack"
}
},
{
"type": "create_okki_trail",
"config": {
"customer_id": "${payload.customer.id}",
"trail_type": 105,
"content": "VIP 客户询盘,已自动生成报价单"
}
}
]
}
{
"id": "quote-followup-sequence",
"name": "报价单跟进序列",
"priority": 70,
"enabled": true,
"trigger": {
"event_type": "quotation_sent",
"conditions": {
"type": "all",
"checks": [
{"field": "payload.amount", "operator": "greater_than", "value": 10000}
]
}
},
"actions": [
{
"type": "wait",
"config": {"duration_minutes": 4320} // 3 天
},
{
"type": "branch",
"config": {
"condition": "${payload.customer.replied} == false",
"true_actions": [
{
"type": "send_email",
"config": {
"to": "${payload.customer.email}",
"template": "quote-followup-1"
}
}
]
}
}
]
}
npm test
bash test/e2e.sh
npm run test:coverage
检查:
enabled: true)// 调试
console.log(engine.getRules());
const matched = engine.matchRules(event);
console.log('Matched rules:', matched);
检查:
const log = engine.getExecutionLog();
console.log(log);
const engine = new RuleEngine({
enableCache: true,
cacheMaxSize: 1000
});
// 批量处理事件
const events = [...];
const results = await Promise.all(
events.map(event => engine.handleEvent(event))
);
schemas/event-schema.json 添加定义lib/actions/xxx-action.jsexecute(config, context) 方法action-schema.json 添加定义版本: 1.0.0
最后更新: 2026-04-02
维护者: Super Sales Agent Team