realtimex-deepagents 0.3.0.post4__tar.gz

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.
Files changed (30) hide show
  1. realtimex_deepagents-0.3.0.post4/PKG-INFO +513 -0
  2. realtimex_deepagents-0.3.0.post4/README.md +495 -0
  3. realtimex_deepagents-0.3.0.post4/deepagents/__init__.py +8 -0
  4. realtimex_deepagents-0.3.0.post4/deepagents/backends/__init__.py +15 -0
  5. realtimex_deepagents-0.3.0.post4/deepagents/backends/composite.py +564 -0
  6. realtimex_deepagents-0.3.0.post4/deepagents/backends/filesystem.py +556 -0
  7. realtimex_deepagents-0.3.0.post4/deepagents/backends/protocol.py +458 -0
  8. realtimex_deepagents-0.3.0.post4/deepagents/backends/sandbox.py +360 -0
  9. realtimex_deepagents-0.3.0.post4/deepagents/backends/state.py +187 -0
  10. realtimex_deepagents-0.3.0.post4/deepagents/backends/store.py +442 -0
  11. realtimex_deepagents-0.3.0.post4/deepagents/backends/utils.py +436 -0
  12. realtimex_deepagents-0.3.0.post4/deepagents/graph.py +161 -0
  13. realtimex_deepagents-0.3.0.post4/deepagents/middleware/__init__.py +11 -0
  14. realtimex_deepagents-0.3.0.post4/deepagents/middleware/filesystem.py +1088 -0
  15. realtimex_deepagents-0.3.0.post4/deepagents/middleware/patch_tool_calls.py +44 -0
  16. realtimex_deepagents-0.3.0.post4/deepagents/middleware/shell.py +233 -0
  17. realtimex_deepagents-0.3.0.post4/deepagents/middleware/subagents.py +494 -0
  18. realtimex_deepagents-0.3.0.post4/deepagents/realtimex_graph.py +255 -0
  19. realtimex_deepagents-0.3.0.post4/deepagents/realtimex_middleware/__init__.py +7 -0
  20. realtimex_deepagents-0.3.0.post4/deepagents/realtimex_middleware/agent_memory.py +265 -0
  21. realtimex_deepagents-0.3.0.post4/deepagents/realtimex_middleware/skills/__init__.py +6 -0
  22. realtimex_deepagents-0.3.0.post4/deepagents/realtimex_middleware/skills/load.py +216 -0
  23. realtimex_deepagents-0.3.0.post4/deepagents/realtimex_middleware/skills/middleware.py +344 -0
  24. realtimex_deepagents-0.3.0.post4/pyproject.toml +99 -0
  25. realtimex_deepagents-0.3.0.post4/realtimex_deepagents.egg-info/PKG-INFO +513 -0
  26. realtimex_deepagents-0.3.0.post4/realtimex_deepagents.egg-info/SOURCES.txt +28 -0
  27. realtimex_deepagents-0.3.0.post4/realtimex_deepagents.egg-info/dependency_links.txt +1 -0
  28. realtimex_deepagents-0.3.0.post4/realtimex_deepagents.egg-info/requires.txt +4 -0
  29. realtimex_deepagents-0.3.0.post4/realtimex_deepagents.egg-info/top_level.txt +1 -0
  30. realtimex_deepagents-0.3.0.post4/setup.cfg +4 -0
