deepagents 0.3.7a1__py3-none-any.whl → 0.3.9__py3-none-any.whl
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.
- deepagents/backends/filesystem.py +55 -7
- deepagents/backends/sandbox.py +76 -23
- deepagents/graph.py +29 -10
- deepagents/middleware/__init__.py +3 -1
- deepagents/middleware/filesystem.py +508 -544
- deepagents/middleware/memory.py +11 -7
- deepagents/middleware/skills.py +4 -2
- deepagents/middleware/subagents.py +35 -19
- deepagents/middleware/summarization.py +763 -0
- {deepagents-0.3.7a1.dist-info → deepagents-0.3.9.dist-info}/METADATA +7 -7
- deepagents-0.3.9.dist-info/RECORD +22 -0
- {deepagents-0.3.7a1.dist-info → deepagents-0.3.9.dist-info}/WHEEL +1 -1
- deepagents-0.3.7a1.dist-info/RECORD +0 -21
- {deepagents-0.3.7a1.dist-info → deepagents-0.3.9.dist-info}/top_level.txt +0 -0
deepagents/middleware/memory.py
CHANGED
|
@@ -74,7 +74,7 @@ logger = logging.getLogger(__name__)
|
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
class MemoryState(AgentState):
|
|
77
|
-
"""State schema for MemoryMiddleware
|
|
77
|
+
"""State schema for `MemoryMiddleware`.
|
|
78
78
|
|
|
79
79
|
Attributes:
|
|
80
80
|
memory_contents: Dict mapping source paths to their loaded content.
|
|
@@ -85,7 +85,7 @@ class MemoryState(AgentState):
|
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
class MemoryStateUpdate(TypedDict):
|
|
88
|
-
"""State update for MemoryMiddleware
|
|
88
|
+
"""State update for `MemoryMiddleware`."""
|
|
89
89
|
|
|
90
90
|
memory_contents: dict[str, str]
|
|
91
91
|
|
|
@@ -153,14 +153,15 @@ MEMORY_SYSTEM_PROMPT = """<agent_memory>
|
|
|
153
153
|
|
|
154
154
|
|
|
155
155
|
class MemoryMiddleware(AgentMiddleware):
|
|
156
|
-
"""Middleware for loading agent memory from AGENTS.md files.
|
|
156
|
+
"""Middleware for loading agent memory from `AGENTS.md` files.
|
|
157
157
|
|
|
158
158
|
Loads memory content from configured sources and injects into the system prompt.
|
|
159
|
+
|
|
159
160
|
Supports multiple sources that are combined together.
|
|
160
161
|
|
|
161
162
|
Args:
|
|
162
163
|
backend: Backend instance or factory function for file operations.
|
|
163
|
-
sources: List of MemorySource configurations specifying paths and names.
|
|
164
|
+
sources: List of `MemorySource` configurations specifying paths and names.
|
|
164
165
|
"""
|
|
165
166
|
|
|
166
167
|
state_schema = MemoryState
|
|
@@ -176,9 +177,12 @@ class MemoryMiddleware(AgentMiddleware):
|
|
|
176
177
|
Args:
|
|
177
178
|
backend: Backend instance or factory function that takes runtime
|
|
178
179
|
and returns a backend. Use a factory for StateBackend.
|
|
179
|
-
sources: List of memory file paths to load (e.g., ["~/.deepagents/AGENTS.md",
|
|
180
|
-
"./.deepagents/AGENTS.md"]).
|
|
181
|
-
|
|
180
|
+
sources: List of memory file paths to load (e.g., `["~/.deepagents/AGENTS.md",
|
|
181
|
+
"./.deepagents/AGENTS.md"]`).
|
|
182
|
+
|
|
183
|
+
Display names are automatically derived from the paths.
|
|
184
|
+
|
|
185
|
+
Sources are loaded in order.
|
|
182
186
|
"""
|
|
183
187
|
self._backend = backend
|
|
184
188
|
self.sources = sources
|
deepagents/middleware/skills.py
CHANGED
|
@@ -560,6 +560,8 @@ class SkillsMiddleware(AgentMiddleware):
|
|
|
560
560
|
lines = []
|
|
561
561
|
for skill in skills:
|
|
562
562
|
lines.append(f"- **{skill['name']}**: {skill['description']}")
|
|
563
|
+
if skill["allowed_tools"]:
|
|
564
|
+
lines.append(f" -> Allowed tools: {', '.join(skill['allowed_tools'])}")
|
|
563
565
|
lines.append(f" -> Read `{skill['path']}` for full instructions")
|
|
564
566
|
|
|
565
567
|
return "\n".join(lines)
|
|
@@ -601,7 +603,7 @@ class SkillsMiddleware(AgentMiddleware):
|
|
|
601
603
|
config: Runnable config.
|
|
602
604
|
|
|
603
605
|
Returns:
|
|
604
|
-
State update with skills_metadata populated, or None if already present
|
|
606
|
+
State update with `skills_metadata` populated, or `None` if already present
|
|
605
607
|
"""
|
|
606
608
|
# Skip if skills_metadata is already present in state (even if empty)
|
|
607
609
|
if "skills_metadata" in state:
|
|
@@ -636,7 +638,7 @@ class SkillsMiddleware(AgentMiddleware):
|
|
|
636
638
|
config: Runnable config.
|
|
637
639
|
|
|
638
640
|
Returns:
|
|
639
|
-
State update with skills_metadata populated, or None if already present
|
|
641
|
+
State update with `skills_metadata` populated, or `None` if already present
|
|
640
642
|
"""
|
|
641
643
|
# Skip if skills_metadata is already present in state (even if empty)
|
|
642
644
|
if "skills_metadata" in state:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Middleware for providing subagents to an agent via a `task` tool."""
|
|
2
2
|
|
|
3
3
|
from collections.abc import Awaitable, Callable, Sequence
|
|
4
|
-
from typing import Any, NotRequired, TypedDict, cast
|
|
4
|
+
from typing import Annotated, Any, NotRequired, TypedDict, cast
|
|
5
5
|
|
|
6
6
|
from langchain.agents import create_agent
|
|
7
7
|
from langchain.agents.middleware import HumanInTheLoopMiddleware, InterruptOnConfig
|
|
@@ -73,10 +73,14 @@ class SubAgent(TypedDict):
|
|
|
73
73
|
class CompiledSubAgent(TypedDict):
|
|
74
74
|
"""A pre-compiled agent spec.
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
!!! note
|
|
77
|
+
|
|
78
|
+
The runnable's state schema must include a 'messages' key.
|
|
79
|
+
|
|
80
|
+
This is required for the subagent to communicate results back to the main agent.
|
|
81
|
+
|
|
78
82
|
When the subagent completes, the final message in the 'messages' list will be
|
|
79
|
-
extracted and returned as a ToolMessage to the parent agent.
|
|
83
|
+
extracted and returned as a `ToolMessage` to the parent agent.
|
|
80
84
|
"""
|
|
81
85
|
|
|
82
86
|
name: str
|
|
@@ -90,8 +94,8 @@ class CompiledSubAgent(TypedDict):
|
|
|
90
94
|
|
|
91
95
|
Create a custom agent using either:
|
|
92
96
|
|
|
93
|
-
1. LangChain's `create_agent()
|
|
94
|
-
2. A custom graph using langgraph
|
|
97
|
+
1. LangChain's [`create_agent()`](https://docs.langchain.com/oss/python/langchain/quickstart)
|
|
98
|
+
2. A custom graph using [`langgraph`](https://docs.langchain.com/oss/python/langgraph/quickstart)
|
|
95
99
|
|
|
96
100
|
If you're creating a custom graph, make sure the state schema includes a 'messages' key.
|
|
97
101
|
This is required for the subagent to communicate results back to the main agent.
|
|
@@ -395,8 +399,11 @@ def _create_task_tool(
|
|
|
395
399
|
task_description = task_description.format(available_agents=subagent_description_str)
|
|
396
400
|
|
|
397
401
|
def task(
|
|
398
|
-
description:
|
|
399
|
-
|
|
402
|
+
description: Annotated[
|
|
403
|
+
str,
|
|
404
|
+
"A detailed description of the task for the subagent to perform autonomously. Include all necessary context and specify the expected output format.", # noqa: E501
|
|
405
|
+
],
|
|
406
|
+
subagent_type: Annotated[str, "The type of subagent to use. Must be one of the available agent types listed in the tool description."],
|
|
400
407
|
runtime: ToolRuntime,
|
|
401
408
|
) -> str | Command:
|
|
402
409
|
if subagent_type not in subagent_graphs:
|
|
@@ -410,8 +417,11 @@ def _create_task_tool(
|
|
|
410
417
|
return _return_command_with_state_update(result, runtime.tool_call_id)
|
|
411
418
|
|
|
412
419
|
async def atask(
|
|
413
|
-
description:
|
|
414
|
-
|
|
420
|
+
description: Annotated[
|
|
421
|
+
str,
|
|
422
|
+
"A detailed description of the task for the subagent to perform autonomously. Include all necessary context and specify the expected output format.", # noqa: E501
|
|
423
|
+
],
|
|
424
|
+
subagent_type: Annotated[str, "The type of subagent to use. Must be one of the available agent types listed in the tool description."],
|
|
415
425
|
runtime: ToolRuntime,
|
|
416
426
|
) -> str | Command:
|
|
417
427
|
if subagent_type not in subagent_graphs:
|
|
@@ -450,18 +460,24 @@ class SubAgentMiddleware(AgentMiddleware):
|
|
|
450
460
|
|
|
451
461
|
Args:
|
|
452
462
|
default_model: The model to use for subagents.
|
|
453
|
-
|
|
463
|
+
|
|
464
|
+
Can be a `LanguageModelLike` or a dict for `init_chat_model`.
|
|
454
465
|
default_tools: The tools to use for the default general-purpose subagent.
|
|
455
|
-
default_middleware: Default middleware to apply to all subagents.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
466
|
+
default_middleware: Default middleware to apply to all subagents.
|
|
467
|
+
|
|
468
|
+
If `None`, no default middleware is applied.
|
|
469
|
+
|
|
470
|
+
Pass a list to specify custom middleware.
|
|
471
|
+
default_interrupt_on: The tool configs to use for the default general-purpose subagent.
|
|
472
|
+
|
|
473
|
+
These are also the fallback for any subagents that don't specify their own tool configs.
|
|
459
474
|
subagents: A list of additional subagents to provide to the agent.
|
|
460
475
|
system_prompt: Full system prompt override. When provided, completely replaces
|
|
461
476
|
the agent's system prompt.
|
|
462
|
-
general_purpose_agent: Whether to include the general-purpose agent.
|
|
463
|
-
task_description: Custom description for the task tool.
|
|
464
|
-
|
|
477
|
+
general_purpose_agent: Whether to include the general-purpose agent.
|
|
478
|
+
task_description: Custom description for the task tool.
|
|
479
|
+
|
|
480
|
+
If `None`, uses the default description template.
|
|
465
481
|
|
|
466
482
|
Example:
|
|
467
483
|
```python
|
|
@@ -505,7 +521,7 @@ class SubAgentMiddleware(AgentMiddleware):
|
|
|
505
521
|
general_purpose_agent: bool = True,
|
|
506
522
|
task_description: str | None = None,
|
|
507
523
|
) -> None:
|
|
508
|
-
"""Initialize the SubAgentMiddleware
|
|
524
|
+
"""Initialize the `SubAgentMiddleware`."""
|
|
509
525
|
super().__init__()
|
|
510
526
|
self.system_prompt = system_prompt
|
|
511
527
|
task_tool = _create_task_tool(
|