Repository navigation
Expand file tree
/
Copy pathquickstart.py
More file actions
58 lines (43 loc) · 1.61 KB
/
Copy pathquickstart.py
File metadata and controls
58 lines (43 loc) · 1.61 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
"""Quickstart: build a research agent with a search tool."""
# :snippet-start: quickstart-search-tool-py
import os
from typing import Literal
from tavily import TavilyClient
from deepagents import create_deep_agent
tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_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,
)
# :snippet-end:
# :snippet-start: quickstart-create-agent-py
# 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="anthropic:claude-sonnet-4-6",
tools=[internet_search],
system_prompt=research_instructions,
)
# :snippet-end:
# :snippet-start: quickstart-run-agent-py
result = agent.invoke({"messages": [{"role": "user", "content": "What is langgraph?"}]})
# Print the agent's response
print(result["messages"][-1].content)
# :snippet-end:
# :remove-start:
assert result is not None
assert result["messages"][-1].content
# :remove-end: