Close Menu
  • AI
  • Content Creation
  • Tech
  • Robotics
AI-trends.todayAI-trends.today
  • AI
  • Content Creation
  • Tech
  • Robotics
Trending
  • DeepSeek AI releases DeepSeek V4: Sparse attention and heavily compressed attention enable one-million-token contexts.
  • AI-Designed drugs by a DeepMind spinoff are headed to human trials
  • Apple’s new CEO must launch an AI killer product
  • OpenMythos Coding Tutorial: Recurrent-Depth Transformers, Depth Extrapolation and Mixture of Experts Routing
  • 5 Reasons to Think Twice Before Using ChatGPT—or Any Chatbot—for Financial Advice
  • OpenAI Releases GPT-5.5, a Absolutely Retrained Agentic Mannequin That Scores 82.7% on Terminal-Bench 2.0 and 84.9% on GDPval
  • Your Favorite AI Gay Thirst Traps: The Men Behind them
  • Mend Releases AI Safety Governance Framework: Masking Asset Stock, Danger Tiering, AI Provide Chain Safety, and Maturity Mannequin
AI-trends.todayAI-trends.today
Home»Tech»LangChain’s DeepAgents Library: A Practical Example of How DeepAgents Work

LangChain’s DeepAgents Library: A Practical Example of How DeepAgents Work

Tech By Gavin Wallace20/10/20257 Mins Read
Facebook Twitter LinkedIn Email
Can LLMs Really Judge with Reasoning? Microsoft and Tsinghua Researchers
Can LLMs Really Judge with Reasoning? Microsoft and Tsinghua Researchers
Share
Facebook Twitter LinkedIn Email

While a basic Large Language Model (LLM) agent—one that repeatedly calls external tools—is easy to create, these agents often struggle with long and complex tasks because they lack the ability to plan ahead and manage their work over time. These agents can be considered “shallow” They are executed in their entirety.

It is important to note that the word “you” means “you”. deepagents library This limitation is overcome by implementing a generic architecture that takes inspiration from advanced applications such as Deep Research and Claude Code.

Four key features combine to give this agent architecture more depth.

  • Plan your trip with this tool This allows the agent to break down complex tasks into smaller, more manageable chunks before taking action.
  • Sub-Agents– Allows the agent in charge to assign specific tasks to agents who are more focused.
  • Access to File SystemProvides persistent memories for work-in progress, notes and final outputs. This allows the agent to pick up where it left.
  • The Detailed Request: Provide the agent with clear directions, context and constraints regarding its long-term goals.

Deepagents provides developers with the foundational elements they need to create powerful agents capable of managing state and executing complex workflows.

This article will show you how DeepAgents work. Click here to find out more FULL CODES here.

DeepAgents Core Capabilities

1. Plan and Break Down TasksDeepAgents include a write_todos function that breaks down complex tasks into small, manageable chunks. The agents can monitor their progress, and make adjustments to the plan as new information is learned.

2. Context ManagementAgents can use file-related tools such as ls to store data outside of their short term memory. The agents can handle large or detailed tasks without any problems.

3. Sub Agent CreationThe agent can create small, targeted subagents using the built-in Task tool. The sub-agents focus on specific aspects of the problem, without clogging up the context for the agent.

4. Long-Term MemoryAgents can now remember data across multiple sessions with the help of LangGraph’s Store. They are able to recall their previous work and conversations.

Set up Dependencies

!pip install deepagents tavily-python langchain-google-genai langchain-openai

Environment Variables

We will use OpenAI API Key to run our Deep Agent in this tutorial. For reference, however, we will also demonstrate how you can instead use a Gemini Model.

You’re free to choose any model provider you prefer — OpenAI, Gemini, Anthropic, or others — as DeepAgents works seamlessly with different backends. You can check out the FULL CODES here.

