diff --git a/examples/mcp_example/mcp_client.py b/examples/mcp_example/mcp_client.py index f769535a..0279a39a 100644 --- a/examples/mcp_example/mcp_client.py +++ b/examples/mcp_example/mcp_client.py @@ -1,3 +1,4 @@ + from swarms import Agent from swarms.tools.mcp_integration import MCPServerSseParams from swarms.prompts.agent_prompts import MATH_AGENT_PROMPT @@ -13,11 +14,12 @@ def initialize_math_system(): ) math_agent = Agent( - agent_name="Math Agent", - agent_description="Basic math calculator", + agent_name="Math Assistant", + agent_description="Friendly math calculator", system_prompt=MATH_AGENT_PROMPT, max_loops=1, - mcp_servers=[math_server] + mcp_servers=[math_server], + model_name="gpt-3.5-turbo" ) return math_agent @@ -26,26 +28,26 @@ def main(): math_agent = initialize_math_system() print("\nMath Calculator Ready!") - print("Available operations: add, multiply, divide") - print("Example: 'add 5 and 3' or 'multiply 4 by 6'") + print("Ask me any math question!") + print("Examples: 'what is 5 plus 3?' or 'can you multiply 4 and 6?'") print("Type 'exit' to quit\n") while True: try: - query = input("Enter math operation: ").strip() + query = input("What would you like to calculate? ").strip() if not query: continue if query.lower() == 'exit': break result = math_agent.run(query) - print(f"Result: {result}") + print(f"\nResult: {result}\n") except KeyboardInterrupt: - print("\nExiting...") + print("\nGoodbye!") break except Exception as e: logger.error(f"Error: {e}") if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/examples/mcp_example/mock_math_server.py b/examples/mcp_example/mock_math_server.py index ef1fcff6..e2574d95 100644 --- a/examples/mcp_example/mock_math_server.py +++ b/examples/mcp_example/mock_math_server.py @@ -1,3 +1,4 @@ + from fastmcp import FastMCP from loguru import logger @@ -5,26 +6,28 @@ mcp = FastMCP( host="0.0.0.0", port=8000, transport="sse", - require_session_id=False, - timeout=30.0 + require_session_id=False ) @mcp.tool() -def add(a: int, b: int) -> int: +def add(a: int, b: int) -> str: """Add two numbers.""" - return a + b + result = a + b + return f"The sum of {a} and {b} is {result}" @mcp.tool() -def multiply(a: int, b: int) -> int: +def multiply(a: int, b: int) -> str: """Multiply two numbers.""" - return a * b + result = a * b + return f"The product of {a} and {b} is {result}" @mcp.tool() -def divide(a: int, b: int) -> float: +def divide(a: int, b: int) -> str: """Divide two numbers.""" if b == 0: - raise ValueError("Cannot divide by zero") - return a / b + return "Cannot divide by zero" + result = a / b + return f"{a} divided by {b} is {result}" if __name__ == "__main__": try: @@ -32,4 +35,4 @@ if __name__ == "__main__": mcp.run() except Exception as e: logger.error(f"Server error: {e}") - raise \ No newline at end of file + raise diff --git a/swarms/prompts/agent_prompts.py b/swarms/prompts/agent_prompts.py index f8554063..e65ba009 100644 --- a/swarms/prompts/agent_prompts.py +++ b/swarms/prompts/agent_prompts.py @@ -1,20 +1,23 @@ # Agent prompts for MCP testing and interactions -MATH_AGENT_PROMPT = '''You are a math calculator agent that performs basic arithmetic operations. +MATH_AGENT_PROMPT = '''You are a helpful math calculator assistant. +Your role is to understand natural language math requests and perform calculations. -Available operations: -- Addition: add numbers together -- Multiplication: multiply numbers -- Division: divide numbers (checks for division by zero) +When asked to perform calculations: +1. Determine the operation (add, multiply, or divide) +2. Extract the numbers from the request +3. Use the appropriate math operation tool -You must respond with the operation and numbers in this exact format: -{"tool_name": "", "a": , "b": } +Respond conversationally but be concise. Example: -User: "add 5 and 3" -You: {"tool_name": "add", "a": 5, "b": 3} +User: "what is 5 plus 3?" +You: Using the add operation for 5 and 3 +{"tool_name": "add", "a": 5, "b": 3} -Parse the numbers as integers. Only return the operation format, no other text.''' +User: "multiply 4 times 6" +You: Using multiply for 4 and 6 +{"tool_name": "multiply", "a": 4, "b": 6}''' FINANCE_AGENT_PROMPT = """You are a financial analysis agent with access to stock market data services. Key responsibilities: @@ -177,4 +180,4 @@ def get_report_by_type(report_type): "resource_report": generate_resource_report_prompt, "outline_report": generate_outline_report_prompt, } - return report_type_mapping[report_type] + return report_type_mapping[report_type] \ No newline at end of file