Skip to main content

Quickstart

This guide walks you through creating your first deep agent with file system tools and subagent capabilities. You will build a research agent that can conduct research and write reports.

Build the Deep Agents research quickstart

Build a Deep Agents research agent in this working directory by following the Deep Agents quickstart.

Step 1: Read the guide

Detect whether this project uses Python or TypeScript/JavaScript. Fetch and follow the matching page; treat it as the source of truth for package names, model strings, search-tool setup, and code:

Step 2: Install dependencies

Install deepagents (and langchain / @langchain/core on TypeScript) with the package manager already used in this project. Add Tavily only if the user is not using a Google, OpenAI, or Anthropic built-in provider search tool.

Step 3: Configure model credentials

Check for a supported provider API key (for example GOOGLE_API_KEY, OPENAI_API_KEY, or ANTHROPIC_API_KEY). If none is set, ask the user which provider to use, then stop and wait while they create a key and set it in the shell or a .env file. Do not invent, hardcode, or commit API keys. If they need Tavily, ask them to set TAVILY_API_KEY the same way.

Step 4: Implement the research agent

Follow the quickstart steps in order:

  1. Create the internet search tool (prefer the provider built-in search tool when the chosen model supports it; otherwise use Tavily).
  2. Call create_deep_agent with the search tool, a provider:model string (or initialized model) from the guide, and the research system prompt shown on the page.
  3. For optional LangSmith tracing, follow https://docs.langchain.com/langsmith/create-an-agent to register an agent in an agent-based workspace. Ask the user to set LANGSMITH_AGENT_ID, LANGSMITH_AGENT_ENVIRONMENT, LANGSMITH_TRACING=true, and LANGSMITH_API_KEY themselves.
  4. Run the agent on a sample research query from the guide and print the final response.

Rules

  • Stay scoped to this quickstart. Do not add Managed Deep Agents deployment, evals, or unrelated frameworks.
  • Prefer provider built-in web search when available; use Tavily only when needed.
  • Ask rather than guess when a secret, provider choice, or project convention is unclear.

Tip

Using an AI coding assistant?

  • Install the LangChain Docs MCP servers to give your agent access to up-to-date LangChain documentation and examples.

    Connect LangChain docs MCP servers

    Connect both LangChain documentation MCP servers to my coding agent so it can look up current LangChain, LangGraph, and LangSmith docs and API reference.

    Servers to add:

    Detect which agent or editor I am using (Claude Code, Cursor, Codex CLI, Claude Desktop, Deep Agents Code, VS Code, Antigravity, or another MCP-compatible client). Use the matching setup from https://docs.langchain.com/use-these-docs.md:

    • Claude Code: claude mcp add --transport http for each server (project scope by default; use --scope user only if I ask for global access).
    • Codex CLI: codex mcp add with each server URL.
    • Cursor, Deep Agents Code, VS Code, or Antigravity: merge both entries into the MCP settings JSON using the field names shown on that page for my client.
    • Claude Desktop: add both URLs under Settings > Connectors.

    Do not invent alternate MCP URLs. After configuring, confirm both servers are listed and reachable.

  • Install LangChain Skills to improve your agent's performance on LangChain ecosystem tasks.

    Install LangChain Skills

    Install LangChain Skills for my coding agent so it can perform better on LangChain, LangGraph, and Deep Agents tasks.

    Use the Agent Skills installer from https://github.com/langchain-ai/langchain-skills:

    npx skills add langchain-ai/langchain-skills --skill '*' --yes

    If I ask for a global install instead, use:

    npx skills add langchain-ai/langchain-skills --skill '*' --yes --global

    Detect which agent or editor I am using. If I use Claude Code and prefer the plugin path, follow the marketplace install from that repository README (/plugin marketplace add then /plugin install). Do not invent alternate skill package names or install URLs. After installing, confirm the skills are available to the agent.

Prerequisites

Before you begin, make sure you have an API key from a model provider (e.g., Gemini, Anthropic, OpenAI).

Note

Deep Agents require a model that supports tool calling. See customization for how to configure your model.

Step 1: Install dependencies

npm install deepagents langchain @langchain/core
yarn add deepagents langchain @langchain/core
pnpm add deepagents langchain @langchain/core

Note

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:

npm install @langchain/tavily

Step 2: Set up your API keys

export GOOGLE_API_KEY="your-api-key"
export OPENAI_API_KEY="your-api-key"
export ANTHROPIC_API_KEY="your-api-key"
export OPENROUTER_API_KEY="your-api-key"
export TAVILY_API_KEY="your-tavily-api-key"
export FIREWORKS_API_KEY="your-api-key"
export TAVILY_API_KEY="your-tavily-api-key"
export BASETEN_API_KEY="your-api-key"
export TAVILY_API_KEY="your-tavily-api-key"
# Local: Ollama must be running on your machine
# Cloud: Set your Ollama API key for hosted inference
export OLLAMA_API_KEY="your-api-key"
export TAVILY_API_KEY="your-tavily-api-key"
# Set the API key for your provider
export <PROVIDER>_API_KEY="your-api-key"
export TAVILY_API_KEY="your-tavily-api-key"

