计划验证器

Other

计划验证器 — 在执行前验证代理计划,防止虚假计划失败。 使用场景:(1) 验证多步计划,(2) 检查工具可用性,(3) 验证权限和依赖,(4) 确保计划执行前的可行性。

Install

openclaw skills install planning-validator-zh

计划验证器

在执行前验证代理计划,防止因对能力的不切实际假设而导致的失败。

问题:虚假计划

症状:
├── 理论上完美的计划
├── 假设可以访问未经验证的工具/API
├── 执行时失败(无回退)
├── 多代理未协调
└── 执行前无验证

解决方案

1. 多代理验证器

class PlanningValidator:
    validation_steps = [
        '检查工具可用性',
        '检查权限', 
        '检查依赖',
        '验证可行性',
        '确认用户'
    ]
    
    def validate_plan(plan):
        for step in validation_steps:
            if not check(step, plan):
                return {'valid': False, 'failed_at': step}
        return {'valid': True}

2. 明确的工具模式

tool_schemas = {
    'telegram_send': {
        'capabilities': ['send_text', 'send_audio', 'send_document'],
        'limitations': ['no_video_call', 'max_10MB'],
        'required_auth': ['bot_token']
    },
    'qdrant_query': {
        'capabilities': ['search', 'insert', 'delete'],
        'limitations': ['no_update'],
        'required_auth': ['qdrant_key']
    }
}

def verify_tool_capabilities(tool, required_action):
    if required_action not in tool_schemas[tool]['capabilities']:
        return False
    return True

3. 约束验证

def verify_constraints(plan):
    constraints = {
        '时间限制': 300,  # 最多5分钟
        '重试限制': 3,
        '最大API调用': 50,
        '内存限制_MB': 4096
    }
    
    for constraint, limit in constraints.items():
        if plan.exceeds(constraint, limit):
            return False
    return True

4. 假设前澄清

def ask_for_clarification(unclear_point):
    """不假设,而是询问用户"""
    message = f"我不确定: {unclear_point}。 "
    message += "你能在继续之前澄清吗?"
    send_to_user(message)
    wait_for_response()

看门狗

看门狗角色阈值
ICS计划完整性>0.800 = 停止
CLW经验教训见过模式 = 警告
STC紧张度>0.500 = 警告

使用方法

from planning_validator import PlanningValidator

validator = PlanningValidator()

# 在执行计划之前
plan = create_plan(objective)

validation = validator.validate_plan(plan)
if not validation['valid']:
    failed_at = validation['failed_at']
    ask_for_clarification(f"计划在 {failed_at} 失败")
else:
    execute_plan(plan)

检查清单

  • 步骤之间的多代理验证器
  • 明确的工具模式(能力 + 限制)
  • 约束验证
  • 假设前澄清
  • ICS 看门狗加强
  • CLW 看门狗(模式检测)
  • 复杂计划需要用户审批

文件结构

planning-validator/
├── SKILL.md
├── scripts/
│   ├── planning_validator.py
│   ├── utils.py
│   └── main.py
├── data/
├── models/
└── tests/