Deep Agents package.
Specification for an async subagent running on a remote LangGraph server.
Async subagents connect to LangGraph deployments via the LangGraph SDK. They run as background tasks that the main agent can monitor and update.
Authentication is handled via environment variables (LANGGRAPH_API_KEY,
LANGSMITH_API_KEY, or LANGCHAIN_API_KEY), which the LangGraph SDK
reads automatically.
Middleware for async subagents running on remote LangGraph servers.
This middleware adds tools for launching, monitoring, and updating
background tasks on remote LangGraph deployments. Unlike the synchronous
SubAgentMiddleware, async subagents return immediately with a task ID,
allowing the main agent to continue working while subagents execute.
Task IDs are persisted in the agent state under async_tasks so they
survive context compaction/offloading and can be accessed programmatically.
Middleware for providing filesystem and optional execution tools to an agent.
This middleware adds filesystem tools to the agent: ls, read_file, write_file,
edit_file, glob, and grep.
Files can be stored using any backend that implements the BackendProtocol.
If the backend implements SandboxBackendProtocol, an execute tool is also added
for running shell commands.
This middleware also automatically evicts large tool results to the file system when they exceed a token threshold, preventing context window saturation.
Middleware for loading agent memory from AGENTS.md files.
Loads memory content from configured sources and injects into the system prompt.
Supports multiple sources that are combined together.
A pre-compiled agent spec.
The runnable's state schema must include a 'messages' key.
This is required for the subagent to communicate results back to the main agent.
When the subagent completes, the final message in the 'messages' list will be
extracted and returned as a ToolMessage to the parent agent.
Specification for an agent.
When using create_deep_agent, subagents automatically receive a default middleware
stack (TodoListMiddleware, FilesystemMiddleware, SummarizationMiddleware, etc.) before
any custom middleware specified in this spec.
Middleware for providing subagents to an agent via a task tool.
This middleware adds a task tool to the agent that can be used to invoke subagents.
Subagents are useful for handling complex tasks that require multiple steps, or tasks
that require a lot of context to resolve.
A chief benefit of subagents is that they can handle multi-step tasks, and then return a clean, concise response to the main agent.
Subagents are also great for different domains of expertise that require a narrower subset of tools and focus.
Deep Agents come with planning, filesystem, and subagents.
Memory backends for pluggable file storage.
Middleware for the Deep Agents agent.
The LLM receives tools through two paths:
tools parameter to create_deep_agent(). The CLI uses this path for
lightweight, consumer-specific tools.Both are merged by create_deep_agent() into the final tool set the LLM sees.
Middleware subclasses AgentMiddleware, overriding its wrap_model_call()
hook that intercepts every LLM request before it is sent. This lets
middleware:
FilesystemMiddleware removes the
execute tool at call-time when the resolved backend doesn't support it.MemoryMiddleware and
SkillsMiddleware inject relevant instructions into the system message on
every call so the LLM knows how to use the tools they provide.SummarizationMiddleware counts tokens,
truncates old tool arguments, and replaces history with summaries when the
context window fills up.A plain tool function in a tools=[] list cannot do any of this -- it is
only invoked by the LLM, not before the LLM call.
Use middleware when the tool needs to:
Use a plain tool when: