Added: Contextual reminder for mcps with multi-step-processes for agent to not get distracted, to continue process.

deci committed May 13, 2025 at 22:56 UTC 36b6dc93cea683ffe5375d2dcd4c5cfd6c42ca7c
1 file changed +7 -1
python/helpers/mcp_handler.py
+7 -1
@@ -5,6 +5,7 @@ import asyncio
5 from contextlib import AsyncExitStack
6 from shutil import which
7 from datetime import timedelta
8 +import json
9
10 import os
11 # print(f"DEBUG: Listing /opt/venv/lib/python3.11/site-packages/ before mcp import: {os.listdir('/opt/venv/lib/python3.11/site-packages/')}") # This line caused FileNotFoundError, **FOR CUDA CHANGE TO '3.12'**
@@ -70,6 +71,9 @@ class MCPTool(Tool):
71 else:
72 text = response.message.strip()
73
74 + # Add a general contextual reminder for multi-step processes
75 + text += f"\n\n[Contextual Reminder for {self.name}: If this action is part of an ongoing sequence, consider the next step with this tool. If the sequence is complete, analyze the final output and report to the user or proceed accordingly.]"
76 +
77 self.agent.hist_add_tool_result(self.name, text)
78 (
79 PrintStyle(font_color="#1B4F72", background_color="white", padding=True, bold=True)
@@ -487,7 +491,9 @@ class MCPClientBase(ABC):
491 PrintStyle(font_color="cyan").print(
492 f"MCPClientBase ({self.server.name} - {operation_name}): Session and transport will be closed by AsyncExitStack."
493 )
490 - # temp_stack.aclose() is called automatically here.
494 + # This line should ideally be unreachable if the try/except/finally logic within the 'async with' is exhaustive.
495 + # Adding it to satisfy linters that might not fully trace the raise/return paths through async context managers.
496 + raise RuntimeError(f"MCPClientBase ({self.server.name} - {operation_name}): _execute_with_session exited 'async with' block unexpectedly.")
497
498 async def update_tools(self) -> "MCPClientBase":
499 PrintStyle(font_color="cyan").print(f"MCPClientBase ({self.server.name}): Starting 'update_tools' operation...")