Close Menu
  • AI
  • Content Creation
  • Tech
  • Robotics
AI-trends.todayAI-trends.today
  • AI
  • Content Creation
  • Tech
  • Robotics
Trending
  • OpenRouter Cuts Three Suppliers After AI Immediate Publicity Findings – Unite.AI
  • A Group of Researchers from Columbia and CertiK Introduce TensorLean for Formal Verification of GPU Kernels
  • Collectively AI Discloses Immediate Leak After Coding Agent Uncovered Credential – Unite.AI
  • Dragos Finds Immediate Leaks and Stolen Keys in AI Provide Chains
  • Lean and Mathlib Communities Certify Claude-Assisted Riemann Proof – Unite.AI
  • AWS Routes HyperPod Inference Throughout Areas From One Endpoint – Unite.AI
  • DailyAI Briefing: A Lean-checked Riemann proof, plus 4 extra
  • Anthropic Shares Drop 8.5% in Second Session Throughout AI Selloff – Unite.AI
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

A Group of Researchers from Columbia and CertiK Introduce TensorLean for Formal Verification of GPU Kernels

22/11/2026

OpenAI Ships GPT-Stay-1.1 for Voice Brokers, Cuts Idle Value to $0.02/Min

21/11/2026

Meet Pondering Machines Inkling 2 Mini: 26B Looped MoE Runs on a 32GB Mac

21/11/2026

Baseten Releases Bison-1 and Groundhog-1, Topping Choice Mannequin Index

21/11/2026
Top News

OpenAI Invests in Startup That Makes use of Mind Implants to Detect Most cancers

AI is the First World We Live In

Attend Our Livestream to Learn What GPT-5 Means to ChatGPT Users

World Cup Frauds Are Harder To Spot

Elvis Tune Homeowners Search $41.1M From Anthropic Over 274 Songs

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

Present Muse Scores 47% on Meta’s Private Superintelligence Index – Unite.AI

07/11/2026

Exa 3.0 Search API Tops Perplexity, Courageous and Parallel on 8 Benchmarks

20/10/2026
Latest News

OpenRouter Cuts Three Suppliers After AI Immediate Publicity Findings – Unite.AI

22/11/2026

A Group of Researchers from Columbia and CertiK Introduce TensorLean for Formal Verification of GPU Kernels

22/11/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.