| title | Build a deep research agent |
|---|---|
| sidebarTitle | Deep Research |
| description | Build a multi-step web research agent with subagent delegation |
import DeepResearchToolsPy from '/snippets/code-samples/deep-research-tools-py.mdx'; import DeepResearchAgentClaudePy from '/snippets/code-samples/deep-research-agent-claude-py.mdx'; import DeepResearchRunSyncPy from '/snippets/code-samples/deep-research-run-sync-py.mdx'; import DeepResearchRunStreamPy from '/snippets/code-samples/deep-research-run-stream-py.mdx'; import DeepResearchToolsJs from '/snippets/code-samples/deep-research-tools-js.mdx'; import DeepResearchAgentClaudeJs from '/snippets/code-samples/deep-research-agent-claude-js.mdx'; import DeepResearchRunSyncJs from '/snippets/code-samples/deep-research-run-sync-js.mdx'; import DeepResearchRunStreamJs from '/snippets/code-samples/deep-research-run-stream-js.mdx'; import DeepResearchWorkflowInstructionsPy from '/snippets/code-samples/deep-research-workflow-instructions-py.mdx'; import DeepResearchWorkflowInstructionsJs from '/snippets/code-samples/deep-research-workflow-instructions-js.mdx'; import DeepResearchResearcherInstructionsPy from '/snippets/code-samples/deep-research-researcher-instructions-py.mdx'; import DeepResearchResearcherInstructionsJs from '/snippets/code-samples/deep-research-researcher-instructions-js.mdx'; import DeepResearchSubagentDelegationInstructionsPy from '/snippets/code-samples/deep-research-subagent-delegation-instructions-py.mdx'; import DeepResearchSubagentDelegationInstructionsJs from '/snippets/code-samples/deep-research-subagent-delegation-instructions-js.mdx'; import DeepResearchAgentGeminiPy from '/snippets/code-samples/deep-research-agent-gemini-py.mdx';
This guide demonstrates how to build a multi-step web research agent from scratch using Deep Agents. The agent decomposes research questions into focused tasks, delegates them to specialized sub-agents, and synthesizes findings into a comprehensive report.
The agent you build will:
- Plan research using the opt-in todo list middleware
- Delegate focused research tasks to sub-agents with isolated context
- Assess search results and plan next steps as you gather information
- Synthesize findings with proper citations into a final report
The spawned sub-agents will conduct web searches with Tavily, fetching full webpage content for analysis.
This tutorial covers:
- Subagents for parallel, context-isolated research
- Custom tools for web search
- Multi-step planning with the opt-in planning tool
API keys for:
- Anthropic (Claude) or Google (Gemini)
- Tavily for web search (optional - free tier sufficient)
- LangSmith for tracing (optional)
:::python
mkdir deep-research-agent
cd deep-research-agentuv init
uv add deepagents tavily-python httpx markdownify langchain-anthropic langchain-core
uv syncuv init
uv add deepagents tavily-python httpx markdownify langchain-google-genai langchain-core
uv sync:::js
mkdir deep-research-agent
cd deep-research-agent:::python
Create agent.py in your project directory:
:::
:::js
Create agent.ts in your project directory:
:::
Add the custom search tool. The tavily_search tool uses Tavily for URL discovery, then fetches full webpage content so the agent can analyze complete sources instead of summaries.
:::python :::
:::js :::
:::python
Add the orchestrator workflow and sub-agent prompt templates to agent.py:
:::
:::js
Add the orchestrator workflow and sub-agent prompt templates to agent.ts:
:::
:::python
:::
:::js
:::
Task planning is opt-in. The research workflow uses write_todos to break questions into focused tasks, so pass @[TodoListMiddleware] when you create the agent.
:::python
from langchain.agents.middleware import TodoListMiddleware:::
:::js
import { todoListMiddleware } from "langchain";:::
You include this middleware in the next step when you create the agent.
:::python
Add the model initialization and agent creation to agent.py. Choose your provider. Include @[TodoListMiddleware] so the planning tool is available:
:::js
Add the model initialization and agent creation to agent.ts. Include todoListMiddleware so the planning tool is available:
You can run the agent synchronously, meaning it will wait for the full result and then print it, or you can stream updates as they come in.
:::python
Add the code from the respective tab at the bottom of agent.py:
:::
:::js
Add the code from the respective tab at the bottom of agent.ts:
:::
:::python :::
:::js :::
:::python :::
:::js :::
Run the agent from the project root:
:::python
python agent.py:::
:::js
npx tsx agent.ts:::
If you set the LANGSMITH_API_KEY environment variable before running, you can view the agent's traces in LangSmith to debug and monitor multi-step behavior.
View the complete Deep Research example on GitHub.
Now that you've built the agent, customize it by changing the prompt constants in your agent file to adjust the workflow, delegation strategy, or researcher behavior. You can also tune the delegation limits to allow for more parallel sub-agents or delegation rounds.
For more information on the concepts in this tutorial, check out the following resources:
- Subagents: Learn how to configure subagents with different tools and prompts
- Customization: Customize models, tools, system prompts, and optional task planning
- LangSmith: Trace research runs and debug multi-step behavior
- Deep Research Course: Full course on deep research with LangGraph