|
| 1 | +--- |
| 2 | +title: Quickstart |
| 3 | +--- |
| 4 | + |
| 5 | +To create a research agent that can conduct thorough investigations: |
| 6 | + |
| 7 | +<CodeGroup> |
| 8 | + |
| 9 | +```python Python |
| 10 | +from tavily import TavilyClient |
| 11 | +from deepagents import create_deep_agent |
| 12 | +import os |
| 13 | + |
| 14 | +def internet_search(query): |
| 15 | + tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"]) |
| 16 | + return tavily_client.search(query) |
| 17 | + |
| 18 | +research_instructions = """You are an expert researcher. |
| 19 | +Your job is to conduct thorough research, and then write a polished report. |
| 20 | +
|
| 21 | +You have access to tools for internet search and file operations. |
| 22 | +""" |
| 23 | + |
| 24 | +agent = create_deep_agent( |
| 25 | + tools=[internet_search], |
| 26 | + instructions=research_instructions |
| 27 | +) |
| 28 | + |
| 29 | +result = agent.invoke({ |
| 30 | + "messages": [{"role": "user", "content": "what is langgraph?"}] |
| 31 | +}) |
| 32 | +``` |
| 33 | + |
| 34 | +```typescript JavaScript |
| 35 | +import { TavilySearch } from "@langchain/tavily"; |
| 36 | +import { createDeepAgent } from "deepagents"; |
| 37 | + |
| 38 | +// Search tool to use to do research |
| 39 | +const internetSearch = new TavilySearch({ |
| 40 | + maxResults: 5, |
| 41 | + tavilyApiKey: process.env.TAVILY_API_KEY, |
| 42 | +}); |
| 43 | + |
| 44 | +// Prompt prefix to steer the agent to be an expert researcher |
| 45 | +const researchInstructions = `You are an expert researcher. Your job is to conduct thorough research, and then write a polished report. |
| 46 | +
|
| 47 | +You have access to a few tools. |
| 48 | +
|
| 49 | +## \`internet_search\` |
| 50 | +
|
| 51 | +Use this to run an internet search for a given query. You can specify the number of results, the topic, and whether raw content should be included. |
| 52 | +`; |
| 53 | + |
| 54 | +// Create the agent |
| 55 | +const agent = createDeepAgent({ |
| 56 | + tools: [internetSearch], |
| 57 | + instructions: researchInstructions, |
| 58 | +}); |
| 59 | + |
| 60 | +// Invoke the agent |
| 61 | +const result = await agent.invoke({ |
| 62 | + messages: [{ role: "user", content: "what is langgraph?" }] |
| 63 | +}); |
| 64 | +``` |
| 65 | + |
| 66 | +</CodeGroup> |
| 67 | + |
| 68 | +The agent created with `createDeepAgent` is a LangGraph graph, so you can interact with it (streaming, human-in-the-loop, memory, studio) the same way you would any LangGraph agent. |
0 commit comments