Documentation Index

Fetch the complete documentation index at: /llms.txt

Use this file to discover all available pages before exploring further.

Skip to main content
This guide walks you through creating your first deep agent with planning, file system tools, and subagent capabilities. You will build a research agent that can conduct research and write reports.
Using an AI coding assistant?
  • Install the LangChain Docs MCP server to give your agent access to up-to-date LangChain documentation and examples.
  • Install LangChain Skills to improve your agent’s performance on LangChain ecosystem tasks.

Prerequisites

Before you begin, make sure you have an API key from a model provider (e.g., Gemini, Anthropic, OpenAI).
Deep Agents require a model that supports tool calling. See customization for how to configure your model.

Step 1: Install dependencies

pip install deepagents
uv init
uv add deepagents
uv sync
Google, OpenAI, and Anthropic all provide built-in web search tools: no extra package or API key required. If you use a different provider or prefer Tavily for search, install the Tavily package as well:
pip install tavily-python

Step 2: Set up your API keys

  • Google
  • OpenAI
  • Anthropic
  • OpenRouter
  • Fireworks
  • Baseten
  • Ollama
  • Other
export GOOGLE_API_KEY="your-api-key"

Step 3: Create a search tool

Google, OpenAI, and Anthropic offer built-in web search tools that run server-side: no extra package or API key needed. Pass a provider tool dict directly to create_deep_agent.
  • Tavily (any provider)

Step 4: Create a deep agent

Pass your search tool and model to create_deep_agent. Pass a model string in provider:model format, or an initialized model instance. See supported models for all providers and suggested models for tested recommendations.
# 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="google_genai:gemini-3.5-flash",
    tools=[internet_search],
    system_prompt=research_instructions,
)
# 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="openai:gpt-5.5",
    tools=[internet_search],
    system_prompt=research_instructions,
)
# 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,
)
# 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="openrouter:z-ai/glm-5.2",
    tools=[internet_search],
    system_prompt=research_instructions,
)
# 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="fireworks:accounts/fireworks/models/glm-5p2",
    tools=[internet_search],
    system_prompt=research_instructions,
)
# 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="baseten:zai-org/GLM-5.2",
    tools=[internet_search],
    system_prompt=research_instructions,
)
# 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="ollama:north-mini-code-1.0",
    tools=[internet_search],
    system_prompt=research_instructions,
)

Step 5: Set up LangSmith tracing

LangSmith provides you with visibility into your agent’s execution, allowing you to view planning steps, tool calls, subagent delegation, and LLM responses. Sign up at smith.langchain.com, create an API key, and set these environment variables:
export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY="your-langsmith-api-key"

Step 6: Run the agent

result = agent.invoke({"messages": [{"role": "user", "content": "What is langgraph?"}]})

# Print the agent's response
print(result["messages"][-1].content)

How does it work?

Your deep agent automatically:
  1. Plans its approach using the built-in write_todos tool to break down the research task.
  2. Conducts research by calling the internet_search tool to gather information.
  3. Manages context by using file system tools (write_file, read_file) to offload large search results.
  4. Spawns subagents as needed to delegate complex subtasks to specialized subagents.
  5. Synthesizes a report to compile findings into a coherent response.

Examples

For agents, patterns, and applications you can build with Deep Agents, see Examples.

Streaming

Deep Agents have built-in streaming for real-time updates from agent execution using LangGraph. This allows you to observe output progressively and review and debug agent and subagent work, such as tool calls, tool results, and LLM responses.

Next steps

Now that you’ve built your first deep agent:
  • Customize your agent: Learn about customization options, including custom system prompts, tools, and subagents.
  • Add long-term memory: Enable persistent memory across conversations.
  • Deploy to production: Use Managed Deep Agents to create, run, and operate deep agents in LangSmith.
  • Test and evaluate: Use LangSmith evaluation to run automated tests and measure your agent’s performance against a dataset.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.