From 1d125aae37866f2969711f0b818e43bfbeaedb03 Mon Sep 17 00:00:00 2001 From: deci Date: Tue, 13 May 2025 22:56:34 -0500 Subject: [PATCH] Added: Contextual reminder for mcps with multi-step-processes for agent to not get distracted, to continue process. --- python/helpers/mcp_handler.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/helpers/mcp_handler.py b/python/helpers/mcp_handler.py index 666a85362..595cdb1e6 100644 --- a/python/helpers/mcp_handler.py +++ b/python/helpers/mcp_handler.py @@ -5,6 +5,7 @@ import asyncio from contextlib import AsyncExitStack from shutil import which from datetime import timedelta +import json import os # 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): else: text = response.message.strip() + # Add a general contextual reminder for multi-step processes + 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.]" + self.agent.hist_add_tool_result(self.name, text) ( PrintStyle(font_color="#1B4F72", background_color="white", padding=True, bold=True) @@ -487,7 +491,9 @@ class MCPClientBase(ABC): PrintStyle(font_color="cyan").print( f"MCPClientBase ({self.server.name} - {operation_name}): Session and transport will be closed by AsyncExitStack." ) - # temp_stack.aclose() is called automatically here. + # This line should ideally be unreachable if the try/except/finally logic within the 'async with' is exhaustive. + # Adding it to satisfy linters that might not fully trace the raise/return paths through async context managers. + raise RuntimeError(f"MCPClientBase ({self.server.name} - {operation_name}): _execute_with_session exited 'async with' block unexpectedly.") async def update_tools(self) -> "MCPClientBase": PrintStyle(font_color="cyan").print(f"MCPClientBase ({self.server.name}): Starting 'update_tools' operation...")