deciduus commited on
Commit
1963ef7
·
1 Parent(s): 25c76c5

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

Browse files
Files changed (1) hide show
  1. python/helpers/mcp_handler.py +7 -1
python/helpers/mcp_handler.py CHANGED
@@ -5,6 +5,7 @@ import asyncio
5
  from contextlib import AsyncExitStack
6
  from shutil import which
7
  from datetime import timedelta
 
8
 
9
  import os
10
  # 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):
70
  else:
71
  text = response.message.strip()
72
 
 
 
 
73
  self.agent.hist_add_tool_result(self.name, text)
74
  (
75
  PrintStyle(font_color="#1B4F72", background_color="white", padding=True, bold=True)
@@ -487,7 +491,9 @@ class MCPClientBase(ABC):
487
  PrintStyle(font_color="cyan").print(
488
  f"MCPClientBase ({self.server.name} - {operation_name}): Session and transport will be closed by AsyncExitStack."
489
  )
490
- # temp_stack.aclose() is called automatically here.
 
 
491
 
492
  async def update_tools(self) -> "MCPClientBase":
493
  PrintStyle(font_color="cyan").print(f"MCPClientBase ({self.server.name}): Starting 'update_tools' operation...")
 
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'**
 
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)
 
491
  PrintStyle(font_color="cyan").print(
492
  f"MCPClientBase ({self.server.name} - {operation_name}): Session and transport will be closed by AsyncExitStack."
493
  )
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...")