deepagents 0.0.2 β†’ 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # πŸ§ πŸ€–Deep Agents
1
+ # πŸ§ πŸ€– Deep Agents
2
2
 
3
3
  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.
4
4
 
@@ -10,7 +10,48 @@ Using an LLM to call tools in a loop is the simplest form of an agent. This arch
10
10
  ## Installation
11
11
 
12
12
  ```bash
13
- yarn add deepagents
13
+ npm install deepagents
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ You can find a full example for how to use this agent in [research-agent.ts](/examples/research/research-agent.ts):
19
+
20
+ ```ts
21
+ const agent = createDeepAgent({
22
+ model: new ChatAnthropic({
23
+ model: "claude-3-5-sonnet-20240620",
24
+ temperature: 0,
25
+ }),
26
+ tools: [internetSearch],
27
+ instructions: researchInstructions,
28
+ subagents: [critiqueSubAgent, researchSubAgent],
29
+ });
30
+
31
+ // Invoke the agent
32
+ const result = await agent.invoke({
33
+ messages: [{ role: "user", content: "what is langgraph?" }],
34
+ }, { recursionLimit: 1000 });
35
+
36
+ console.log("πŸŽ‰ Finished!")
37
+ console.log(`\n\nAgent ToDo List:\n${result.todos.map((todo) => ` - ${todo.content} (${todo.status})`).join("\n")}`);
38
+ console.log(`\n\nAgent Files:\n${Object.entries(result.files).map(([key, value]) => ` - ${key}: ${value}`).join("\n")}`);
39
+ ```
40
+
41
+ Which will return:
42
+
43
+ ```
44
+ πŸŽ‰ Finished!
45
+
46
+ Agent ToDo List:
47
+ - Research LangGraph using the research-agent (completed)
48
+ - Write a comprehensive report on LangGraph (completed)
49
+ - Review and critique the report using the critique-agent (completed)
50
+ - Make necessary revisions to the report (completed)
51
+
52
+ Agent Files:
53
+ - /question.txt: What is LangGraph?
54
+ - /final_report.md: # What is LangGraph? ...
14
55
  ```
15
56
 
16
57
  ## Learn more
package/dist/index.d.ts CHANGED
@@ -1,13 +1,195 @@
1
+ import * as langchain0 from "langchain";
2
+ import { AgentMiddleware, AgentMiddleware as AgentMiddleware$1, InterruptOnConfig, ReactAgent, StructuredTool } from "langchain";
3
+ import { AnnotationRoot } from "@langchain/langgraph";
4
+ import { z } from "zod/v3";
5
+ import * as _langchain_langgraph_zod0 from "@langchain/langgraph/zod";
6
+ import { StructuredTool as StructuredTool$1 } from "@langchain/core/tools";
7
+ import { LanguageModelLike } from "@langchain/core/language_models/base";
8
+ import { BaseCheckpointSaver, BaseStore } from "@langchain/langgraph-checkpoint";
9
+ import * as _langchain_core_utils_types0 from "@langchain/core/utils/types";
10
+ import { InteropZodObject } from "@langchain/core/utils/types";
11
+
12
+ //#region src/middleware/fs.d.ts
1
13
  /**
2
- * Deep Agents TypeScript Implementation
14
+ * Zod v3 schema for FileData
15
+ */
16
+ declare const FileDataSchema: z.ZodObject<{
17
+ content: z.ZodArray<z.ZodString, "many">;
18
+ created_at: z.ZodString;
19
+ modified_at: z.ZodString;
20
+ }, "strip", z.ZodTypeAny, {
21
+ content: string[];
22
+ created_at: string;
23
+ modified_at: string;
24
+ }, {
25
+ content: string[];
26
+ created_at: string;
27
+ modified_at: string;
28
+ }>;
29
+ type FileData = z.infer<typeof FileDataSchema>;
30
+ /**
31
+ * Options for creating filesystem middleware.
32
+ */
33
+ interface FilesystemMiddlewareOptions {
34
+ /** Whether to enable longterm memory support */
35
+ longTermMemory?: boolean;
36
+ /** Optional custom system prompt override */
37
+ systemPrompt?: string | null;
38
+ /** Optional custom tool descriptions override */
39
+ customToolDescriptions?: Record<string, string> | null;
40
+ /** Optional token limit before evicting a tool result to the filesystem (default: 20000 tokens, ~80KB) */
41
+ toolTokenLimitBeforeEvict?: number | null;
42
+ }
43
+ /**
44
+ * Create filesystem middleware with all tools and features.
45
+ */
46
+ declare function createFilesystemMiddleware(options?: FilesystemMiddlewareOptions): langchain0.AgentMiddleware<z.ZodObject<{
47
+ files: _langchain_langgraph_zod0.ReducedZodChannel<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
48
+ content: z.ZodArray<z.ZodString, "many">;
49
+ created_at: z.ZodString;
50
+ modified_at: z.ZodString;
51
+ }, "strip", z.ZodTypeAny, {
52
+ content: string[];
53
+ created_at: string;
54
+ modified_at: string;
55
+ }, {
56
+ content: string[];
57
+ created_at: string;
58
+ modified_at: string;
59
+ }>>>, _langchain_core_utils_types0.InteropZodType<Record<string, {
60
+ content: string[];
61
+ created_at: string;
62
+ modified_at: string;
63
+ } | null>>>;
64
+ }, "strip", z.ZodTypeAny, {
65
+ files: Record<string, {
66
+ content: string[];
67
+ created_at: string;
68
+ modified_at: string;
69
+ }>;
70
+ }, {
71
+ files?: Record<string, {
72
+ content: string[];
73
+ created_at: string;
74
+ modified_at: string;
75
+ }> | undefined;
76
+ }>, undefined, any>;
77
+ //#endregion
78
+ //#region src/middleware/subagents.d.ts
79
+ /**
80
+ * Type definitions for subagents
81
+ */
82
+ interface SubAgent {
83
+ /** The name of the agent */
84
+ name: string;
85
+ /** The description of the agent */
86
+ description: string;
87
+ /** The system prompt to use for the agent */
88
+ systemPrompt: string;
89
+ /** The tools to use for the agent (tool instances, not names). Defaults to defaultTools */
90
+ tools?: StructuredTool[];
91
+ /** The model for the agent. Defaults to default_model */
92
+ model?: LanguageModelLike | string;
93
+ /** Additional middleware to append after default_middleware */
94
+ middleware?: AgentMiddleware$1[];
95
+ /** The tool configs to use for the agent */
96
+ interruptOn?: Record<string, boolean | InterruptOnConfig>;
97
+ }
98
+ /**
99
+ * Options for creating subagent middleware
100
+ */
101
+ interface SubAgentMiddlewareOptions {
102
+ /** The model to use for subagents */
103
+ defaultModel: LanguageModelLike | string;
104
+ /** The tools to use for the default general-purpose subagent */
105
+ defaultTools?: StructuredTool[];
106
+ /** Default middleware to apply to all subagents */
107
+ defaultMiddleware?: AgentMiddleware$1[] | null;
108
+ /** The tool configs for the default general-purpose subagent */
109
+ defaultInterruptOn?: Record<string, boolean | InterruptOnConfig> | null;
110
+ /** A list of additional subagents to provide to the agent */
111
+ subagents?: Array<SubAgent>;
112
+ /** Full system prompt override */
113
+ systemPrompt?: string | null;
114
+ /** Whether to include the general-purpose agent */
115
+ generalPurposeAgent?: boolean;
116
+ /** Custom description for the task tool */
117
+ taskDescription?: string | null;
118
+ }
119
+ /**
120
+ * Create subagent middleware with task tool
121
+ */
122
+ declare function createSubAgentMiddleware(options: SubAgentMiddlewareOptions): AgentMiddleware$1;
123
+ //#endregion
124
+ //#region src/middleware/patch_tool_calls.d.ts
125
+ /**
126
+ * Create middleware that patches dangling tool calls in the messages history.
127
+ *
128
+ * When an AI message contains tool_calls but subsequent messages don't include
129
+ * the corresponding ToolMessage responses, this middleware adds synthetic
130
+ * ToolMessages saying the tool call was cancelled.
131
+ *
132
+ * @returns AgentMiddleware that patches dangling tool calls
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * import { createAgent } from "langchain";
137
+ * import { createPatchToolCallsMiddleware } from "./middleware/patch_tool_calls";
138
+ *
139
+ * const agent = createAgent({
140
+ * model: "claude-sonnet-4-5-20250929",
141
+ * middleware: [createPatchToolCallsMiddleware()],
142
+ * });
143
+ * ```
144
+ */
145
+ declare function createPatchToolCallsMiddleware(): AgentMiddleware;
146
+ //#endregion
147
+ //#region src/agent.d.ts
148
+ /**
149
+ * Configuration parameters for creating a Deep Agent
150
+ * Matches Python's create_deep_agent parameters
151
+ */
152
+ interface CreateDeepAgentParams<ContextSchema extends AnnotationRoot<any> | InteropZodObject = AnnotationRoot<any>> {
153
+ /** The model to use (model name string or LanguageModelLike instance). Defaults to claude-sonnet-4-5-20250929 */
154
+ model?: LanguageModelLike | string;
155
+ /** Tools the agent should have access to */
156
+ tools?: StructuredTool$1[];
157
+ /** Custom system prompt for the agent. This will be combined with the base agent prompt */
158
+ systemPrompt?: string;
159
+ /** Custom middleware to apply after standard middleware */
160
+ middleware?: AgentMiddleware[];
161
+ /** List of subagent specifications for task delegation */
162
+ subagents?: SubAgent[];
163
+ /** Structured output response format for the agent */
164
+ responseFormat?: any;
165
+ /** Optional schema for context (not persisted between invocations) */
166
+ contextSchema?: ContextSchema;
167
+ /** Optional checkpointer for persisting agent state between runs */
168
+ checkpointer?: BaseCheckpointSaver | boolean;
169
+ /** Optional store for persisting longterm memories */
170
+ store?: BaseStore;
171
+ /** Whether to use longterm memory - requires a store to be provided */
172
+ useLongtermMemory?: boolean;
173
+ /** Optional interrupt configuration mapping tool names to interrupt configs */
174
+ interruptOn?: Record<string, boolean | InterruptOnConfig>;
175
+ /** The name of the agent */
176
+ name?: string;
177
+ }
178
+ /**
179
+ * Create a Deep Agent with middleware-based architecture.
180
+ *
181
+ * Matches Python's create_deep_agent function, using middleware for all features:
182
+ * - Todo management (todoListMiddleware)
183
+ * - Filesystem tools (createFilesystemMiddleware)
184
+ * - Subagent delegation (createSubAgentMiddleware)
185
+ * - Conversation summarization (summarizationMiddleware)
186
+ * - Prompt caching (anthropicPromptCachingMiddleware)
187
+ * - Tool call patching (createPatchToolCallsMiddleware)
188
+ * - Human-in-the-loop (humanInTheLoopMiddleware) - optional
3
189
  *
4
- * A TypeScript port of the Python Deep Agents library for building controllable AI agents with LangGraph.
5
- * This implementation maintains 1:1 compatibility with the Python version.
190
+ * @param params Configuration parameters for the agent
191
+ * @returns ReactAgent instance ready for invocation
6
192
  */