Deep Agents work with any LangChain chat model. Set the API key for your provider.

Tip

Using LangSmith Gateway

The LangSmith Gateway routes most major providers through LangSmith. You can bring your own provider keys, or use Gateway Credits to access models without a provider 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.

import { createDeepAgent } from "deepagents";

// Google's built-in search — no extra install or API key needed
const internetSearch = { googleSearch: {} };
import { createDeepAgent } from "deepagents";

// OpenAI's built-in web search — no extra install or API key needed
const internetSearch = { type: "web_search_preview" };
import { createDeepAgent } from "deepagents";

// Anthropic's built-in web search — no extra install or API key needed
const internetSearch = { type: "web_search_20250305", name: "web_search" };
import { tool } from "langchain";
import { TavilySearch } from "@langchain/tavily";
import { z } from "zod";

const internetSearch = tool(
  async ({
    query,
    maxResults = 5,
    topic = "general",
    includeRawContent = false,
  }: {
    query: string;
    maxResults?: number;
    topic?: "general" | "news" | "finance";
    includeRawContent?: boolean;
  }) => {
    const tavilySearch = new TavilySearch({
      maxResults,
      tavilyApiKey: process.env.TAVILY_API_KEY,
      includeRawContent,
      topic,
    });
    return await tavilySearch._call({ query });
  },
  {
    name: "internet_search",
    description: "Run a web search",
    schema: z.object({
      query: z.string().describe("The search query"),
      maxResults: z
        .number()
        .optional()
        .default(5)
        .describe("Maximum number of results to return"),
      topic: z
        .enum(["general", "news", "finance"])
        .optional()
        .default("general")
        .describe("Search topic category"),
      includeRawContent: z
        .boolean()
        .optional()
        .default(false)
        .describe("Whether to include raw content"),
    }),
  },
);

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.

import { createDeepAgent } from "deepagents";

// System prompt to steer the agent to be an expert researcher
const researchInstructions = `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.
`;

const agent = createDeepAgent({
  model: "google:gemini-3.6-flash",
  tools: [internetSearch],
  systemPrompt: researchInstructions,
});
import { createDeepAgent } from "deepagents";

// System prompt to steer the agent to be an expert researcher
const researchInstructions = `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.
`;

const agent = createDeepAgent({
  model: "openai:gpt-5.5",
  tools: [internetSearch],
  systemPrompt: researchInstructions,
});
import { createDeepAgent } from "deepagents";

// System prompt to steer the agent to be an expert researcher
const researchInstructions = `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.
`;

const agent = createDeepAgent({
  model: "anthropic:claude-sonnet-5",
  tools: [internetSearch],
  systemPrompt: researchInstructions,
});
import { createDeepAgent } from "deepagents";

// System prompt to steer the agent to be an expert researcher
const researchInstructions = `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.
`;

const agent = createDeepAgent({
  model: "openrouter:z-ai/glm-5.2",
  tools: [internetSearch],
  systemPrompt: researchInstructions,
});
import { createDeepAgent } from "deepagents";

// System prompt to steer the agent to be an expert researcher
const researchInstructions = `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.
`;

const agent = createDeepAgent({
  model: "fireworks:accounts/fireworks/models/glm-5p2",
  tools: [internetSearch],
  systemPrompt: researchInstructions,
});
import { createDeepAgent } from "deepagents";

// System prompt to steer the agent to be an expert researcher
const researchInstructions = `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.
`;

const agent = createDeepAgent({
  model: "baseten:zai-org/GLM-5.2",
  tools: [internetSearch],
  systemPrompt: researchInstructions,
});
import { createDeepAgent } from "deepagents";

// System prompt to steer the agent to be an expert researcher
const researchInstructions = `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.
`;

const agent = createDeepAgent({
  model: "ollama:north-mini-code-1.0",
  tools: [internetSearch],
  systemPrompt: researchInstructions,
});

Step 5: Set up LangSmith tracing

Note

In an agent-based workspace, create an agent once before sending traces. Use agent addressing to select its identifier and environment. If an integration requires project_name, use the selected environment's tracer_session_name as a compatibility value.

LangSmith provides you with visibility into your agent's execution, allowing you to view tool calls, subagent delegation, and LLM responses.

Sign up at smith.langchain.com, create an API key, and set these environment variables:

export LANGSMITH_AGENT_ID="<your-agent-id>"
export LANGSMITH_AGENT_ENVIRONMENT="production"
export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY="your-langsmith-api-key"

Step 6: Run the agent

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

// Print the agent's response
console.log(result.messages[result.messages.length - 1].content);

How does it work?

Your deep agent automatically:

  1. Conducts research by calling the internet_search tool to gather information.
  2. Manages context by using file system tools (write_file, read_file) to offload large search results.
  3. Spawns subagents as needed to delegate complex subtasks to specialized subagents.
  4. Synthesizes a report to compile findings into a coherent response.

To add structured task planning with write_todos, opt in with TodoListMiddleware. See Task planning.

Examples

For examples of agents and patterns 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.