fix(evolution): prevent MCP tool re-injection into restricted review agent #2904

This commit is contained in:
zhayujie
2026-06-20 15:17:11 +08:00
parent a0e20ef311
commit 0bc0f2b930
2 changed files with 15 additions and 0 deletions

View File

@@ -424,6 +424,11 @@ def run_evolution_for_session(
enable_skills=True, enable_skills=True,
runtime_info=getattr(agent, "runtime_info", None), runtime_info=getattr(agent, "runtime_info", None),
) )
# Mark this as a restricted review agent so runtime MCP reconciliation
# (ToolManager.sync_mcp_into_agent) will NOT silently re-inject MCP tools
# that _select_tools()/_guard_tools() intentionally withheld. Without this
# flag the review boundary would be re-opened on the first LLM turn.
review_agent._evolution_restricted = True
# Reuse the live model so it follows the user's configured model. # Reuse the live model so it follows the user's configured model.
review_agent.model = agent.model review_agent.model = agent.model
# Inject the evolution task brief AFTER the full system prompt: the agent # Inject the evolution task brief AFTER the full system prompt: the agent

View File

@@ -523,6 +523,16 @@ class ToolManager:
if agent is None or not hasattr(agent, "tools"): if agent is None or not hasattr(agent, "tools"):
return ([], []) return ([], [])
# Never re-inject MCP tools into a restricted Self-Evolution review agent.
# The review agent is created with a deliberately reduced, workspace-guarded
# toolset; silently re-adding configured MCP tools here would bypass that
# policy boundary (see agent/evolution/executor.py). The flag may live on
# the agent itself (Agent) or on the wrapping stream executor's .agent.
if getattr(agent, "_evolution_restricted", False) or getattr(
getattr(agent, "agent", None), "_evolution_restricted", False
):
return ([], [])
from agent.tools.mcp.mcp_tool import McpTool from agent.tools.mcp.mcp_tool import McpTool
current = self._mcp_tool_instances current = self._mcp_tool_instances
registry_names = set(current.keys()) registry_names = set(current.keys())