7
- export { createDeepAgent } from "./graph.js";
8
- export { getDefaultModel } from "./model.js";
9
- export { createTaskTool } from "./subAgent.js";
10
- export { writeTodos, readFile, writeFile, editFile, ls } from "./tools.js";
11
- export { DeepAgentState, fileReducer } from "./state.js";
12
- export { WRITE_TODOS_DESCRIPTION, TASK_DESCRIPTION_PREFIX, TASK_DESCRIPTION_SUFFIX, EDIT_DESCRIPTION, TOOL_DESCRIPTION, } from "./prompts.js";
13
- export type { SubAgent, Todo, DeepAgentStateType, CreateDeepAgentParams, CreateTaskToolParams, TodoStatus, } from "./types.js";
193
+ declare function createDeepAgent<ContextSchema extends AnnotationRoot<any> | InteropZodObject = AnnotationRoot<any>>(params?: CreateDeepAgentParams<ContextSchema>): ReactAgent<any, any, ContextSchema, any>;
194
+ //#endregion
195
+ export { type CreateDeepAgentParams, type FileData, createFilesystemMiddleware as FilesystemMiddleware, createFilesystemMiddleware, type FilesystemMiddlewareOptions, type SubAgent, type SubAgentMiddlewareOptions, createDeepAgent, createPatchToolCallsMiddleware, createSubAgentMiddleware };