Import os
From getpass import Getpass
os.environ['TAVILY_API_KEY'] Getpass ('Enter Tavily API key:'
os.environ['OPENAI_API_KEY'] = getpass('Enter OpenAI API Key: ')
os.environ['GOOGLE_API_KEY'] = getpass('Enter Google API Key: ')

Importing libraries

Import os
Literal import is the opposite of typing.
Import TavilyClient from tavily
Create deep agents from the import of deepagents


TavilyClient()

The Right Tool

A Deep Agent, like other agents who use tools for their tasks, can be provided with an array of useful tools.

This example will give the agent a Tavily Search Tool, which he can use to collect real-time web information. Visit the FULL CODES here.

Literal import is the opposite of typing.
from langchain.chat_models import init_chat_model
Create deep agents from the import of deepagents


Internet_search = def
    query: str,
 max_results int = 5
 Topic:["general", "news", "finance"] = "general",
    include_raw_content: bool = False,
):
    """Run a web search"""
    search_docs = tavily_client.search(
        query,
        max_results=max_results,
        include_raw_content=include_raw_content,
        topic=topic,
    )
 Return search_docs

Sub-Agents

Deep Agents’ most powerful feature is the subagent. They allow the main agent to delegate specific parts of a complex task to smaller, specialized agents — each with its own focus, tools, and instructions. The main agent can keep his context organized and clean while still being able to work deeply on subtasks.

Two subagents are defined in the following example.

  • policy-research-agent — a specialized researcher that conducts in-depth analysis on AI policies, regulations, and ethical frameworks worldwide. The tool uses internet_search to collect real-time data and produce a professional, well-structured report.
  • policy-critique-agent — an editorial agent responsible for reviewing the generated report for accuracy, completeness, and tone. This ensures the research is factual and balanced. It also aligns with legal frameworks in each region.

These subagents work together to enable the Deep Agent’s main function of research, quality assurance, and analysis in a modular, structured workflow. See the FULL CODES here.

sub_research_prompt = """
You are an AI specialist policy researcher.
Research in depth government policies, international regulations and ethical frameworks relating to artificial intelligence.

Answer:
Key updates and trends
Include all relevant laws and sources (e.g. EU AI Act; U.S. Exec Orders).
Compare global perspectives when appropriate
- Be written in clear, professional language

Your FINAL message is the only one that will be sent back to your main agent.
"""

research_sub_agent = {
    "name": "policy-research-agent",
    "description": "Used to research specific AI policy and regulation questions in depth.",
    "system_prompt": sub_research_prompt,
    "tools": [internet_search],
}


sub_critique_prompt = """
You are an editor of a government report.
You can find the questions and answers in question.txt.

Focus on:
Accuracy, completeness and relevance of information
Citation of policies in the correct manner
A balanced analysis of regional variations
Clarity, neutrality and tone

Please provide feedback constructively, but DO NOT directly alter the report.
"""

critique_sub_agent = {
    "name": "policy-critique-agent",
    "description": "Critiques AI policy research reports for completeness, clarity, and accuracy.",
    "system_prompt": sub_critique_prompt,
}

System Prompt

Deep Agents come with a system prompt built in that is their main set of instructions. The system prompt in Claude Code inspired this prompt, which is intended to be more generic and provide guidance on using built-in features like planning, filing system operations, or subagent collaboration.

It’s recommended that you create a customized system prompt to suit your use case. The prompt design is crucial in determining the reasoning and structure of an agent, as well as its overall performance.

In our example, we defined a custom prompt called policy_research_instructions, which transforms the agent into an expert AI policy researcher. It clearly outlines a step-by-step workflow — saving the question, using the research subagent for analysis, writing the report, and optionally invoking the critique subagent for review. This tool enforces the best practices, such as Markdown, citation style and professional tone, to make sure that your final report is up-to-date with policy standards. Click here to view the FULL CODES here.

