|
|
|
@ -1861,8 +1861,7 @@ class Agent:
|
|
|
|
|
return previous_state, f"Restored to {previous_state}"
|
|
|
|
|
|
|
|
|
|
# Response Filtering
|
|
|
|
|
def add_response_filter(self, filter_word: str) -> None:
|
|
|
|
|
"""
|
|
|
|
|
def add_response_filter(self, filter_word: str) -> None:"""
|
|
|
|
|
Add a response filter.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
@ -2777,32 +2776,11 @@ class Agent:
|
|
|
|
|
role="Output Cleaner",
|
|
|
|
|
content=response,
|
|
|
|
|
)
|
|
|
|
|
def mcp_execution_flow(self, response: str | dict) -> str | None:
|
|
|
|
|
"""
|
|
|
|
|
Detect an LLM function-call style response and proxy the call to the
|
|
|
|
|
configured MCP servers. Returns the tool output as a string so it can
|
|
|
|
|
be fed back into the conversation.
|
|
|
|
|
"""
|
|
|
|
|
if not self.mcp_servers:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
def mcp_execution_flow(self, payload: dict) -> str | None:
|
|
|
|
|
"""Forward the tool-call dict to every MCP server in self.mcp_servers"""
|
|
|
|
|
try:
|
|
|
|
|
# LLM may give us a JSON string or already-parsed dict
|
|
|
|
|
if isinstance(response, str):
|
|
|
|
|
call_dict = json.loads(response)
|
|
|
|
|
else:
|
|
|
|
|
call_dict = response
|
|
|
|
|
|
|
|
|
|
if not isinstance(call_dict, dict):
|
|
|
|
|
return None # nothing to do
|
|
|
|
|
|
|
|
|
|
if "tool_name" not in call_dict and "name" not in call_dict:
|
|
|
|
|
return None # not a tool call
|
|
|
|
|
|
|
|
|
|
from swarms.tools.mcp_integration import batch_mcp_flow
|
|
|
|
|
out = batch_mcp_flow(self.mcp_servers, call_dict)
|
|
|
|
|
return any_to_str(out)
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"MCP flow failed: {e}")
|
|
|
|
|
return f"[MCP-error] {e}"
|
|
|
|
|
result = asyncio.run(batch_mcp_flow(self.mcp_servers, [payload]))
|
|
|
|
|
return any_to_str(result)
|
|
|
|
|
except Exception as err:
|
|
|
|
|
logger.error(f"MCP flow failed: {err}")
|
|
|
|
|
return f"[MCP-error] {err}"
|