agent-team/docs/plans/2026-03-10-file-operations-enhancement-design.md

76 lines
2.0 KiB
Markdown
Raw Permalink 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.

# Agent Team 文件操作能力增强设计
## 目标
为 Agent Team 赋予类似 opencode/claudecode 的强大文件处理能力,支持智能搜索、大文件处理、精细编辑、多 agent 并行处理、Git 集成和文件可视化。
## 架构选择
- **工具调用方式**: Tool Calling - Agent 直接调用 LLM 时带上工具定义LLM 自主决定何时调用哪些工具
- **适用范围**: 全部 workspace 文件
## 工具定义
### 1. 智能文件搜索
| 工具 | 功能 | 参数 |
|------|------|------|
| `glob` | 模式匹配文件 | `pattern`: glob 模式 |
| `grep` | 内容搜索 | `pattern`: 正则, `path`: 目录, `include`: 文件过滤 |
### 2. 大文件处理
| 工具 | 功能 | 参数 |
|------|------|------|
| `read_file` | 读取文件 | `filename`, `offset`, `limit` |
| `get_line_count` | 查询总行数 | `filename` |
### 3. 精细编辑操作
| 工具 | 功能 | 参数 |
|------|------|------|
| `edit_file` | 编辑文件 | `filename`, `old_string`, `new_string` |
| `write_file` | 写入文件 | `filename`, `content` |
| `create_dir` | 创建目录 | `dir` |
| `delete_file` | 删除文件 | `filename` |
| `list_workspace` | 列出工作区文件 | - |
### 4. Git 集成
| 工具 | 功能 | 参数 |
|------|------|------|
| `git_status` | 查看变更状态 | - |
| `git_diff` | 查看变更 | `filename` |
| `git_commit` | 提交变更 | `message` |
## 实现策略
### Phase 1: 核心工具实现
- 实现 glob, grep, read_file, edit_file, write_file 工具
- 集成到 Room 的 Agent 调用中
### Phase 2: 大文件支持
- 添加 offset/limit 支持
- 实现 get_line_count
### Phase 3: Git 集成
- 实现 git_status, git_diff, git_commit
### Phase 4: 并行处理
- 添加文件锁机制
- 处理并发编辑冲突
## 数据流
```
User Message
Room.HandleUserMessage()
Agent.StreamWithTools([glob, grep, read_file, edit_file, ...])
LLM 自主选择工具 → 执行 → 返回结果
继续生成或结束
```