-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
39 lines (30 loc) · 1.04 KB
/
Copy pathagent.py
File metadata and controls
39 lines (30 loc) · 1.04 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
import os
from dotenv import load_dotenv
from langchain.agents import initialize_agent, Tool
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_google_genai import ChatGoogleGenerativeAI
# Load environment variables
load_dotenv()
# Get API keys
TAVILY_API_KEY = os.getenv("TAVILY_API_KEY")
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
# Ensure API keys are available
if not TAVILY_API_KEY or not GOOGLE_API_KEY:
raise ValueError("Please set TAVILY_API_KEY and GOOGLE_API_KEY in your .env file.")
# Setup Tavily search tool
search = TavilySearchResults()
tools = [
Tool(
name="Web Search",
func=search.run,
description="Useful for answering questions using web search.",
)
]
# Setup Google Generative AI (Gemini)
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", google_api_key=GOOGLE_API_KEY)
# Create the agent
agent = initialize_agent(
tools=tools, llm=llm, agent="zero-shot-react-description", verbose=True
)
def run_query(query: str) -> str:
return agent.run(query)