policy_research_instructions = """
Your expertise is in AI research and analysis.
It is your job to research questions related to AI governance, ethics, global regulation and regulatory frameworks.

1️⃣ Save the user's question to `question.txt`
2️⃣ Use the `policy-research-agent` to perform in-depth research
3️⃣ Write a detailed report to `final_report.md`
4️⃣ Optionally, ask the `policy-critique-agent` to critique your draft
5️⃣ Revise if necessary, then output the final, comprehensive report

Write the report final:
Use the Markdown format with sections that are clearly marked (#)
Citations are included in [Title]The URL format
The ### sources section should be added at the end.
Use a professional and neutral tone for your policy briefings
"""

Main Agent

This is how we create our Deep Agent main using the Create_deep_agent function.() function. Initialize the model by using OpenAI’s gpt-4oYou can switch easily to Google Gemini 2.5 flash model if you prefer. The agent is configured with the internet_search tool, our custom policy_research_instructions system prompt, and two subagents — one for in-depth research and another for critique.

DeepAgents uses the default language for its internal use. Claude Sonnet 4.5 Check out the LangChain library. See the FULL CODES here.

model = init_chat_model(model="openai:gpt-4o")
# model = init_chat_model(model="google_genai:gemini-2.5-flash")
Create deep agent with the code: Agent = create_deep_agent
    model=model,
    tools=[internet_search],
    system_prompt=policy_research_instructions,
    subagents=[research_sub_agent, critique_sub_agent],
)

Invoking Agent

Questionresult = Agent.invoke () "What are the latest updates on the EU AI Act and its global impact?"
result = agent.invoke({"messages": [{"role": "user", "content": query}]})

Click here to find out more FULL CODES here. Please feel free to browse our GitHub Page for Tutorials, Codes and Notebooks. Also, feel free to follow us on Twitter Join our Facebook group! 100k+ ML SubReddit Subscribe Now our Newsletter. Wait! What? now you can join us on telegram as well.


I’m a Civil Engineering graduate (2022) at Jamia Millia Islamia in New Delhi. I’m interested in Data Science and especially Neural networks and how they can be applied in different areas.

🙌 Follow MARKTECHPOST: Add us as a preferred source on Google.

AI ar work x
Share. Facebook Twitter LinkedIn Email
Avatar
Gavin Wallace

Related Posts

DeepSeek AI releases DeepSeek V4: Sparse attention and heavily compressed attention enable one-million-token contexts.

24/04/2026

OpenMythos Coding Tutorial: Recurrent-Depth Transformers, Depth Extrapolation and Mixture of Experts Routing

24/04/2026

OpenAI Releases GPT-5.5, a Absolutely Retrained Agentic Mannequin That Scores 82.7% on Terminal-Bench 2.0 and 84.9% on GDPval

24/04/2026

Mend Releases AI Safety Governance Framework: Masking Asset Stock, Danger Tiering, AI Provide Chain Safety, and Maturity Mannequin

24/04/2026
Top News

Politico’s Newsroom Is Starting a Legal Battle With Management Over AI

OpenAI should stop naming its creations after products that already exist

Meet the Chinese Startup Using AI—and a Small Army of Workers—to Train Robots

o1’s Thoughts on LNMs and LMMs • AI Blog

AI and the Enshittification Trap

Load More
AI-Trends.Today

Your daily source of AI news and trends. Stay up to date with everything AI and automation!

X (Twitter) Instagram
Top Insights

This paper presents a full implementation of the code to design a graph-structured agent using Gemini, for task planning, retrieval and computation.

24/08/2025

Modular Python Guide for Building AI Agents that are Event Driven with UAgents & Google Gemini

22/06/2025
Latest News

DeepSeek AI releases DeepSeek V4: Sparse attention and heavily compressed attention enable one-million-token contexts.

24/04/2026

AI-Designed drugs by a DeepMind spinoff are headed to human trials

24/04/2026
X (Twitter) Instagram
  • Privacy Policy
  • Contact Us
  • Terms and Conditions
© 2026 AI-Trends.Today

Type above and press Enter to search. Press Esc to cancel.