Files
zclaw_openfang/docs/features/02-intelligence-layer/05-autonomy-manager.md
iven 3518fc8ece feat(automation): complete unified automation system redesign
Phase 4 completion:
- Add ApprovalQueue component for managing pending approvals
- Add ExecutionResult component for displaying hand/workflow results
- Update Sidebar navigation to use unified AutomationPanel
- Replace separate 'hands' and 'workflow' tabs with single 'automation' tab
- Fix TypeScript type safety issues with unknown types in JSX expressions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 17:12:05 +08:00

188 lines
5.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 自主授权系统 (Autonomy Manager)
> **分类**: 智能层
> **优先级**: P1 - 重要
> **成熟度**: L4 - 生产
> **最后更新**: 2026-03-18
---
## ✅ 集成状态
> **当前状态**: ✅ 完全集成
>
> `AutonomyConfig.tsx` 组件已集成到 `RightPanel.tsx` 的 'autonomy' tab。
>
> **集成位置**: RightPanel 'autonomy' tab (点击 Shield 图标)
### 已集成的系统
| 系统 | 文件 | 集成状态 | 说明 |
|------|------|---------|------|
| 反思引擎 | `reflection-engine.ts` | ✅ 已集成 | 反思运行前检查授权 |
| 上下文压缩 | `context-compactor.ts` | ✅ 已集成 | 压缩执行前检查授权 |
| 身份更新 | `agent-identity.ts` | ✅ 已集成 | 身份变更前检查授权 |
| 技能安装 | `skill-discovery.ts` | ✅ 已集成 | 技能安装/卸载前检查授权 |
| 记忆提取 | `session-persistence.ts` | ✅ 已集成 | 记忆保存前检查授权 |
---
## 一、功能概述
### 1.1 基本信息
自主授权系统实现了分层授权机制,根据操作的风险等级和当前的自主级别,决定是自动执行还是需要用户审批。
| 属性 | 值 |
|------|-----|
| 分类 | 智能层 |
| 优先级 | P1 |
| 成熟度 | L4 |
| 依赖 | AuditLog, ApprovalWorkflow |
### 1.2 相关文件
| 文件 | 路径 | 用途 | 集成状态 |
|------|------|------|---------|
| 核心实现 | `desktop/src/lib/autonomy-manager.ts` | 授权逻辑 | ✅ 存在 |
| 配置 UI | `desktop/src/components/AutonomyConfig.tsx` | 配置界面 | ✅ 已集成 |
| 审批 UI | `desktop/src/components/ApprovalsPanel.tsx` | 审批界面 | ✅ 已集成 |
---
## 二、设计初衷
### 2.1 问题背景
**用户痛点**:
1. Agent 自主操作可能带来风险
2. 不同操作的风险等级不同
3. 需要平衡效率和安全
**系统缺失能力**:
- 缺乏风险分级机制
- 缺乏审批流程
- 缺乏操作审计
**为什么需要**:
自主与安全的平衡是 AI Agent 可信的关键,需要分层授权机制来管理不同风险的操作。
### 2.2 设计目标
1. **分层授权**: Supervised / Assisted / Autonomous
2. **风险分级**: Low / Medium / High
3. **审批流程**: 请求 → 等待 → 批准/拒绝
4. **审计追踪**: 所有操作可追溯
### 2.3 自主级别
| 级别 | 描述 | 行为 |
|------|------|------|
| Supervised | 监督模式 | 所有操作需要确认 |
| Assisted | 辅助模式 | 低风险自动执行,中高风险需确认 |
| Autonomous | 自主模式 | 低中风险自动执行,高风险需确认 |
### 2.4 风险等级
| 等级 | 操作类型 | Supervised | Assisted | Autonomous |
|------|---------|------------|----------|------------|
| Low | memory_save, reflection_run, compaction_run | 需确认 | 自动 | 自动 |
| Medium | hand_trigger, config_change, skill_install | 需确认 | 需确认 | 自动 |
| High | memory_delete, identity_update | 需确认 | 需确认 | 需确认 |
### 2.5 设计约束
- **安全约束**: 高风险操作始终需要确认
- **性能约束**: 审批不能阻塞主流程
- **审计约束**: 所有操作必须可追溯
---
## 三、技术设计
### 3.1 核心接口
```typescript
interface AutonomyManager {
getLevel(): AutonomyLevel;
setLevel(level: AutonomyLevel): void;
requestAuthorization(action: Action): Promise<AuthorizationResult>;
getPendingApprovals(): ApprovalRequest[];
approve(requestId: string): Promise<void>;
reject(requestId: string, reason: string): Promise<void>;
getAuditLog(filter?: AuditFilter): AuditEntry[];
}
```
### 3.2 授权流程
```
操作请求 → 评估风险等级 → 需要确认? → 执行操作 → 完成
创建审批请求 → 用户批准/拒绝
```
### 3.3 集成模式
各系统集成自主检查的统一模式:
```typescript
import { canAutoExecute } from './autonomy-manager';
async function someOperation(options?: { skipAutonomyCheck?: boolean }) {
// 自主检查
if (!options?.skipAutonomyCheck) {
const { canProceed, decision } = canAutoExecute('action_type', importance);
if (!canProceed) {
console.log(`[Module] Autonomy check failed: ${decision.reason}`);
return; // 或返回默认结果
}
console.log(`[Module] Autonomy check passed: ${decision.reason}`);
}
// 执行实际操作
// ...
}
```
---
## 四、实际效果
### 4.1 已实现功能
- [x] 三级自主级别 (lib)
- [x] 三级风险分级 (lib)
- [x] 审批流程 (lib)
- [x] 审计日志 (lib)
- [x] 操作回滚 (lib)
- [x] 审批过期 (lib)
- [x] **UI 审批面板** - ✅ 已集成到 RightPanel 'autonomy' tab
- [x] **反思引擎集成** - ✅ 2026-03-18
- [x] **上下文压缩集成** - ✅ 2026-03-18
- [x] **身份更新集成** - ✅ 2026-03-18
- [x] **技能安装集成** - ✅ 2026-03-18
### 4.2 已知问题
| 问题 | 严重程度 | 状态 |
|------|---------|------|
| 回滚不总是可用 | 中 | 已知 |
| 审批 UI 需要优化 | 低 | 待处理 |
---
## 五、演化路线
### 5.1 短期计划1-2 周)
- [x] 集成反思引擎
- [x] 集成上下文压缩
- [x] 集成身份更新
- [x] 集成技能安装
- [ ] 优化审批 UI
- [ ] 添加批量审批
### 5.3 中期计划1-2 月)
- [ ] 智能风险预测
- [ ] 自适应自主级别