feat: implement interactive multi-agent system with MCP integration

pull/819/head
Pavan Kumar 2 days ago committed by ascender1729
parent 9355f06f64
commit 9859fcfd2a

@ -4,6 +4,7 @@ modules = ["python-3.10", "bash"]
channel = "stable-24_05" channel = "stable-24_05"
[workflows] [workflows]
runButton = "Run Interactive Agents"
[[workflows.workflow]] [[workflows.workflow]]
name = "Run MCP Tests" name = "Run MCP Tests"
@ -13,3 +14,12 @@ mode = "sequential"
[[workflows.workflow.tasks]] [[workflows.workflow.tasks]]
task = "shell.exec" task = "shell.exec"
args = "python -m pytest tests/tools/test_mcp_integration.py -v" args = "python -m pytest tests/tools/test_mcp_integration.py -v"
[[workflows.workflow]]
name = "Run Interactive Agents"
author = 13983571
mode = "sequential"
[[workflows.workflow.tasks]]
task = "shell.exec"
args = "python -m pytest tests/tools/test_mcp_integration.py::test_interactive_multi_agent_mcp -s"

@ -1,24 +1,75 @@
import pytest import pytest
from swarms.tools.mcp_integration import MCPServerSseParams, mcp_flow from swarms.tools.mcp_integration import MCPServerSseParams
from swarms import Agent
from swarms.prompts.finance_agent_sys_prompt import FINANCIAL_AGENT_SYS_PROMPT
def test_mcp_flow(): def test_interactive_multi_agent_mcp():
params = MCPServerSseParams( # Configure two MCP servers
url="http://localhost:6274", server_one = MCPServerSseParams(
url="http://0.0.0.0:6274",
headers={"Content-Type": "application/json"} headers={"Content-Type": "application/json"}
) )
function_call = { server_two = MCPServerSseParams(
"tool_name": "test_tool", url="http://0.0.0.0:6275",
"args": {"param1": "value1"} headers={"Content-Type": "application/json"}
} )
# Create two agents with different roles
finance_agent = Agent(
agent_name="Finance-Agent",
agent_description="Financial analysis expert",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
max_loops=1,
mcp_servers=[server_one],
interactive=True,
streaming_on=True
)
research_agent = Agent(
agent_name="Research-Agent",
agent_description="Market research specialist",
system_prompt="You are a market research specialist. Analyze market trends and provide insights.",
max_loops=1,
mcp_servers=[server_two],
interactive=True,
streaming_on=True
)
try: try:
result = mcp_flow(params, function_call) # Interactive loop
assert isinstance(result, str) while True:
# Get user input for which agent to use
print("\nWhich agent would you like to interact with?")
print("1. Finance Agent")
print("2. Research Agent")
print("3. Exit")
choice = input("Enter your choice (1-3): ")
if choice == "3":
break
# Get the task from user
task = input("\nEnter your task for the agent: ")
# Route to appropriate agent
if choice == "1":
response = finance_agent.run(task)
print(f"\nFinance Agent Response:\n{response}")
elif choice == "2":
response = research_agent.run(task)
print(f"\nResearch Agent Response:\n{response}")
else:
print("Invalid choice, please try again")
except Exception as e: except Exception as e:
pytest.fail(f"MCP flow failed: {e}") pytest.fail(f"Interactive multi-agent test failed: {e}")
def test_mcp_invalid_params(): def test_mcp_invalid_params():
with pytest.raises(Exception): with pytest.raises(Exception):
mcp_flow(None, {}) mcp_flow(None, {})
if __name__ == "__main__":
test_interactive_multi_agent_mcp()

Loading…
Cancel
Save