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
13 changes: 12 additions & 1 deletion mpp-core/src/commonMain/kotlin/cc/unitmesh/agent/CodingAgent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import cc.unitmesh.agent.subagent.AnalysisAgent
import cc.unitmesh.agent.subagent.ChartAgent
import cc.unitmesh.agent.subagent.ErrorRecoveryAgent
import cc.unitmesh.agent.subagent.NanoDSLAgent
import cc.unitmesh.agent.subagent.PlotDSLAgent
import cc.unitmesh.agent.tool.*
import cc.unitmesh.agent.tool.filesystem.DefaultToolFileSystem
import cc.unitmesh.agent.tool.filesystem.ToolFileSystem
Expand Down Expand Up @@ -99,6 +100,7 @@ class CodingAgent(
private val analysisAgent = AnalysisAgent(llmService, contentThreshold = 15000)
private val nanoDSLAgent = NanoDSLAgent(llmService)
private val chartAgent = ChartAgent(llmService)
private val plotDSLAgent = PlotDSLAgent(llmService)
private val mcpToolsInitializer = McpToolsInitializer()

// 执行器
Expand Down Expand Up @@ -133,6 +135,14 @@ class CodingAgent(
toolRegistry.registerTool(chartAgent)
subAgentManager.registerSubAgent(chartAgent)

// PlotDSLAgent - only available on JVM/Android (checks isAvailable internally)
if (plotDSLAgent.isAvailable) {
registerTool(plotDSLAgent)
toolRegistry.registerTool(plotDSLAgent)
}

subAgentManager.registerSubAgent(plotDSLAgent)
Comment on lines +142 to +144
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The conditional registration logic is inconsistent. PlotDSLAgent is registered to toolRegistry only when isAvailable is true (lines 139-142), but then unconditionally registered to subAgentManager (line 144). This could lead to the SubAgent being available in the manager but not as a tool. Either both should be conditional, or the subAgentManager.registerSubAgent() call should handle the availability check internally (which it does based on the SubAgentManager.kt changes).

Suggested change
}
subAgentManager.registerSubAgent(plotDSLAgent)
subAgentManager.registerSubAgent(plotDSLAgent)
}

Copilot uses AI. Check for mistakes.

CoroutineScope(SupervisorJob() + Dispatchers.Default).launch {
initializeWorkspace(projectPath)
}
Expand All @@ -142,7 +152,8 @@ class CodingAgent(
input: AgentTask,
onProgress: (String) -> Unit
): ToolResult.AgentResult {
initializeWorkspace(input.projectPath)
// Note: initializeWorkspace is already called in init block, no need to call again here
// The buildContext() will handle MCP tools initialization if needed
Comment on lines +155 to +156
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

[nitpick] The comment on line 155 is misleading. It states "initializeWorkspace is already called in init block, no need to call again here," but this comment describes removed code behavior rather than explaining why the code was removed or what the current approach is. Consider removing this comment or updating it to explain the current initialization strategy more clearly.

Suggested change
// Note: initializeWorkspace is already called in init block, no need to call again here
// The buildContext() will handle MCP tools initialization if needed
// Workspace initialization is performed asynchronously in the init block.
// MCP tools initialization is handled within buildContext if needed.

Copilot uses AI. Check for mistakes.

val context = buildContext(input)
val systemPrompt = buildSystemPrompt(context)
Expand Down
10 changes: 10 additions & 0 deletions mpp-core/src/commonMain/kotlin/cc/unitmesh/agent/core/SubAgent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ abstract class SubAgent<TInput : Any, TOutput : ToolResult>(
*/
open val priority: Int = 100

/**
* 检查此 SubAgent 在当前平台是否可用
*
* 用于平台相关的 SubAgent(如依赖 Lets-Plot 的 PlotDSLAgent)
* 在不支持的平台上跳过注册
*
* @return 如果在当前平台可用返回 true,否则返回 false
*/
open val isAvailable: Boolean = true

/**
* 检查是否应该触发此 SubAgent
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,24 @@ class SubAgentManager {

/**
* 注册 SubAgent
*
* 注册前会检查 SubAgent 是否在当前平台可用。
* 如果不可用,则跳过注册并记录日志。
*
* @param subAgent 要注册的 SubAgent
* @return 是否成功注册(如果不可用则返回 false)
*/
fun <TInput : Any, TOutput : ToolResult> registerSubAgent(
subAgent: SubAgent<TInput, TOutput>
) {
): Boolean {
if (!subAgent.isAvailable) {
logger.info { "⏭️ Skipped SubAgent: ${subAgent.name} (not available on current platform)" }
return false
}

subAgents[subAgent.name] = subAgent
logger.info { "🤖 Registered SubAgent: ${subAgent.name}" }
return true
}

@Suppress("UNCHECKED_CAST")
Expand Down
Loading
Loading