-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagents.py
More file actions
27 lines (20 loc) · 802 Bytes
/
agents.py
File metadata and controls
27 lines (20 loc) · 802 Bytes
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
from tools import get_current_weather, Usd_to_Inr, web_search, calculator_tool
from langchain.agents import create_agent
# =================== Agent Configuration ===================
def agents(model: str, query: str) -> str:
'''
Main function to create and run the agent with the provided model and user query.
'''
agent = create_agent(
model=model,
system_prompt="You are a helpful assistant. Be concise and short. Answer the user's queries using the available tools when necessary.",
tools=[get_current_weather, Usd_to_Inr, web_search, calculator_tool],
)
response = agent.invoke({
"messages": [{
"role": "user",
"content": query
}]
})
result = response["messages"][-1].content
return result