Skip to content

Commit 4ad4fb6

Browse files
committed
feat: 支持agent模式
1 parent 2098a69 commit 4ad4fb6

3 files changed

Lines changed: 38 additions & 34 deletions

File tree

README.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -324,21 +324,6 @@ Currently, Agent mode is supported by:
324324
- **DeepSeek** (`deepseek-chat` and other models with function calling)
325325
- **Zhipu** (`glm-4` and other models with function calling)
326326

327-
### Available Tools
328-
329-
| Tool | Description | Use Case |
330-
|------|-------------|----------|
331-
| `read_file` | Read file contents with pagination | View complete source files, type definitions |
332-
| `search_content` | Search code with regex patterns | Find function definitions, method calls |
333-
| `list_directory` | List directory structure | Understand project organization |
334-
335-
### How It Works
336-
337-
1. AI receives the diff and list of changed files
338-
2. AI analyzes the changes and identifies areas needing more context
339-
3. AI uses tools to retrieve relevant code (e.g., type definitions, related functions)
340-
4. AI generates a comprehensive review based on full context
341-
5. Process repeats until AI has enough information or limits are reached
342327

343328
### Agent Mode Prompt Example
344329

@@ -352,6 +337,7 @@ export default {
352337
maxIterations: 5,
353338
maxToolCalls: 10
354339
},
340+
..., // other options
355341
prompt: `You are a senior code reviewer with access to the full codebase context.
356342
357343
Project Info:
@@ -390,7 +376,24 @@ Final recommendation on whether to merge`
390376
}
391377
```
392378

393-
> **Note**: Agent mode increases API token usage due to multi-turn conversations and tool results. Consider this when reviewing large changes.
379+
> **Note**: Agent mode increases API token usage due to multi-turn conversations and tool results. Consider this when reviewing large changes. To save tokens, the diff content is also merged and displayed.
380+
381+
382+
### Available Tools
383+
384+
| Tool | Description | Use Case |
385+
|------|-------------|----------|
386+
| `read_file` | Read file contents with pagination | View complete source files, type definitions |
387+
| `search_content` | Search code with regex patterns | Find function definitions, method calls |
388+
| `list_directory` | List directory structure | Understand project organization |
389+
390+
### How It Works
391+
392+
1. AI receives the diff and list of changed files
393+
2. AI analyzes the changes and identifies areas needing more context
394+
3. AI uses tools to retrieve relevant code (e.g., type definitions, related functions)
395+
4. AI generates a comprehensive review based on full context
396+
5. Process repeats until AI has enough information or limits are reached
394397

395398
---
396399

README_ZH.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -329,22 +329,6 @@ export default {
329329
- **DeepSeek**`deepseek-chat` 及其他支持函数调用的模型)
330330
- **智谱**`glm-4` 及其他支持函数调用的模型)
331331

332-
### 可用工具
333-
334-
| 工具 | 描述 | 使用场景 |
335-
|------|------|----------|
336-
| `read_file` | 分页读取文件内容 | 查看完整源代码、类型定义 |
337-
| `search_content` | 使用正则表达式搜索代码 | 查找函数定义、方法调用 |
338-
| `list_directory` | 列出目录结构 | 了解项目组织方式 |
339-
340-
### 工作原理
341-
342-
1. AI 接收 diff 和变更文件列表
343-
2. AI 分析变更并识别需要更多上下文的区域
344-
3. AI 使用工具获取相关代码(如类型定义、关联函数)
345-
4. AI 基于完整上下文生成全面的审查报告
346-
5. 重复上述过程直到 AI 获取足够信息或达到限制
347-
348332
### Agent 模式提示词示例
349333

350334
使用 Agent 模式时,可以优化提示词以充分利用 AI 获取上下文的能力。以下是推荐的 Agent 模式提示词:
@@ -357,6 +341,7 @@ export default {
357341
maxIterations: 5,
358342
maxToolCalls: 10
359343
},
344+
..., // 其它配置
360345
prompt: `你是一位高级代码审查员,可以访问完整的代码库上下文。
361346
362347
项目信息:
@@ -395,7 +380,23 @@ export default {
395380
}
396381
```
397382

398-
> **注意**:Agent 模式会因多轮对话和工具结果而增加 API Token 消耗。审查大型变更时请注意这一点。
383+
> **注意**:Agent 模式会因多轮对话和工具结果而增加 API Token 消耗。审查大型变更时请注意这一点。为了节省token的同时,diff内容也会合并展示
384+
385+
### agent可用工具
386+
387+
| 工具 | 描述 | 使用场景 |
388+
|------|------|----------|
389+
| `read_file` | 分页读取文件内容 | 查看完整源代码、类型定义 |
390+
| `search_content` | 使用正则表达式搜索代码 | 查找函数定义、方法调用 |
391+
| `list_directory` | 列出目录结构 | 了解项目组织方式 |
392+
393+
### 工作原理
394+
395+
1. AI 接收 diff 和变更文件列表
396+
2. AI 分析变更并识别需要更多上下文的区域
397+
3. AI 使用工具获取相关代码(如类型定义、关联函数)
398+
4. AI 基于完整上下文生成全面的审查报告
399+
5. 重复上述过程直到 AI 获取足够信息或达到限制
399400

400401
---
401402

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "code-gate",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Intelligent Git commit guard and code reviewer. Supports local (Ollama) and cloud models (DeepSeek, OpenAI, Anthropic, etc.) with a rich CLI UI.",
55
"type": "module",
66
"bin": {

0 commit comments

Comments
 (0)