Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version-file: .nvmrc
cache: "yarn"
- name: Install dependencies
run: yarn install --immutable --mode=skip-build
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version-file: .nvmrc
cache: "yarn"
- name: Install dependencies
run: yarn install --immutable --mode=skip-build
Expand All @@ -63,7 +63,7 @@ jobs:
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version-file: .nvmrc
cache: "yarn"
- name: Install dependencies
run: yarn install --immutable --mode=skip-build
Expand All @@ -80,7 +80,7 @@ jobs:
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version-file: .nvmrc
cache: "yarn"
- name: Install dependencies
run: yarn install --immutable --mode=skip-build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [18.x, 20.x]
node-version: [22.x, 24.x]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Enable Corepack
run: corepack enable
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.x
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 🧠🤖Deep Agents
# 🧠🤖 Deep Agents

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.

Expand All @@ -10,7 +10,48 @@ Using an LLM to call tools in a loop is the simplest form of an agent. This arch
## Installation

```bash
yarn add deepagents
npm install deepagents
```

## Usage

You can find a full example for how to use this agent in [research-agent.ts](/examples/research/research-agent.ts):

```ts
const agent = createDeepAgent({
model: new ChatAnthropic({
model: "claude-3-5-sonnet-20240620",
temperature: 0,
}),
tools: [internetSearch],
instructions: researchInstructions,
subagents: [critiqueSubAgent, researchSubAgent],
});

// Invoke the agent
const result = await agent.invoke({
messages: [{ role: "user", content: "what is langgraph?" }],
}, { recursionLimit: 1000 });

console.log("🎉 Finished!")
console.log(`\n\nAgent ToDo List:\n${result.todos.map((todo) => ` - ${todo.content} (${todo.status})`).join("\n")}`);
console.log(`\n\nAgent Files:\n${Object.entries(result.files).map(([key, value]) => ` - ${key}: ${value}`).join("\n")}`);
```

Which will return:

```
🎉 Finished!

Agent ToDo List:
- Research LangGraph using the research-agent (completed)
- Write a comprehensive report on LangGraph (completed)
- Review and critique the report using the critique-agent (completed)
- Make necessary revisions to the report (completed)

Agent Files:
- /question.txt: What is LangGraph?
- /final_report.md: # What is LangGraph? ...
```

## Learn more
Expand Down
42 changes: 30 additions & 12 deletions examples/research/research-agent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* eslint-disable no-console */
import { createDeepAgent, type SubAgent } from "../../src/index.js";
import { tool } from "@langchain/core/tools";
import { z } from "zod";
import "dotenv/config";
import { z } from "zod";
import { tool, HumanMessage } from "langchain";
import { TavilySearch } from "@langchain/tavily";
import { ChatAnthropic } from "@langchain/anthropic";

import { createDeepAgent, type SubAgent } from "../../src/index.js";

type Topic = "general" | "news" | "finance";

Expand Down Expand Up @@ -32,7 +34,9 @@ const internetSearch = tool(
includeRawContent,
topic,
});
const tavilyResponse = await tavilySearch.invoke({ query });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Type instantiation is excessively deep and possibly infinite.
const tavilyResponse = await tavilySearch._call({ query });

return tavilyResponse;
},
Expand All @@ -57,7 +61,7 @@ const internetSearch = tool(
.default(false)
.describe("Whether to include raw content"),
}),
},
}
);

const subResearchPrompt = `You are a dedicated researcher. Your job is to conduct research based on the users questions.
Expand Down Expand Up @@ -195,21 +199,35 @@ Use this to run an internet search for a given query. You can specify the number

// Create the agent
const agent = createDeepAgent({
model: new ChatAnthropic({
model: "claude-sonnet-4-20250514",
temperature: 0,
}),
tools: [internetSearch],
instructions: researchInstructions,
subagents: [critiqueSubAgent, researchSubAgent],
}).withConfig({ recursionLimit: 1000 });
});

// Invoke the agent
async function main() {
const result = await agent.invoke({
messages: [{ role: "user", content: "what is langgraph?" }],
});
console.log(result);
const result = await agent.invoke(
{
messages: [new HumanMessage("what is langgraph?")],
},
{ recursionLimit: 1000 }
);

console.log("🎉 Finished!");
console.log(
`\n\nAgent ToDo List:\n${result.todos.map((todo) => ` - ${todo.content} (${todo.status})`).join("\n")}`
);
console.log(
`\n\nAgent Files:\n${Object.entries(result.files)
.map(([key, value]) => ` - ${key}: ${value}`)
.join("\n")}`
);
}

export { agent, internetSearch };

// Run if this file is executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
main();
Expand Down
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@
},
"homepage": "https://github.com/langchain-ai/deepagentsjs#readme",
"dependencies": {
"@langchain/anthropic": "^0.3.25",
"@langchain/core": "^0.3.66",
"@langchain/langgraph": "^0.4.6",
"zod": "^3.25.32"
"@langchain/anthropic": "alpha",
"@langchain/core": "alpha",
"@langchain/langgraph": "next",
"langchain": "alpha",
"zod": "^4.1.11"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.19.0",
"@langchain/tavily": "^0.1.4",
"@tsconfig/recommended": "^1.0.8",
"@tsconfig/recommended": "^1.0.10",
"@types/node": "^22.13.5",
"dotenv": "^17.2.1",
"eslint": "^9.19.0",
Expand All @@ -58,13 +59,10 @@
"eslint-plugin-prettier": "^4.2.1",
"globals": "^15.0.0",
"prettier": "^3.6.2",
"typescript": "^5",
"tsx": "^4.20.5",
"typescript": "^5.9.2",
"typescript-eslint": "^8.22.0"
},
"resolutions": {
"@langchain/langgraph": ">=0.2.53",
"@langchain/core": ">=0.3.0"
},
"files": [
"dist/**/*"
],
Expand Down
Loading
Loading