-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
45 lines (36 loc) · 1.19 KB
/
client.py
File metadata and controls
45 lines (36 loc) · 1.19 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
from langchain_groq import ChatGroq
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from dotenv import load_dotenv
load_dotenv()
import asyncio
async def main():
client = MultiServerMCPClient(
{
"math":{
"command": "python",
"args": ["mathserver.py"],
"transport": "stdio"
},
"weather":{
"url": "http://localhost:8000/mcp",
"transport": "streamable_http"
}
}
)
import os
os.environ["GROQ_API_KEY"]=os.getenv("GROQ_API_KEY")
tools=await client.get_tools()
model=ChatGroq(model="qwen-qwq-32b")
agent=create_react_agent(
model,tools
)
math_response = await agent.ainvoke(
{"messages": [{"role": "user", "content": "what's (3 + 5) x 12?"}]}
)
print("Math response:", math_response['messages'][-1].content)
weather_response = await agent.ainvoke(
{"messages": [{"role": "user", "content": "what is the weather in California?"}]}
)
print("Weather response:", weather_response['messages'][-1].content)
asyncio.run(main())