-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add deep agents to labs #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
07b8e5b
feat: add deep agents to labs
Palashio a3aa951
Apply suggestions from code review
lnhsingh 71332ef
edits
lnhsingh b44d37a
Merge branch 'main' into palash/create-deep-agents-page
lnhsingh 1811ab6
reorg
lnhsingh fba2245
reorg
lnhsingh 2e42691
fixes
lnhsingh badefcf
fix link
lnhsingh d276149
Merge branch 'main' into palash/create-deep-agents-page
lnhsingh 9b99f58
Merge branch 'main' into palash/create-deep-agents-page
lnhsingh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
title: Built-in components | ||
--- | ||
|
||
Deep Agents comes with a number of built-in components that help agents perform complex tasks. | ||
|
||
## System prompt | ||
|
||
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. | ||
|
||
## Planning tool | ||
|
||
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. | ||
|
||
## File system tools | ||
|
||
Four built-in tools that mock a file system using LangGraph's state: | ||
|
||
- `ls` - List files and directories | ||
- `read_file` - Read file contents | ||
- `write_file` - Write to files | ||
- `edit_file` - Edit existing files | ||
|
||
Files can be passed in and retrieved via the files key: | ||
|
||
<CodeGroup> | ||
|
||
```python Python | ||
# Pass files to the agent | ||
result = agent.invoke({ | ||
"messages": [...], | ||
"files": {"foo.txt": "file content", ...} | ||
}) | ||
|
||
# Access files after execution | ||
updated_files = result["files"] | ||
``` | ||
|
||
```typescript JavaScript | ||
const result = await agent.invoke({ | ||
messages: [...], | ||
// Pass in files to the agent using this key | ||
files: {"foo.txt": "foo", ...} | ||
}); | ||
|
||
// Access any files afterwards like this | ||
result.files; | ||
``` | ||
|
||
</CodeGroup> | ||
|
||
## Sub-agents | ||
|
||
Built-in support for calling specialized sub-agents with the following: | ||
|
||
- **Context quarantine**: Prevents polluting the main agent's context | ||
- **Custom instructions**: Tailored prompts for specific tasks | ||
- **Tool access control**: Subagents can have different tool sets | ||
|
||
A general-purpose sub-agent with the same instructions and tools as the main agent is always available. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
--- | ||
title: Configuration options | ||
--- | ||
|
||
Deep Agents provides a number of configuration options to customize the agent's behavior and capabilities: | ||
|
||
- **Tools** (required): The tools that the agent and any subagents will have access to. | ||
- **Instructions** (required): Custom instructions that serve as part of the agent's prompt. This supplements the built-in system prompt. | ||
- **Sub-agents**: Specialized subagents for specific tasks. | ||
- **Model**: The model to use for the agent. | ||
|
||
## Tools | ||
|
||
Required. A list of tools that the agent and any subagents will have access to. | ||
|
||
## Instructions | ||
|
||
Required. Custom instructions that serve as part of the agent's prompt. This supplements the built-in system prompt. | ||
|
||
## Sub-agents | ||
|
||
Define specialized subagents for specific tasks: | ||
|
||
<CodeGroup> | ||
|
||
```python Python | ||
subagents = [{ | ||
"name": "research-agent", | ||
"description": "Used to research more in depth questions", | ||
"prompt": sub_research_prompt, | ||
"tools": ["internet_search"] # Optional: defaults to all tools | ||
}] | ||
|
||
agent = create_deep_agent( | ||
tools=tools, | ||
instructions=prompt, | ||
subagents=subagents | ||
) | ||
``` | ||
|
||
```typescript JavaScript | ||
interface SubAgent { | ||
name: string; | ||
description: string; | ||
prompt: string; | ||
tools?: string[]; | ||
} | ||
|
||
const researchSubAgent: SubAgent = { | ||
name: "research-agent", | ||
description: "Used to research more in depth questions", | ||
prompt: subResearchPrompt, | ||
}; | ||
|
||
const agent = createDeepAgent({ | ||
tools, | ||
instructions: prompt, | ||
subagents: [researchSubAgent] | ||
}); | ||
``` | ||
|
||
</CodeGroup> | ||
|
||
## Model | ||
|
||
Both the Python and JavaScript implementations default to `"claude-sonnet-4-20250514"` but support custom models: | ||
|
||
<CodeGroup> | ||
|
||
```python Python | ||
from langchain_openai import ChatOpenAI | ||
|
||
custom_model = ChatOpenAI(model="gpt-4") | ||
agent = create_deep_agent( | ||
tools=tools, | ||
instructions=instructions, | ||
model=custom_model | ||
) | ||
``` | ||
|
||
```typescript JavaScript | ||
import { ChatOpenAI } from "@langchain/openai"; | ||
|
||
const customModel = new ChatOpenAI({ model: "gpt-4" }); | ||
const agent = createDeepAgent({ | ||
tools, | ||
instructions, | ||
model: customModel | ||
}); | ||
``` | ||
|
||
</CodeGroup> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
title: Deep Agents | ||
sidebarTitle: Overview | ||
--- | ||
|
||
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**. | ||
|
||
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**. | ||
|
||
## Key features | ||
|
||
- **Planning Tool**: Built-in planning capabilities to break down complex tasks and enable long-term planning. | ||
- **Persistent state**: Memory between tool calls beyond conversation history. | ||
- **Sub-agents**: Specialized agents for specific tasks with context quarantine. | ||
- **Virtual File System**: Mock file system for persistent state without conflicts. | ||
- **Detailed System Prompt**: Prompts, heavily inspired by Claude Code, leverage proven patterns. | ||
|
||
Deep Agents implements the architectural patterns that make sophisticated agents like Claude Code effective. | ||
|
||
## Installation | ||
|
||
<CodeGroup> | ||
|
||
```bash pip | ||
pip install deepagents | ||
``` | ||
|
||
```bash yarn | ||
yarn add deepagents | ||
``` | ||
|
||
```bash npm | ||
npm install deepagents | ||
``` | ||
|
||
</CodeGroup> | ||
|
||
## Implementations | ||
|
||
Deep Agents is available in both [**Python**](https://github.com/hwchase17/deepagents) and [**JavaScript**](https://www.npmjs.com/package/deepagents). | ||
|
||
## Acknowledgements | ||
|
||
This project was primarily inspired by Claude Code and is an attempt to better understand Claude Code and extend it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
title: Quickstart | ||
--- | ||
|
||
To create a research agent that can conduct thorough investigations: | ||
|
||
<CodeGroup> | ||
|
||
```python Python | ||
from tavily import TavilyClient | ||
from deepagents import create_deep_agent | ||
import os | ||
|
||
def internet_search(query): | ||
tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"]) | ||
return tavily_client.search(query) | ||
|
||
research_instructions = """You are an expert researcher. | ||
Your job is to conduct thorough research, and then write a polished report. | ||
|
||
You have access to tools for internet search and file operations. | ||
""" | ||
|
||
agent = create_deep_agent( | ||
tools=[internet_search], | ||
instructions=research_instructions | ||
) | ||
|
||
result = agent.invoke({ | ||
"messages": [{"role": "user", "content": "what is langgraph?"}] | ||
}) | ||
``` | ||
|
||
```typescript JavaScript | ||
import { TavilySearch } from "@langchain/tavily"; | ||
import { createDeepAgent } from "deepagents"; | ||
|
||
// Search tool to use to do research | ||
const internetSearch = new TavilySearch({ | ||
maxResults: 5, | ||
tavilyApiKey: process.env.TAVILY_API_KEY, | ||
}); | ||
|
||
// Prompt prefix to steer the agent to be an expert researcher | ||
const researchInstructions = `You are an expert researcher. Your job is to conduct thorough research, and then write a polished report. | ||
|
||
You have access to a few tools. | ||
|
||
## \`internet_search\` | ||
|
||
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. | ||
`; | ||
|
||
// Create the agent | ||
const agent = createDeepAgent({ | ||
tools: [internetSearch], | ||
instructions: researchInstructions, | ||
}); | ||
|
||
// Invoke the agent | ||
const result = await agent.invoke({ | ||
messages: [{ role: "user", content: "what is langgraph?" }] | ||
}); | ||
``` | ||
|
||
</CodeGroup> | ||
|
||
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.