AI agents are becoming more useful as they move beyond answering questions and start handling tasks from start to finish. LangChain Deep Agents add more control and flexibility by helping agents break down work, use different tools, manage information, and coordinate smaller tasks. This makes it easier to create agents that can handle real-world workflows without needing constant guidance. Let's explore how LangChain Deep Agents work and what you can build with them.
What are LangChain Deep Agents?
LangChain Deep Agents are an agent framework built on LangChain's core building blocks and the LangGraph runtime. They extend standard agent workflows with built-in capabilities such as filesystem access, subagent delegation, planning, memory, and human-in-the-loop support. Deep Agents use an agent loop that combines reasoning, tool calling, and iterative execution, making them suitable for complex tasks that require multiple steps, large amounts of context, and coordinated workflows.
Unlike basic agents that mainly call tools in a simple loop, Deep Agents provide additional infrastructure for handling long-running tasks. They can manage files, delegate work to specialized subagents, maintain context across complex workflows, and allow human intervention when necessary. These built-in capabilities reduce the amount of custom engineering required when building advanced agent systems.
How LangChain Deep Agents work
When a Deep Agent receives a task, it analyzes the request and plans the steps required to complete it. It then uses available tools, such as search, code execution, or filesystem operations, to gather information and perform actions.
During execution, Deep Agents manage context by reading and writing files. Instead of keeping all intermediate results inside the conversation history, they can store large amounts of information externally and retrieve it when needed. This approach helps agents handle longer workflows while reducing limitations caused by context window size.
For complex tasks that involve multiple areas of work, Deep Agents can delegate specific subtasks to specialized subagents. Each subagent focuses on a defined objective and returns relevant results to the main agent. The main agent then combines subagent outputs, retrieved information, and stored files to generate a complete and coherent response.
With features such as planning, tool use, filesystem management, subagent collaboration, and human oversight, LangChain Deep Agents provide a foundation for building more capable AI systems that can handle multi-step, real-world tasks.
Core capabilities of Deep Agents: Planning, tools, and execution
Deep Agents can handle tasks that require multiple steps, decisions, and actions. Their core features help them plan the work, use the right tools, and complete each step efficiently with less manual input. Let's look at these capabilities in detail:
Task planning
Task planning enables agents to create and manage a structured task list during execution. Instead of handling a complex goal as a single instruction, agents can divide it into smaller steps, track progress, and update task status throughout the workflow.
When to use planning
Long or complicated multi-step tasks
Tasks that benefit from explicit progress tracking and structured execution
UIs that stream progress from agent state
How to enable it
Pass TodoListMiddleware to the middleware parameter. This gives the agent a write_todos tool for maintaining a structured task list with status tracking (pending, in_progress, completed).
from deepagents import create_deep_agent
from deepagents.middleware import TodoListMiddleware
agent = create_deep_agent(
model="your-model",
middleware=[TodoListMiddleware()],
)Tasks are persisted in agent state, giving agents a lightweight planning layer for organizing long-running work.
Virtual filesystem tools
Deep Agents provide a configurable virtual filesystem backed by pluggable backends: in-memory state, local disk, LangGraph store, composite routing, or custom backends with permission rules.
Built-in filesystem tools
| Tool | Description |
|---|---|
ls | List files in a directory with metadata (size, modified time) |
read_file | Read file contents with line numbers; supports offset/limit for large files; also returns multimodal content blocks for images, video, audio, and documents |
write_file | Create a new file or overwrite an existing one |
edit_file | Perform exact string replacements in files (with global replace mode) |
delete | Delete a file or directory recursively |
glob | Find files matching patterns (e.g., **/*.py) |
grep | Search file contents with multiple output modes |
execute | Run shell commands in the environment (sandbox backends only) |
Supported multimodal extensions
Image:
.png,.jpg,.jpeg,.gif,.webp,.heic,.heifVideo:
.mp4,.mpeg,.mov,.avi,.flv,.mpg,.webm,.wmv,.3gppAudio:
.wav,.mp3,.aiff,.aac,.ogg,.flacDocument:
.pdf,.ppt,.pptx
Filesystem permissions
The harness supports declarative permission rules that control which files and directories the agent can read or write. Rules are evaluated top to bottom with first-match-wins semantics.
from deepagents import create_deep_agent
agent = create_deep_agent(
model="anthropic:your-model",
permissions=[
{"operations": ["read", "write"], "paths": ["/workspace/**"], "mode": "allow"},
{"operations": ["read"], "paths": [".env", "**/secrets/**"], "mode": "deny"},
],
)from deepagents import create_deep_agent
agent = create_deep_agent(
model="anthropic:your-model",
permissions=[
{"operations": ["read", "write"], "paths": ["/workspace/**"], "mode": "allow"},
{"operations": ["read"], "paths": [".env", "**/secrets/**"], "mode": "deny"},
],
)This lets you restrict agents to specific directories, protect sensitive files, and give subagents narrower access than the parent agent.
Restricting tool access
You can expose only a subset of filesystem tools by passing a tools allowlist to FilesystemMiddleware. read_file must always be included.
from deepagents import create_deep_agent
from deepagents.middleware import FilesystemMiddleware
# Read-only agent
agent = create_deep_agent(
model="your-model",
middleware=[
FilesystemMiddleware(backend=backend, tools=["read_file", "ls", "glob", "grep"]),
],
)from deepagents import create_deep_agent
from deepagents.middleware import FilesystemMiddleware
# Read-only agent
agent = create_deep_agent(
model="your-model",
middleware=[
FilesystemMiddleware(backend=backend, tools=["read_file", "ls", "glob", "grep"]),
],
)Subagents (Delegation)
The harness includes a built-in task tool that lets the main agent create ephemeral subagents for isolated, long-running, multi-step, or parallel tasks.
Key characteristics
Fresh context: Each invocation creates a new agent instance with its own context
Autonomous execution: The subagent runs independently until completion
Single handoff: It returns one final report to the main agent
Configurable strategy: Use the default
general-purposesubagent or define custom subagentsContext efficiency: Heavy subtask work stays isolated and is compressed into a compact result
Disabling subagents
To run an agent without the task tool, disable the auto-added subagent via the harness profile and pass no synchronous subagents via subagents=. Do not try removing SubAgentMiddleware via excluded_middleware—that is intentionally rejected.
Tool calling capabilities
Deep Agents support three categories of tools:
Custom functions & LangChain tools
Pass custom functions or LangChain tools directly via the tools= parameter:
MCP (Model Context Protocol)
Deep Agents fully support MCP, letting you connect to databases, APIs, file systems, and more through a standard interface.
Code execution
Sandbox backends: Expose an
executetool for shell commands in an isolated environmentInterpreters: Add an
evaltool that runs JavaScript in a scoped QuickJS runtime for lightweight programmable layers
As these capabilities come together, the language model powering the agent becomes an important part of the overall setup. A capable model can help Deep Agents understand instructions, reason through tasks, and make better use of the tools available to them. The Kimi API can provide this model layer, making it a natural next step for building more capable Deep Agent workflows.
Connect Kimi API to LangChain Deep Agents in 6 Steps
A capable model gives your Deep Agent the language understanding and reasoning needed to handle tasks effectively. Kimi API can provide these capabilities while the agent works with tools, manages tasks, and handles complex instructions. With the model layer in place, the setup can move naturally into connecting Kimi API with LangChain Agents. Here's how you can connect Kimi API to LangChain Deep Agents:
Step 1: Get your Kimi API Key
Sign in to the Kimi API platform and create a new API key. Copy and securely save the key, as you'll need to add it to your Deep Agents setup. This API key authenticates your requests and enables LangChain's Deep Agents to access Kimi models through the API.
Step 2: Set environmental variables
Set your Kimi API key as an environment variable. The Kimi API uses the Moonshot API endpoint, so configure the following variable:
export MOONSHOT_API_KEY="your-api-key-here"export MOONSHOT_API_KEY="your-api-key-here"The API base URL is:
https://api.moonshot.ai/v1https://api.moonshot.ai/v1Step 3: Install dependencies
Install Deep Agents and the required LangChain dependencies:
pip install deepagents langchain-openai
``````bash
pip install deepagents langchain-openaiSince the Kimi API is OpenAI-compatible, langchain-openai allows LangChain to connect to Kimi models through the OpenAI-compatible interface.
If you want to add web search capabilities to your Deep Agent, you can optionally install Tavily:
pip install tavily-pythonpip install tavily-pythonAfter creating a Tavily API key from the Tavily platform, set it as an environment variable:
export TAVILY_API_KEY="your-tavily-api-key"export TAVILY_API_KEY="your-tavily-api-key"You only need Tavily if you plan to add web search tools to your agent.
Step 4: Configure a Deep Agent with Kimi API
Since the Kimi API is compatible with the OpenAI API format, you can connect it to LangChain Deep Agents through init_chat_model.
The following example creates a basic Deep Agent powered by Kimi. You can optionally extend it with tools such as web search.
Basic Kimi-powered Deep Agent
Add web search capabilities (optional)
To enable web search, connect a search tool such as Tavily:
With this configuration, Deep Agents can use Kimi as the reasoning model while accessing external search capabilities through Tavily.
Step 5: Run your Kimi-powered Deep Agent
Once your Deep Agent is configured with Kimi, run the agent to test how it handles tasks and tool calls.
result = agent.invoke(
{"messages": [{"role": "user", "content": "What is LangGraph?"}]}
)
print(result["messages"][-1].content)result = agent.invoke(
{"messages": [{"role": "user", "content": "What is LangGraph?"}]}
)
print(result["messages"][-1].content)Step 6: Enable LangSmith tracing (optional)
LangSmith tracing helps you monitor agent execution, including tool calls, intermediate steps, and model responses.
Enable tracing with the following environment variables:
export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY="your-langsmith-api-key"export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY="your-langsmith-api-key"Use LangSmith when you need deeper visibility into agent workflows, debugging, or performance analysis.
Benefits of using Kimi API
Connecting Kimi API with Deep Agents can make complex workflows more capable and easier to manage. The combination gives agents stronger reasoning while allowing them to use tools, handle files, and work through multiple tasks. Let's look at the key benefits this setup can offer:
Improve agent reasoning and task execution
Kimi models provide strong language understanding and reasoning capabilities, helping Deep Agents analyze complex instructions, break down tasks, and generate more accurate responses. This allows agents to handle multi-step workflows more effectively with less manual guidance.
Build more capable AI workflows
With Kimi API connected to Deep Agents, developers can combine Kimi's model capabilities with tools, file systems, and external integrations supported by LangChain. This enables agents to perform tasks such as research, document processing, code analysis, and data handling within a unified workflow.
Scale complex tasks with autonomous agents
Kimi-powered Deep Agents can manage long-running tasks by creating plans, using tools, and delegating subtasks when needed. This makes it easier to build AI applications that can complete complex workflows while reducing repetitive manual operations.
Conclusion
Building reliable AI agents starts with choosing the right foundation for complex workflows. LangChain Deep Agents provide the tools and structure needed to create agents that can plan, use tools, manage context, and handle multi-step tasks with less manual effort. With the right model and configuration, developers can turn advanced agent ideas into practical applications. By integrating the Kimi API, you can further enhance your Deep Agent workflows with strong reasoning and long-context capabilities. Start exploring the Kimi API and discover what you can build with AI agents.