import asyncio from dotenv import load_dotenv from langchain_groq import ChatGroq from mcp_use import MCPAgent, MCPClient import os # Load env once load_dotenv() os.environ["GROQ_API_KEY"] = os.getenv("GROQ_API_KEY") # Initialize MCP client and agent once (memory preserved) CONFIG_FILE = "server/weather.json" client = MCPClient.from_config_file(CONFIG_FILE) llm = ChatGroq(model="qwen-qwq-32b") agent = MCPAgent( llm=llm, client=client, max_steps=15, memory_enabled=True # Keep memory for conversation ) async def run_memory_chat(question: str) -> str: """Run a single question through the MCPAgent and get a response.""" try: response = await agent.run(question) return response except Exception as e: return f"Error: {e}"