Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions mpp-core/src/commonMain/kotlin/cc/unitmesh/agent/CodingAgent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,18 @@ class CodingAgent(
private var mcpToolsInitialized = false

init {
// 注册 Agents(作为 Tools)- 根据配置决定是否启用
if (configService.isBuiltinToolEnabled("error-agent")) {
registerTool(errorRecoveryAgent)
toolRegistry.registerTool(errorRecoveryAgent) // 同时注册到 ToolRegistry
subAgentManager.registerSubAgent(errorRecoveryAgent) // 注册到 SubAgentManager
}
if (configService.isBuiltinToolEnabled("analysis-agent")) {
registerTool(analysisAgent)
toolRegistry.registerTool(analysisAgent) // 同时注册到 ToolRegistry
subAgentManager.registerSubAgent(analysisAgent) // 注册到 SubAgentManager
}
if (configService.isBuiltinToolEnabled("code-agent")) {
registerTool(codebaseInvestigatorAgent)
toolRegistry.registerTool(codebaseInvestigatorAgent) // 同时注册到 ToolRegistry
subAgentManager.registerSubAgent(codebaseInvestigatorAgent) // 注册到 SubAgentManager
}
// Register Sub-Agents (as Tools) - Always enabled as they are built-in tools
registerTool(errorRecoveryAgent)
toolRegistry.registerTool(errorRecoveryAgent)
subAgentManager.registerSubAgent(errorRecoveryAgent)

registerTool(analysisAgent)
toolRegistry.registerTool(analysisAgent)
subAgentManager.registerSubAgent(analysisAgent)

registerTool(codebaseInvestigatorAgent)
toolRegistry.registerTool(codebaseInvestigatorAgent)
subAgentManager.registerSubAgent(codebaseInvestigatorAgent)

CoroutineScope(SupervisorJob() + Dispatchers.Default).launch {
initializeWorkspace(projectPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,72 @@ Each tool's parameters are validated against its JSON Schema. Refer to the schem

## Task Execution Guidelines

1. **Gather Context First**: Before making changes, use /read-file and /glob to understand the codebase
1. **Gather Context First**: Before making changes understand the codebase
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after 'changes'. Should be: 'Before making changes, understand the codebase'.

Suggested change
1. **Gather Context First**: Before making changes understand the codebase
1. **Gather Context First**: Before making changes, understand the codebase

Copilot uses AI. Check for mistakes.
2. **Plan Your Approach**: Think step-by-step about what needs to be done
3. **Make Incremental Changes**: Make one change at a time and verify it works
4. **Test Your Changes**: Run tests or build commands to verify changes
5. **Handle Errors Gracefully**: When a tool fails, analyze the error and try alternative approaches

## Smart File Search Guidelines

When searching for files, use **specific and targeted patterns** to avoid overwhelming context:

**DO:**
- ✅ Use specific patterns: `src/**/*.kt`, `**/test/**/*.java`, `**/config/*.yml`
- ✅ Target specific directories: `/glob pattern="*.ts" path="src/main"`
- ✅ Use grep with specific patterns to narrow down first
- ✅ For broad exploration, use `/ask-agent` to get a summary instead

**DON'T:**
- ❌ Avoid `**/*` or overly broad patterns (returns too many files, wastes context)
- ❌ Don't glob the entire codebase without a specific goal

**Smart Strategy:**
1. If you need to understand the project structure, use grep for specific keywords first
2. Use targeted glob patterns based on what you found
3. For very large result sets (100+ files), the system will automatically invoke a SummaryAgent to provide a concise overview

Comment on lines +47 to +65
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

Verify implementation details match the documented behavior.

The new guidance references specific thresholds and automatic behaviors:

  • Line 64: Claims "100+ files" automatically invokes SummaryAgent (note: text says "SummaryAgent" but line 71 says "analysis-agent")
  • Line 53: Shows glob syntax /glob pattern="*.ts" path="src/main"
  • Line 64: Promises automatic agent invocation for large result sets

Please verify:

  1. The actual threshold for auto-summarization (is it exactly 100 files?)
  2. The correct glob tool syntax matches the schema
  3. The automatic AnalysisAgent invocation is implemented as described
  4. Consistent agent naming (SummaryAgent vs analysis-agent)

🏁 Script executed:

#!/bin/bash
# Verify the implementation of glob tool and auto-summarization threshold

echo "=== Searching for glob tool implementation and threshold ==="
rg -n "100|threshold" --type kotlin -g "**/tool/**" -g "**/*Glob*" -C 3

echo -e "\n=== Searching for AnalysisAgent/SummaryAgent references ==="
rg -n "AnalysisAgent|SummaryAgent|analysis-agent" --type kotlin -C 3

echo -e "\n=== Searching for glob tool schema/parameters ==="
ast-grep --pattern 'class GlobTool {
  $$$
}'

Length of output: 58005


Update line 64 to use "AnalysisAgent" instead of "SummaryAgent".

The documentation in line 64 incorrectly references "SummaryAgent" when the actual implementation uses "AnalysisAgent". The codebase correctly implements a 100-file threshold that automatically triggers the AnalysisAgent for large file lists. Update the reference to match the correct agent name.

Line 64 should read:

  • Current: "For very large result sets (100+ files), the system will automatically invoke a SummaryAgent to provide a concise overview"
  • Corrected: "For very large result sets (100+ files), the system will automatically invoke an AnalysisAgent to provide a concise overview"
🤖 Prompt for AI Agents
mpp-core/src/commonMain/kotlin/cc/unitmesh/agent/CodingAgentTemplate.kt around
lines 47 to 65: the documentation on line 64 references "SummaryAgent" but the
implementation uses "AnalysisAgent", so update the text to replace
"SummaryAgent" with "AnalysisAgent" so the doc matches the code; ensure the
sentence reads that for very large result sets (100+ files) the system will
automatically invoke an AnalysisAgent to provide a concise overview.

## Agent Communication & Collaboration

When dealing with complex information or large content, you can **communicate with specialized SubAgents** to get focused analysis:

**Available SubAgents:**
- `analysis-agent`: Analyzes and summarizes any content (logs, file lists, code, data)
- `error-agent`: Analyzes errors and provides recovery suggestions
- `code-agent`: Deep codebase investigation and architectural analysis

**When to Use `/ask-agent`:**
1. **After automatic summarization**: When a tool (like glob) triggers auto-summarization, you can ask follow-up questions
```
/ask-agent
```json
{"agentName": "analysis-agent", "question": "What are the main patterns in the file structure you analyzed?"}
```
```

2. **For specific insights**: Ask targeted questions about previously analyzed content
```
/ask-agent
```json
{"agentName": "analysis-agent", "question": "Which files are most likely related to authentication?"}
```
```

3. **To avoid re-reading large content**: If you need different perspectives on the same data
```
/ask-agent
```json
{"agentName": "analysis-agent", "question": "Can you identify the main dependencies in the files you saw?"}
```
```

**Example Workflow:**
1. `/glob pattern="**/*.kt"` → Auto-triggers AnalysisAgent (returns summary)
2. Review the summary, then ask: `/ask-agent` to get specific insights
3. Based on insights, use targeted `/read-file` or `/grep` commands

This approach keeps your context efficient while getting deep insights from specialized agents!

## Task Progress Communication

For complex multi-step tasks (5+ steps), use `/task-boundary` to help users understand your progress:
Expand Down Expand Up @@ -158,11 +218,71 @@ ${'$'}{toolList}

## 任务执行指南

1. **先获取上下文**: 在进行更改之前,使用 /read-file 和 /glob 来了解代码库
1. **先获取上下文**: 在进行更改之前,先来了解代码库
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Chinese text is awkward. '先来了解代码库' should be '先了解代码库' (remove '来' which is redundant).

Suggested change
1. **先获取上下文**: 在进行更改之前,先来了解代码库
1. **先获取上下文**: 在进行更改之前,先了解代码库

Copilot uses AI. Check for mistakes.
2. **规划你的方法**: 逐步思考需要做什么
3. **增量更改**: 一次做一个更改并验证其有效性
4. **测试更改**: 运行测试或构建命令来验证更改

## 智能文件搜索指南

搜索文件时,使用**具体且有针对性的模式**以避免上下文超载:

**应该做:**
- ✅ 使用具体的模式:`src/**/*.kt`、`**/test/**/*.java`、`**/config/*.yml`
- ✅ 针对特定目录:`/glob pattern="*.ts" path="src/main"`
- ✅ 先使用 grep 配合具体模式来缩小范围
- ✅ 对于广泛探索,使用 `/ask-agent` 获取摘要

**不应该做:**
- ❌ 避免 `**/*` 或过于宽泛的模式(返回太多文件,浪费上下文)
- ❌ 不要在没有明确目标的情况下 glob 整个代码库

**智能策略:**
1. 如果需要了解项目结构,先使用 grep 搜索特定关键词
2. 根据发现的内容使用有针对性的 glob 模式
3. 对于非常大的结果集(100+ 文件),系统会自动调用 SummaryAgent 提供简洁概述

## Agent 通信与协作

处理复杂信息或大量内容时,你可以**与专业的 SubAgent 通信**来获取专注的分析:

**可用的 SubAgent:**
- `analysis-agent`: 分析和总结任何内容(日志、文件列表、代码、数据)
- `error-agent`: 分析错误并提供恢复建议
- `code-agent`: 深度代码库调查和架构分析

**何时使用 `/ask-agent`:**
1. **自动总结之后**: 当工具(如 glob)触发自动总结后,你可以询问后续问题
```
/ask-agent
```json
{"agentName": "analysis-agent", "question": "你分析的文件结构中有哪些主要模式?"}
```
```

2. **获取特定见解**: 就之前分析的内容提出针对性问题
```
/ask-agent
```json
{"agentName": "analysis-agent", "question": "哪些文件最可能与身份验证相关?"}
```
```

3. **避免重复读取大内容**: 需要从不同角度看待相同数据时
```
/ask-agent
```json
{"agentName": "analysis-agent", "question": "你能识别出文件中的主要依赖关系吗?"}
```
```

**示例工作流:**
1. `/glob pattern="**/*.kt"` → 自动触发 AnalysisAgent(返回摘要)
2. 查看摘要,然后询问:`/ask-agent` 获取特定见解
3. 基于见解,使用有针对性的 `/read-file` 或 `/grep` 命令

这种方法既保持上下文高效,又能从专业 Agent 获得深度见解!

## 任务进度沟通

对于复杂的多步骤任务(5+ 步骤),使用 `/task-boundary` 帮助用户了解你的进度:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ class McpToolConfigService(val toolConfig: ToolConfigFile) {
}
}

/**
* Built-in tools are always enabled and cannot be disabled.
* This method always returns true for backward compatibility.
*
* @deprecated Built-in tools are now always enabled
*/
@Deprecated("Built-in tools are always enabled", ReplaceWith("true"))
fun isBuiltinToolEnabled(toolName: String): Boolean {
if (toolConfig.enabledBuiltinTools.isEmpty()) {
return true
}
return toolName in toolConfig.enabledBuiltinTools
// Built-in tools are always enabled
return true
}

fun isMcpToolEnabled(toolName: String): Boolean {
Expand All @@ -36,14 +41,16 @@ class McpToolConfigService(val toolConfig: ToolConfigFile) {
return toolName in toolConfig.enabledMcpTools
}

/**
* Built-in tools are always enabled and cannot be disabled.
* This method returns all tools without filtering.
*
* @deprecated Built-in tools are now always enabled
*/
@Deprecated("Built-in tools are always enabled", ReplaceWith("tools"))
fun <T : ExecutableTool<*, *>> filterBuiltinTools(tools: List<T>): List<T> {
if (toolConfig.enabledBuiltinTools.isEmpty()) {
return tools
}

return tools.filter { tool ->
isBuiltinToolEnabled(tool.name)
}
// Built-in tools are always enabled - no filtering
return tools
}

fun <T : ExecutableTool<*, *>> filterMcpTools(tools: List<T>): List<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,13 @@ import kotlinx.serialization.Serializable
* Tool Configuration - Manages enabled tools for CodingAgent
*
* Supports both:
* - Built-in system tools (from ToolType)
* - MCP (Model Context Protocol) tools from external servers
* - Built-in system tools (always enabled, cannot be disabled)
* - MCP (Model Context Protocol) tools from external servers (configurable)
*
* Stored in ~/.autodev/mcp.json
*/
@Serializable
data class ToolConfigFile(
/**
* List of enabled built-in tool names
*
* Available tools:
* - File System: read-file, write-file, list-files, edit-file, patch-file
* - Search: grep, glob
* - Execution: shell
* - SubAgent: error-recovery, log-summary, codebase-investigator
*/
val enabledBuiltinTools: List<String> = emptyList(),

/**
* List of enabled MCP tool names (tool names, not server names)
*/
Expand All @@ -38,17 +27,13 @@ data class ToolConfigFile(
) {
companion object {
/**
* Default configuration with all built-in tools enabled
* Default configuration.
*
* Note: Built-in tools are always enabled and don't need to be listed.
* The enabledBuiltinTools field is deprecated and ignored.
*/
fun default(): ToolConfigFile {
return ToolConfigFile(
enabledBuiltinTools = listOf(
"read-file", "write-file", "list-files", "edit-file", "patch-file",
"grep", "glob",
"shell",
"web-fetch",
"error-recovery", "log-summary", "codebase-investigator"
),
enabledMcpTools = emptyList(),
mcpServers = emptyMap()
)
Expand Down

This file was deleted.

Loading
Loading