from dotenv import dotenv_values
from langchain_openai import ChatOpenAI
from typing import Literal
from tavily import TavilyClient
from deepagents import create_deep_agent
env_vars = dotenv_values('.env')
OPENAI_KEY = env_vars['OPENAI_API_KEY']
OPENAI_BASE_URL = env_vars['OPENAI_API_BASE']
llm = ChatOpenAI(model="gpt-4o-mini", api_key=OPENAI_KEY, base_url=OPENAI_BASE_URL)
tavily_client = TavilyClient(api_key=env_vars['TAVILY_KEY'] )
def internet_search(
query: str,
max_results: int = 5,
topic: Literal["general", "news", "finance"] = "general",
include_raw_content: bool = False,
):
"""Run a web search"""
return tavily_client.search(
query,
max_results=max_results,
include_raw_content=include_raw_content,
topic=topic,
)
# System prompt to steer the agent to be an expert researcher
research_instructions = """You are an expert researcher. Your job is to conduct thorough research and then write a polished report.
You have access to an internet search tool as your primary means of gathering information.
## `internet_search`
Use this to run an internet search for a given query. You can specify the max number of results to return, the topic, and whether raw content should be included.
"""
agent = create_deep_agent(model=llm, tools=[internet_search], system_prompt=research_instructions)
result = agent.invoke({"messages": [{"role": "user", "content": "what is langgraph?"}]})
# Print the agent's response
print(111, result["messages"][-1].content)
Sort: Trending