Skip to content

Commit 46b69ae

Browse files
Palashiolnhsingh
andauthored
feat: add deep agents to labs (#137)
This PR adds unified documentation in Langchain Labs for both Python & Typescript. --------- Co-authored-by: Lauren Hirata Singh <[email protected]>
1 parent 2ddc8ca commit 46b69ae

File tree

6 files changed

+299
-5
lines changed

6 files changed

+299
-5
lines changed

src/docs.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,25 @@
327327
"labs/index"
328328
]
329329
},
330+
{
331+
"tab": "Deep Agents",
332+
"pages": [
333+
{
334+
"group": "Get started",
335+
"pages": [
336+
"labs/deep-agents/overview",
337+
"labs/deep-agents/quickstart"
338+
]
339+
},
340+
{
341+
"group": "Configuration",
342+
"pages": [
343+
"labs/deep-agents/configuration-options",
344+
"labs/deep-agents/built-in-components"
345+
]
346+
}
347+
]
348+
},
330349
{
331350
"tab": "Open SWE",
332351
"pages": [
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: Built-in components
3+
---
4+
5+
Deep Agents comes with a number of built-in components that help agents perform complex tasks.
6+
7+
## System prompt
8+
9+
Deep Agents comes with a detailed system prompt heavily inspired by Claude Code's architecture. This prompt provides instructions for using the planning tool, file system tools, and sub agents effectively.
10+
11+
## Planning tool
12+
13+
A simple planning tool based on Claude Code's TodoWrite functionality that helps agents create and track plans in their context, keeping them on track for complex tasks.
14+
15+
## File system tools
16+
17+
Four built-in tools that mock a file system using LangGraph's state:
18+
19+
- `ls` - List files and directories
20+
- `read_file` - Read file contents
21+
- `write_file` - Write to files
22+
- `edit_file` - Edit existing files
23+
24+
Files can be passed in and retrieved via the files key:
25+
26+
<CodeGroup>
27+
28+
```python Python
29+
# Pass files to the agent
30+
result = agent.invoke({
31+
"messages": [...],
32+
"files": {"foo.txt": "file content", ...}
33+
})
34+
35+
# Access files after execution
36+
updated_files = result["files"]
37+
```
38+
39+
```typescript JavaScript
40+
const result = await agent.invoke({
41+
messages: [...],
42+
// Pass in files to the agent using this key
43+
files: {"foo.txt": "foo", ...}
44+
});
45+
46+
// Access any files afterwards like this
47+
result.files;
48+
```
49+
50+
</CodeGroup>
51+
52+
## Sub-agents
53+
54+
Built-in support for calling specialized sub-agents with the following:
55+
56+
- **Context quarantine**: Prevents polluting the main agent's context
57+
- **Custom instructions**: Tailored prompts for specific tasks
58+
- **Tool access control**: Subagents can have different tool sets
59+
60+
A general-purpose sub-agent with the same instructions and tools as the main agent is always available.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: Configuration options
3+
---
4+
5+
Deep Agents provides a number of configuration options to customize the agent's behavior and capabilities:
6+
7+
- **Tools** (required): The tools that the agent and any subagents will have access to.
8+
- **Instructions** (required): Custom instructions that serve as part of the agent's prompt. This supplements the built-in system prompt.
9+
- **Sub-agents**: Specialized subagents for specific tasks.
10+
- **Model**: The model to use for the agent.
11+
12+
## Tools
13+
14+
Required. A list of tools that the agent and any subagents will have access to.
15+
16+
## Instructions
17+
18+
Required. Custom instructions that serve as part of the agent's prompt. This supplements the built-in system prompt.
19+
20+
## Sub-agents
21+
22+
Define specialized subagents for specific tasks:
23+
24+
<CodeGroup>
25+
26+
```python Python
27+
subagents = [{
28+
"name": "research-agent",
29+
"description": "Used to research more in depth questions",
30+
"prompt": sub_research_prompt,
31+
"tools": ["internet_search"] # Optional: defaults to all tools
32+
}]
33+
34+
agent = create_deep_agent(
35+
tools=tools,
36+
instructions=prompt,
37+
subagents=subagents
38+
)
39+
```
40+
41+
```typescript JavaScript
42+
interface SubAgent {
43+
name: string;
44+
description: string;
45+
prompt: string;
46+
tools?: string[];
47+
}
48+
49+
const researchSubAgent: SubAgent = {
50+
name: "research-agent",
51+
description: "Used to research more in depth questions",
52+
prompt: subResearchPrompt,
53+
};
54+
55+
const agent = createDeepAgent({
56+
tools,
57+
instructions: prompt,
58+
subagents: [researchSubAgent]
59+
});
60+
```
61+
62+
</CodeGroup>
63+
64+
## Model
65+
66+
Both the Python and JavaScript implementations default to `"claude-sonnet-4-20250514"` but support custom models:
67+
68+
<CodeGroup>
69+
70+
```python Python
71+
from langchain_openai import ChatOpenAI
72+
73+
custom_model = ChatOpenAI(model="gpt-4")
74+
agent = create_deep_agent(
75+
tools=tools,
76+
instructions=instructions,
77+
model=custom_model
78+
)
79+
```
80+
81+
```typescript JavaScript
82+
import { ChatOpenAI } from "@langchain/openai";
83+
84+
const customModel = new ChatOpenAI({ model: "gpt-4" });
85+
const agent = createDeepAgent({
86+
tools,
87+
instructions,
88+
model: customModel
89+
});
90+
```
91+
92+
</CodeGroup>

src/labs/deep-agents/overview.mdx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Deep Agents
3+
sidebarTitle: Overview
4+
---
5+
6+
Using an LLM to call tools in a loop is the simplest form of an agent. This architecture, however, can yield agents that are "shallow" and fail to plan and act over longer, more complex tasks. Applications like "Deep Research", "Manus", and "Claude Code" have gotten around this limitation by implementing a combination of four things: a **planning tool**, **sub agents**, access to a **file system**, and a **detailed prompt**.
7+
8+
Deep Agents implements these components in a general purpose way so that you can easily create sophisticated agents for your application, available in both **Python** and **JavaScript/TypeScript**.
9+
10+
## Key features
11+
12+
- **Planning Tool**: Built-in planning capabilities to break down complex tasks and enable long-term planning.
13+
- **Persistent state**: Memory between tool calls beyond conversation history.
14+
- **Sub-agents**: Specialized agents for specific tasks with context quarantine.
15+
- **Virtual File System**: Mock file system for persistent state without conflicts.
16+
- **Detailed System Prompt**: Prompts, heavily inspired by Claude Code, leverage proven patterns.
17+
18+
Deep Agents implements the architectural patterns that make sophisticated agents like Claude Code effective.
19+
20+
## Installation
21+
22+
<CodeGroup>
23+
24+
```bash pip
25+
pip install deepagents
26+
```
27+
28+
```bash yarn
29+
yarn add deepagents
30+
```
31+
32+
```bash npm
33+
npm install deepagents
34+
```
35+
36+
</CodeGroup>
37+
38+
## Implementations
39+
40+
Deep Agents is available in both [**Python**](https://github.com/hwchase17/deepagents) and [**JavaScript**](https://www.npmjs.com/package/deepagents).
41+
42+
## Acknowledgements
43+
44+
This project was primarily inspired by Claude Code and is an attempt to better understand Claude Code and extend it.

src/labs/deep-agents/quickstart.mdx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: Quickstart
3+
---
4+
5+
To create a research agent that can conduct thorough investigations:
6+
7+
<CodeGroup>
8+
9+
```python Python
10+
from tavily import TavilyClient
11+
from deepagents import create_deep_agent
12+
import os
13+
14+
def internet_search(query):
15+
tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
16+
return tavily_client.search(query)
17+
18+
research_instructions = """You are an expert researcher.
19+
Your job is to conduct thorough research, and then write a polished report.
20+
21+
You have access to tools for internet search and file operations.
22+
"""
23+
24+
agent = create_deep_agent(
25+
tools=[internet_search],
26+
instructions=research_instructions
27+
)
28+
29+
result = agent.invoke({
30+
"messages": [{"role": "user", "content": "what is langgraph?"}]
31+
})
32+
```
33+
34+
```typescript JavaScript
35+
import { TavilySearch } from "@langchain/tavily";
36+
import { createDeepAgent } from "deepagents";
37+
38+
// Search tool to use to do research
39+
const internetSearch = new TavilySearch({
40+
maxResults: 5,
41+
tavilyApiKey: process.env.TAVILY_API_KEY,
42+
});
43+
44+
// Prompt prefix to steer the agent to be an expert researcher
45+
const researchInstructions = `You are an expert researcher. Your job is to conduct thorough research, and then write a polished report.
46+
47+
You have access to a few tools.
48+
49+
## \`internet_search\`
50+
51+
Use this to run an internet search for a given query. You can specify the number of results, the topic, and whether raw content should be included.
52+
`;
53+
54+
// Create the agent
55+
const agent = createDeepAgent({
56+
tools: [internetSearch],
57+
instructions: researchInstructions,
58+
});
59+
60+
// Invoke the agent
61+
const result = await agent.invoke({
62+
messages: [{ role: "user", content: "what is langgraph?" }]
63+
});
64+
```
65+
66+
</CodeGroup>
67+
68+
The agent created with `createDeepAgent` is a LangGraph graph, so you can interact with it (streaming, human-in-the-loop, memory, studio) the same way you would any LangGraph agent.

src/labs/index.mdx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ description: LangChain Labs is a collection of agents and experimental AI produc
88

99
<Columns cols={2}>
1010
<Card
11-
title="Open Agent Platform"
12-
icon="layer-group"
13-
href="https://docs.oap.langchain.com/"
11+
title="Deep Agents"
12+
icon="brain"
13+
href="/labs/deep-agents/overview"
1414
arrow="true"
1515
cta="Learn more"
1616
>
17-
Open Agent Platform is a citizen developer platform, allowing non-technical users to build, prototype, and use agents.
17+
Create sophisticated AI agents that can plan, use subagents, and work with files for complex tasks.
1818
</Card>
19-
19+
2020
<Card
2121
title="Open SWE"
2222
icon="code"
@@ -27,4 +27,15 @@ description: LangChain Labs is a collection of agents and experimental AI produc
2727
Open SWE is an open source cloud based coding agent.
2828
</Card>
2929

30+
<Card
31+
title="Open Agent Platform"
32+
icon="layer-group"
33+
href="https://docs.oap.langchain.com/"
34+
arrow="true"
35+
cta="Learn more"
36+
>
37+
Open Agent Platform is a citizen developer platform, allowing non-technical users to build, prototype, and use agents.
38+
</Card>
39+
40+
3041
</Columns>

0 commit comments

Comments
 (0)