Skip to main content
This quickstart takes you from a simple setup to a fully functional AI agent in just a few minutes. A deep agent is a LangChain agent with batteries included—planning, file system tools, and subagents out of the box. Use deep agents when you want maximum capability with minimal setup; choose LangChain agents when you need fine-grained control.
LangChain Docs MCP serverIf you’re using an AI coding assistant or IDE (e.g. Claude Code or Cursor), you should install the LangChain Docs MCP server to get the most out of the docs. This ensures your agent has access to up-to-date LangChain documentation and examples.

Install dependencies

This guide uses Tavily as an example search provider, but you can substitute any search API (e.g., DuckDuckGo, SerpAPI, Brave Search).

Set up API keys

Get an API key from any supported model provider (for example, Claude (Anthropic) or OpenAI). If you are following along with the Tavily example, also get a Tavily API key. Set the API keys, for example:

Build a basic agent

Start by creating a simple agent that can answer questions and call tools. The agent in this example uses the specified language model, a basic weather function as a tool, and a simple prompt to guide its behavior:
You can use any model that supports tool calling by changing the model name in the code and setting up the appropriate API key.

Build a real-world agent

When building real-world agents, both LangChain and deep agents provide you with fine-grained control over tools, memory, and structured ouput. The main difference between both is that deep agents come with a range of commonly useful capabilities already built in. By following this example you will build a research agent that can conduct research and write reports. Along the way you will explore the following concepts:
  1. Detailed system prompts for better agent behavior
  2. Create tools that integrate with external data
  3. Model configuration for consistent responses
  4. Structured output for predictable results
  5. Conversational memory for chat-like interactions
  6. Testing your agent and using tracing
1

Define the system prompt

The system prompt defines your agent’s role and behavior. Keep it specific and actionable:
2

Create tools

Tools let a model interact with external systems by calling functions you define. Tools can depend on runtime context and also interact with agent memory.This example uses two tools, one for internet searches and one for obtaining the user’s location based on their user ID.
Tools should be well-documented: their name, description, and argument names become part of the model’s prompt. LangChain’s @[@tool decorator][@tool] adds metadata and enables runtime injection with the ToolRuntime parameter.
3

Configure your model

Set up your language model with the right parameters for your use case:
Depending on the model and provider chosen, initialization parameters may vary; refer to their reference pages for details.
4

Define response format

Optionally, define a structured response format if you need the agent responses to match a specific schema.
5

Add memory

Add memory to your agent to maintain state across interactions. This allows the agent to remember previous conversations and context.
In production, use a persistent checkpointer that saves message history to a database. See Add and manage memory for more details.
6

Create and run the agent

Now assemble your agent with all the components and run it:

Test your agent

Start by running your script. You may get different output than we did:
If you look at the output on both tabs, you notice an immediate difference in the structure and length of the responses. A 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.
For LangChain agents, you must implement more capabilities to get a similar level of service and can customize them along the way as needed.

Trace agent calls

Most interesting applications you build with LangChain make many calls to LLMs. As these applications get more complex, it becomes important to be able to inspect what exactly is going on inside your agent. The best way to do this is with LangSmith. Sign up for a LangSmith account and set these to start logging traces:
Once set, run your script again and then inspect what happened during your agent calls on LangSmith .
To learn more about tracing your agent with LangSmith, see the LangSmith documentation.

Next steps

You now have agents that can:
  • Understand context and remember conversations
  • Use tools intelligently
  • Provide structured responses in a consistent format
  • Handle user-specific information through context
  • Maintain conversation state across interactions
  • Plan, research, and synthesize (deep agents only)
Continue with: