|
|
|
@ -1,29 +1,30 @@
|
|
|
|
|
from swarms import Agent
|
|
|
|
|
from swarms.tools.mcp_integration import MCPServerSseParams
|
|
|
|
|
from loguru import logger
|
|
|
|
|
|
|
|
|
|
# Comprehensive math prompt that encourages proper JSON formatting
|
|
|
|
|
MATH_AGENT_PROMPT = """
|
|
|
|
|
You are a helpful math calculator assistant.
|
|
|
|
|
from swarms import Agent
|
|
|
|
|
from swarms.tools.mcp_integration import MCPServerSseParams
|
|
|
|
|
from loguru import logger
|
|
|
|
|
|
|
|
|
|
Your role is to understand natural language math requests and perform calculations.
|
|
|
|
|
When asked to perform calculations:
|
|
|
|
|
# Comprehensive math prompt that encourages proper JSON formatting
|
|
|
|
|
MATH_AGENT_PROMPT = """
|
|
|
|
|
You are a helpful math calculator assistant.
|
|
|
|
|
|
|
|
|
|
1. Determine the operation (add, multiply, or divide)
|
|
|
|
|
2. Extract the numbers from the request
|
|
|
|
|
3. Use the appropriate math operation tool
|
|
|
|
|
Your role is to understand natural language math requests and perform calculations.
|
|
|
|
|
When asked to perform calculations:
|
|
|
|
|
|
|
|
|
|
FORMAT YOUR TOOL CALLS AS JSON with this format:
|
|
|
|
|
{"tool_name": "add", "a": <first_number>, "b": <second_number>}
|
|
|
|
|
or
|
|
|
|
|
{"tool_name": "multiply", "a": <first_number>, "b": <second_number>}
|
|
|
|
|
or
|
|
|
|
|
{"tool_name": "divide", "a": <first_number>, "b": <second_number>}
|
|
|
|
|
1. Determine the operation (add, multiply, or divide)
|
|
|
|
|
2. Extract the numbers from the request
|
|
|
|
|
3. Use the appropriate math operation tool
|
|
|
|
|
|
|
|
|
|
Always respond with a tool call in JSON format first, followed by a brief explanation.
|
|
|
|
|
"""
|
|
|
|
|
FORMAT YOUR TOOL CALLS AS JSON with this format:
|
|
|
|
|
{"tool_name": "add", "a": <first_number>, "b": <second_number>}
|
|
|
|
|
or
|
|
|
|
|
{"tool_name": "multiply", "a": <first_number>, "b": <second_number>}
|
|
|
|
|
or
|
|
|
|
|
{"tool_name": "divide", "a": <first_number>, "b": <second_number>}
|
|
|
|
|
|
|
|
|
|
def initialize_math_system():
|
|
|
|
|
Always respond with a tool call in JSON format first, followed by a brief explanation.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def initialize_math_system():
|
|
|
|
|
"""Initialize the math agent with MCP server configuration."""
|
|
|
|
|
# Configure the MCP server connection
|
|
|
|
|
math_server = MCPServerSseParams(
|
|
|
|
@ -46,7 +47,7 @@
|
|
|
|
|
|
|
|
|
|
return math_agent
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
def main():
|
|
|
|
|
try:
|
|
|
|
|
logger.info("Initializing math system...")
|
|
|
|
|
math_agent = initialize_math_system()
|
|
|
|
@ -79,5 +80,5 @@
|
|
|
|
|
logger.error(f"System initialization error: {e}")
|
|
|
|
|
print(f"Failed to start the math system: {str(e)}")
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|