@@ -0,0 +1,513 @@
1
+ Metadata-Version: 2.4
2
+ Name: realtimex-deepagents
3
+ Version: 0.3.0.post4
4
+ Summary: General purpose 'deep agent' with sub-agent spawning, todo list capabilities, and mock file system. Built on LangGraph.
5
+ License: MIT
6
+ Project-URL: Homepage, https://docs.langchain.com/oss/python/deepagents/overview
7
+ Project-URL: Documentation, https://reference.langchain.com/python/deepagents/
8
+ Project-URL: Source, https://github.com/langchain-ai/deepagents
9
+ Project-URL: Twitter, https://x.com/LangChainAI
10
+ Project-URL: Slack, https://www.langchain.com/join-community
11
+ Project-URL: Reddit, https://www.reddit.com/r/LangChain/
12
+ Requires-Python: <4.0,>=3.11
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: langchain-anthropic<2.0.0,>=1.2.0
15
+ Requires-Dist: langchain<2.0.0,>=1.1.0
16
+ Requires-Dist: langchain-core<2.0.0,>=1.1.0
17
+ Requires-Dist: wcmatch
18
+
19
+ # 🧠🤖Deep Agents
20
+
21
+ Using an LLM to call tools in a loop is the simplest form of an agent.
22
+ This architecture, however, can yield agents that are “shallow” and fail to plan and act over longer, more complex tasks.
23
+
24
+ Applications like “Deep Research”, "Manus", and “Claude Code” have gotten around this limitation by implementing a combination of four things:
25
+ a **planning tool**, **sub agents**, access to a **file system**, and a **detailed prompt**.
26
+
27
+ <img src="../../deep_agents.png" alt="deep agent" width="600"/>
28
+
29
+ `deepagents` is a Python package that implements these in a general purpose way so that you can easily create a Deep Agent for your application. For a full overview and quickstart of `deepagents`, the best resource is our [docs](https://docs.langchain.com/oss/python/deepagents/overview).
30
+
31
+ **Acknowledgements: This project was primarily inspired by Claude Code, and initially was largely an attempt to see what made Claude Code general purpose, and make it even more so.**
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ # pip
37
+ pip install deepagents
38
+
39
+ # uv
40
+ uv add deepagents
41
+
42
+ # poetry
43
+ poetry add deepagents
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ (To run the example below, you will need to `pip install tavily-python`).
49
+
50
+ Make sure to set `TAVILY_API_KEY` in your environment. You can generate one [here](https://www.tavily.com/).
51
+
52
+ ```python
53
+ import os
54
+ from typing import Literal
55
+ from tavily import TavilyClient
56
+ from deepagents import create_deep_agent
57
+
58
+ tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
59
+
60
+ # Web search tool
61
+ def internet_search(
62
+ query: str,
63
+ max_results: int = 5,
64
+ topic: Literal["general", "news", "finance"] = "general",
65
+ include_raw_content: bool = False,
66
+ ):
67
+ """Run a web search"""
68
+ return tavily_client.search(
69
+ query,
70
+ max_results=max_results,
71
+ include_raw_content=include_raw_content,
72
+ topic=topic,
73
+ )
74
+
75
+
76
+ # System prompt to steer the agent to be an expert researcher
77
+ research_instructions = """You are an expert researcher. Your job is to conduct thorough research, and then write a polished report.
78
+
79
+ You have access to an internet search tool as your primary means of gathering information.
80
+
81
+ ## `internet_search`
82
+
83
+ Use this to run an internet search for a given query. You can specify the max number of results to return, the topic, and whether raw content should be included.
84
+ """
85
+
86
+ # Create the deep agent
87
+ agent = create_deep_agent(
88
+ tools=[internet_search],
89
+ system_prompt=research_instructions,
90
+ )
91
+
92
+ # Invoke the agent
93
+ result = agent.invoke({"messages": [{"role": "user", "content": "What is langgraph?"}]})
94
+ ```
95
+
96
+ See [examples/research/research_agent.py](examples/research/research_agent.py) for a more complex example.
97
+
98
+ The agent created with `create_deep_agent` is just a LangGraph graph - so you can interact with it (streaming, human-in-the-loop, memory, studio)
99
+ in the same way you would any LangGraph agent.
100
+
101
+ ## Core Capabilities
102
+ **Planning & Task Decomposition**
103
+
104
+ Deep Agents include a built-in `write_todos` tool that enables agents to break down complex tasks into discrete steps, track progress, and adapt plans as new information emerges.
105
+
106
+ **Context Management**
107
+
108
+ File system tools (`ls`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`) allow agents to offload large context to memory, preventing context window overflow and enabling work with variable-length tool results.
109
+
110
+ **Subagent Spawning**
111
+
112
+ A built-in `task` tool enables agents to spawn specialized subagents for context isolation. This keeps the main agent’s context clean while still going deep on specific subtasks.
113
+
114
+ **Long-term Memory**
115
+
116
+ Extend agents with persistent memory across threads using LangGraph’s Store. Agents can save and retrieve information from previous conversations.
117
+
118
+ ## Customizing Deep Agents
119
+
120
+ There are several parameters you can pass to `create_deep_agent` to create your own custom deep agent.
121
+
122
+ ### `model`
123
+
124
+ By default, `deepagents` uses `"claude-sonnet-4-5-20250929"`. You can customize this by passing any [LangChain model object](https://python.langchain.com/docs/integrations/chat/).
125
+
126
+ ```python
127
+ from langchain.chat_models import init_chat_model
128
+ from deepagents import create_deep_agent
129
+
130
+ model = init_chat_model("openai:gpt-4o")
131
+ agent = create_deep_agent(
132
+ model=model,
133
+ )
134
+ ```
135
+
136
+ ### `system_prompt`
137
+ Deep Agents come with a built-in system prompt. This is relatively detailed prompt that is heavily based on and inspired by [attempts](https://github.com/kn1026/cc/blob/main/claudecode.md) to [replicate](https://github.com/asgeirtj/system_prompts_leaks/blob/main/Anthropic/claude-code.md)
138
+ Claude Code's system prompt. It was made more general purpose than Claude Code's system prompt. The default prompt contains detailed instructions for how to use the built-in planning tool, file system tools, and sub agents.
139
+
140
+ Each deep agent tailored to a use case should include a custom system prompt specific to that use case as well. The importance of prompting for creating a successful deep agent cannot be overstated.
141
+
142
+ ```python
143
+ from deepagents import create_deep_agent
144
+
145
+ research_instructions = """You are an expert researcher. Your job is to conduct thorough research, and then write a polished report.
146
+ """
147
+
148
+ agent = create_deep_agent(
149
+ system_prompt=research_instructions,
150
+ )
151
+ ```
152
+
153
+ ### `tools`
154
+
155
+ Just like with tool-calling agents, you can provide a deep agent with a set of tools that it has access to.
156
+
157
+ ```python
158
+ import os
159
+ from typing import Literal
160
+ from tavily import TavilyClient
161
+ from deepagents import create_deep_agent
162
+
163
+ tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
164
+
165
+ def internet_search(
166
+ query: str,
167
+ max_results: int = 5,
168
+ topic: Literal["general", "news", "finance"] = "general",
169
+ include_raw_content: bool = False,
170
+ ):
171
+ """Run a web search"""
172
+ return tavily_client.search(
173
+ query,
174
+ max_results=max_results,
175
+ include_raw_content=include_raw_content,
176
+ topic=topic,
177
+ )
178
+
179
+ agent = create_deep_agent(
180
+ tools=[internet_search]
181
+ )
182
+ ```
183
+
184
+ ### `middleware`
185
+ `create_deep_agent` is implemented with middleware that can be customized. You can provide additional middleware to extend functionality, add tools, or implement custom hooks.
186
+
187
+ ```python
188
+ from langchain_core.tools import tool
189
+ from deepagents import create_deep_agent
190
+ from langchain.agents.middleware import AgentMiddleware
191
+
192
+ @tool
193
+ def get_weather(city: str) -> str:
194
+ """Get the weather in a city."""
195
+ return f"The weather in {city} is sunny."
196
+
197
+ @tool
198
+ def get_temperature(city: str) -> str:
199
+ """Get the temperature in a city."""
200
+ return f"The temperature in {city} is 70 degrees Fahrenheit."
201
+
202
+ class WeatherMiddleware(AgentMiddleware):
203
+ tools = [get_weather, get_temperature]
204
+
205
+ agent = create_deep_agent(
206
+ model="anthropic:claude-sonnet-4-20250514",
207
+ middleware=[WeatherMiddleware()]
208
+ )
209
+ ```
210
+
211
+ ### `subagents`
212
+
213
+ A main feature of Deep Agents is their ability to spawn subagents. You can specify custom subagents that your agent can hand off work to in the subagents parameter. Sub agents are useful for context quarantine (to help not pollute the overall context of the main agent) as well as custom instructions.
214
+
215
+ `subagents` should be a list of dictionaries, where each dictionary follow this schema:
216
+
217
+ ```python
218
+ class SubAgent(TypedDict):
219
+ name: str
220
+ description: str
221
+ prompt: str
222
+ tools: Sequence[BaseTool | Callable | dict[str, Any]]
223
+ model: NotRequired[str | BaseChatModel]
224
+ middleware: NotRequired[list[AgentMiddleware]]
225
+ interrupt_on: NotRequired[dict[str, bool | InterruptOnConfig]]
226
+
227
+ class CompiledSubAgent(TypedDict):
228
+ name: str
229
+ description: str
230
+ runnable: Runnable
231
+ ```
232
+
233
+ **SubAgent fields:**
234
+ - **name**: This is the name of the subagent, and how the main agent will call the subagent
235
+ - **description**: This is the description of the subagent that is shown to the main agent
236
+ - **prompt**: This is the prompt used for the subagent
237
+ - **tools**: This is the list of tools that the subagent has access to.
238
+ - **model**: Optional model name or model instance.
239
+ - **middleware** Additional middleware to attach to the subagent. See [here](https://docs.langchain.com/oss/python/langchain/middleware) for an introduction into middleware and how it works with create_agent.
240
+ - **interrupt_on** A custom interrupt config that specifies human-in-the-loop interactions for your tools.
241
+
242
+ **CompiledSubAgent fields:**
243
+ - **name**: This is the name of the subagent, and how the main agent will call the subagent
244
+ - **description**: This is the description of the subagent that is shown to the main agent
245
+ - **runnable**: A pre-built LangGraph graph/agent that will be used as the subagent
246
+
247
+ #### Using SubAgent
248
+
249
+ ```python
250
+ import os
251
+ from typing import Literal
252
+ from tavily import TavilyClient
253
+ from deepagents import create_deep_agent
254
+
255
+ tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
256
+
257
+ def internet_search(
258
+ query: str,
259
+ max_results: int = 5,
260
+ topic: Literal["general", "news", "finance"] = "general",
261
+ include_raw_content: bool = False,
262
+ ):
263
+ """Run a web search"""
264
+ return tavily_client.search(
265
+ query,
266
+ max_results=max_results,
267
+ include_raw_content=include_raw_content,
268
+ topic=topic,
269
+ )
270
+
271
+ research_subagent = {
272
+ "name": "research-agent",
273
+ "description": "Used to research more in depth questions",
274
+ "system_prompt": "You are a great researcher",
275
+ "tools": [internet_search],
276
+ "model": "openai:gpt-4o", # Optional override, defaults to main agent model
277
+ }
278
+ subagents = [research_subagent]
279
+
280
+ agent = create_deep_agent(
281
+ model="anthropic:claude-sonnet-4-20250514",
282
+ subagents=subagents
283
+ )
284
+ ```
285
+
286
+ #### Using CustomSubAgent
287
+
288
+ For more complex use cases, you can provide your own pre-built LangGraph graph as a subagent:
289
+
290
+ ```python
291
+ # Create a custom agent graph
292
+ custom_graph = create_agent(
293
+ model=your_model,
294
+ tools=specialized_tools,
295
+ prompt="You are a specialized agent for data analysis..."
296
+ )
297
+
298
+ # Use it as a custom subagent
299
+ custom_subagent = CompiledSubAgent(
300
+ name="data-analyzer",
301
+ description="Specialized agent for complex data analysis tasks",
302
+ runnable=custom_graph
303
+ )
304
+
305
+ subagents = [custom_subagent]
306
+
307
+ agent = create_deep_agent(
308
+ model="anthropic:claude-sonnet-4-20250514",
309
+ tools=[internet_search],
310
+ system_prompt=research_instructions,
311
+ subagents=subagents
312
+ )
313
+ ```
314
+
315
+ ### `interrupt_on`
316
+ A common reality for agents is that some tool operations may be sensitive and require human approval before execution. Deep Agents supports human-in-the-loop workflows through LangGraph’s interrupt capabilities. You can configure which tools require approval using a checkpointer.
317
+
318
+ These tool configs are passed to our prebuilt [HITL middleware](https://docs.langchain.com/oss/python/langchain/middleware#human-in-the-loop) so that the agent pauses execution and waits for feedback from the user before executing configured tools.
319
+
320
+ ```python
321
+ from langchain_core.tools import tool
322
+ from deepagents import create_deep_agent
323
+
324
+ @tool
325
+ def get_weather(city: str) -> str:
326
+ """Get the weather in a city."""
327
+ return f"The weather in {city} is sunny."
328
+
329
+ agent = create_deep_agent(
330
+ model="anthropic:claude-sonnet-4-20250514",
331
+ tools=[get_weather],
332
+ interrupt_on={
333
+ "get_weather": {
334
+ "allowed_decisions": ["approve", "edit", "reject"]
335
+ },
336
+ }
337
+ )
338
+
339
+ ```
340
+
341
+ ## Deep Agents Middleware
342
+
343
+ Deep Agents are built with a modular middleware architecture. As a reminder, Deep Agents have access to:
344
+ - A planning tool
345
+ - A filesystem for storing context and long-term memories
346
+ - The ability to spawn subagents
347
+
348
+ Each of these features is implemented as separate middleware. When you create a deep agent with `create_deep_agent`, we automatically attach **TodoListMiddleware**, **FilesystemMiddleware** and **SubAgentMiddleware** to your agent.
349
+
350
+ Middleware is a composable concept, and you can choose to add as many or as few middleware to an agent depending on your use case. That means that you can also use any of the aforementioned middleware independently!
351
+
352
+ ### TodoListMiddleware
353
+
354
+ Planning is integral to solving complex problems. If you’ve used claude code recently, you’ll notice how it writes out a To-Do list before tackling complex, multi-part tasks. You’ll also notice how it can adapt and update this To-Do list on the fly as more information comes in.
355
+
356
+ **TodoListMiddleware** provides your agent with a tool specifically for updating this To-Do list. Before, and while it executes a multi-part task, the agent is prompted to use the write_todos tool to keep track of what its doing, and what still needs to be done.
357
+
358
+ ```python
359
+ from langchain.agents import create_agent
360
+ from langchain.agents.middleware import TodoListMiddleware
361
+
362
+ # TodoListMiddleware is included by default in create_deep_agent
363
+ # You can customize it if building a custom agent
364
+ agent = create_agent(
365
+ model="anthropic:claude-sonnet-4-20250514",
366
+ # Custom planning instructions can be added via middleware
367
+ middleware=[
368
+ TodoListMiddleware(
369
+ system_prompt="Use the write_todos tool to..." # Optional: Custom addition to the system prompt
370
+ ),
371
+ ],
372
+ )
373
+ ```
374
+
375
+ ### FilesystemMiddleware
376
+
377
+ Context engineering is one of the main challenges in building effective agents. This can be particularly hard when using tools that can return variable length results (ex. web_search, rag), as long ToolResults can quickly fill up your context window.
378
+ **FilesystemMiddleware** provides four tools to your agent to interact with both short-term and long-term memory.
379
+ - **ls**: List the files in your filesystem
380
+ - **read_file**: Read an entire file, or a certain number of lines from a file
381
+ - **write_file**: Write a new file to your filesystem
382
+ - **edit_file**: Edit an existing file in your filesystem
383
+
384
+ ```python
385
+ from langchain.agents import create_agent
386
+ from deepagents.middleware.filesystem import FilesystemMiddleware
387
+
388
+
389
+ # FilesystemMiddleware is included by default in create_deep_agent
390
+ # You can customize it if building a custom agent
391
+ agent = create_agent(
392
+ model="anthropic:claude-sonnet-4-20250514",
393
+ middleware=[
394
+ FilesystemMiddleware(
395
+ backend=..., # Optional: customize storage backend
396
+ system_prompt="Write to the filesystem when...", # Optional custom system prompt override
397
+ custom_tool_descriptions={
398
+ "ls": "Use the ls tool when...",
399
+ "read_file": "Use the read_file tool to..."
400
+ } # Optional: Custom descriptions for filesystem tools
401
+ ),
402
+ ],
403
+ )
404
+ ```
405
+
406
+ ### SubAgentMiddleware
407
+
408
+ Handing off tasks to subagents is a great way to isolate context, keeping the context window of the main (supervisor) agent clean while still going deep on a task. The subagents middleware allows you supply subagents through a task tool.
409
+
410
+ A subagent is defined with a name, description, system prompt, and tools. You can also provide a subagent with a custom model, or with additional middleware. This can be particularly useful when you want to give the subagent an additional state key to share with the main agent.
411
+
412
+ ```python
413
+ from langchain_core.tools import tool
414
+ from langchain.agents import create_agent
415
+ from deepagents.middleware.subagents import SubAgentMiddleware
416
+
417
+
418
+ @tool
419
+ def get_weather(city: str) -> str:
420
+ """Get the weather in a city."""
421
+ return f"The weather in {city} is sunny."
422
+
423
+ agent = create_agent(
424
+ model="claude-sonnet-4-20250514",
425
+ middleware=[
426
+ SubAgentMiddleware(
427
+ default_model="claude-sonnet-4-20250514",
428
+ default_tools=[],
429
+ subagents=[
430
+ {
431
+ "name": "weather",
432
+ "description": "This subagent can get weather in cities.",
433
+ "system_prompt": "Use the get_weather tool to get the weather in a city.",
434
+ "tools": [get_weather],
435
+ "model": "gpt-4.1",
436
+ "middleware": [],
437
+ }
438
+ ],
439
+ )
440
+ ],
441
+ )
442
+ ```
443
+
444
+ For more complex use cases, you can also provide your own pre-built LangGraph graph as a subagent.
445
+
446
+ ```python
447
+ # Create a custom LangGraph graph
448
+ def create_weather_graph():
449
+ workflow = StateGraph(...)
450
+ # Build your custom graph
451
+ return workflow.compile()
452
+
453
+ weather_graph = create_weather_graph()
454
+
455
+ # Wrap it in a CompiledSubAgent
456
+ weather_subagent = CompiledSubAgent(
457
+ name="weather",
458
+ description="This subagent can get weather in cities.",
459
+ runnable=weather_graph
460
+ )
461
+
462
+ agent = create_agent(
463
+ model="anthropic:claude-sonnet-4-20250514",
464
+ middleware=[
465
+ SubAgentMiddleware(
466
+ default_model="claude-sonnet-4-20250514",
467
+ default_tools=[],
468
+ subagents=[weather_subagent],
469
+ )
470
+ ],
471
+ )
472
+ ```
473
+
474
+ ## Sync vs Async
475
+
476
+ Prior versions of deepagents separated sync and async agent factories.
477
+
478
+ `async_create_deep_agent` has been folded in to `create_deep_agent`.
479
+
480
+ **You should use `create_deep_agent` as the factory for both sync and async agents**
481
+
482
+
483
+ ## MCP
484
+
485
+ The `deepagents` library can be ran with MCP tools. This can be achieved by using the [Langchain MCP Adapter library](https://github.com/langchain-ai/langchain-mcp-adapters).
486
+
487
+ **NOTE:** You will want to use `from deepagents import async_create_deep_agent` to use the async version of `deepagents`, since MCP tools are async
488
+
489
+ (To run the example below, will need to `pip install langchain-mcp-adapters`)
490
+
491
+ ```python
492
+ import asyncio
493
+ from langchain_mcp_adapters.client import MultiServerMCPClient
494
+ from deepagents import create_deep_agent
495
+
496
+ async def main():
497
+ # Collect MCP tools
498
+ mcp_client = MultiServerMCPClient(...)
499
+ mcp_tools = await mcp_client.get_tools()
500
+
501
+ # Create agent
502
+ agent = create_deep_agent(tools=mcp_tools, ....)
503
+
504
+ # Stream the agent
505
+ async for chunk in agent.astream(
506
+ {"messages": [{"role": "user", "content": "what is langgraph?"}]},
507
+ stream_mode="values"
508
+ ):
509
+ if "messages" in chunk:
510
+ chunk["messages"][-1].pretty_print()
511
+
512
+ asyncio.run(main())
513
+ ```