Files
zclaw_openfang/docs/features/02-intelligence-layer/05-autonomy-manager.md
2026-03-17 23:26:16 +08:00

147 lines
3.8 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-17
---
## ✅ UI 集成状态
> **当前状态**: ✅ 已集成
>
> `AutonomyConfig.tsx` 组件已集成到 `RightPanel.tsx` 的 'autonomy' tab。
>
> **集成位置**: RightPanel 'autonomy' tab (点击 Shield 图标)
---
## 一、功能概述
### 1.1 基本信息
自主授权系统实现了分层授权机制,根据操作的风险等级和当前的自主级别,决定是自动执行还是需要用户审批。
| 属性 | 值 |
|------|-----|
| 分类 | 智能层 |
| 优先级 | P1 |
| 成熟度 | L2 (降级UI 未集成) |
| 依赖 | 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 | 需确认 | 自动 | 自动 |
| Medium | hand_trigger, config_change | 需确认 | 需确认 | 自动 |
| 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 授权流程
```
操作请求 → 评估风险等级 → 需要确认? → 执行操作 → 完成
创建审批请求 → 用户批准/拒绝
```
---
## 四、实际效果
### 4.1 已实现功能
- [x] 三级自主级别 (lib)
- [x] 三级风险分级 (lib)
- [x] 审批流程 (lib)
- [x] 审计日志 (lib)
- [x] 操作回滚 (lib)
- [x] 审批过期 (lib)
- [x] **UI 审批面板** - ✅ 已集成到 RightPanel 'autonomy' tab
### 4.2 已知问题
| 问题 | 严重程度 | 状态 |
|------|---------|------|
| 回滚不总是可用 | 中 | 已知 |
| 审批 UI 需要优化 | 低 | 待处理 |
---
## 五、演化路线
### 5.1 短期计划1-2 周)
- [ ] 优化审批 UI
- [ ] 添加批量审批
### 5.3 中期计划1-2 月)
- [ ] 智能风险预测
- [ ] 自适应自主级别