-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
59 lines (49 loc) · 1.83 KB
/
Copy pathapp.py
File metadata and controls
59 lines (49 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import asyncio
from dotenv import load_dotenv
import os
from mcp_use import MCPClient, MCPAgent
from langchain_groq import ChatGroq
async def run_memory_chat():
load_dotenv()
os.environ["GROQ_API_KEY"] = os.getenv("GROQ_API_KEY")
# Update this if your file is renamed or moved
config_file = "browser_mcp.json"
print("Initializing chat....")
# Load multiple services via config file
client = MCPClient.from_config_file(config_file)
# Use your preferred LLM - you can swap models here
llm = ChatGroq(model="gemma-7b-it")
# Initialize MCP agent with memory and expanded tools/services
agent = MCPAgent(
llm=llm,
client=client,
max_steps=20,
memory_enabled=True
)
print("\n===== Interactive MCP Chat with Enhanced Services =====")
print("Type 'exit' to end the conversation.")
print("Type 'clear' to clear the memory.")
print("=======================================================\n")
try:
while True:
user_input = input("You: ")
if user_input.lower() in ["exit", "quit"]:
print("Exiting chat....")
break
elif user_input.lower() == "clear":
agent.clear_memory()
print("Memory cleared.")
continue
print("\nAssistant: ", end="", flush=True)
try:
print("Sending to agent...")
response = await agent.run(user_input)
print("Got response.")
print(response)
except Exception as e:
print(f"An error occurred: {e}")
finally:
if client and client.sessions:
await client.close_all_sessions()
if __name__ == "__main__":
asyncio.run(run_memory_chat())