deepagents 0.0.12rc1__py3-none-any.whl → 0.0.12rc2__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/__init__.py +7 -5
- deepagents/graph.py +109 -129
- deepagents/middleware/__init__.py +6 -0
- deepagents/middleware/filesystem.py +1125 -0
- deepagents/middleware/subagents.py +481 -0
- {deepagents-0.0.12rc1.dist-info → deepagents-0.0.12rc2.dist-info}/METADATA +12 -11
- deepagents-0.0.12rc2.dist-info/RECORD +10 -0
- {deepagents-0.0.12rc1.dist-info → deepagents-0.0.12rc2.dist-info}/top_level.txt +0 -1
- deepagents/middleware.py +0 -216
- deepagents/model.py +0 -5
- deepagents/prompts.py +0 -429
- deepagents/state.py +0 -33
- deepagents/tools.py +0 -313
- deepagents/types.py +0 -21
- deepagents-0.0.12rc1.dist-info/RECORD +0 -18
- tests/test_deepagents.py +0 -136
- tests/test_filesystem.py +0 -196
- tests/test_hitl.py +0 -51
- tests/test_middleware.py +0 -57
- tests/utils.py +0 -81
- {deepagents-0.0.12rc1.dist-info → deepagents-0.0.12rc2.dist-info}/WHEEL +0 -0
- {deepagents-0.0.12rc1.dist-info → deepagents-0.0.12rc2.dist-info}/licenses/LICENSE +0 -0
deepagents/__init__.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
from deepagents.
|
|
4
|
-
from deepagents.
|
|
5
|
-
from deepagents.
|
|
1
|
+
"""DeepAgents package."""
|
|
2
|
+
|
|
3
|
+
from deepagents.graph import create_deep_agent
|
|
4
|
+
from deepagents.middleware.filesystem import FilesystemMiddleware
|
|
5
|
+
from deepagents.middleware.subagents import CompiledSubAgent, SubAgent, SubAgentMiddleware
|
|
6
|
+
|
|
7
|
+
__all__ = ["CompiledSubAgent", "FilesystemMiddleware", "SubAgent", "SubAgentMiddleware", "create_deep_agent"]
|
deepagents/graph.py
CHANGED
|
@@ -1,160 +1,140 @@
|
|
|
1
|
-
|
|
1
|
+
"""Deepagents come with planning, filesystem, and subagents."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable, Sequence
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from langchain.agents import create_agent
|
|
7
|
+
from langchain.agents.middleware import HumanInTheLoopMiddleware, InterruptOnConfig, TodoListMiddleware
|
|
8
|
+
from langchain.agents.middleware.summarization import SummarizationMiddleware
|
|
9
|
+
from langchain.agents.middleware.types import AgentMiddleware
|
|
10
|
+
from langchain.agents.structured_output import ResponseFormat
|
|
11
|
+
from langchain_anthropic import ChatAnthropic
|
|
12
|
+
from langchain_core.language_models import BaseChatModel
|
|
2
13
|
from langchain_core.tools import BaseTool
|
|
3
|
-
from
|
|
4
|
-
from langgraph.
|
|
14
|
+
from langgraph.cache.base import BaseCache
|
|
15
|
+
from langgraph.graph.state import CompiledStateGraph
|
|
5
16
|
from langgraph.store.base import BaseStore
|
|
6
|
-
from
|
|
7
|
-
from langchain.agents.middleware import AgentMiddleware, SummarizationMiddleware, HumanInTheLoopMiddleware
|
|
8
|
-
from langchain.agents.middleware.human_in_the_loop import ToolConfig
|
|
9
|
-
from langchain.agents.middleware.prompt_caching import AnthropicPromptCachingMiddleware
|
|
10
|
-
from deepagents.middleware import PlanningMiddleware, FilesystemMiddleware, SubAgentMiddleware
|
|
11
|
-
from deepagents.prompts import BASE_AGENT_PROMPT
|
|
12
|
-
from deepagents.model import get_default_model
|
|
13
|
-
from deepagents.types import SubAgent, CustomSubAgent
|
|
17
|
+
from langgraph.types import Checkpointer
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
instructions: str,
|
|
18
|
-
middleware: Optional[list[AgentMiddleware]] = None,
|
|
19
|
-
tool_configs: Optional[dict[str, bool | ToolConfig]] = None,
|
|
20
|
-
model: Optional[Union[str, LanguageModelLike]] = None,
|
|
21
|
-
subagents: Optional[list[SubAgent | CustomSubAgent]] = None,
|
|
22
|
-
context_schema: Optional[Type[Any]] = None,
|
|
23
|
-
checkpointer: Optional[Checkpointer] = None,
|
|
24
|
-
store: Optional[BaseStore] = None,
|
|
25
|
-
use_longterm_memory: bool = False,
|
|
26
|
-
is_async: bool = False,
|
|
27
|
-
):
|
|
28
|
-
if model is None:
|
|
29
|
-
model = get_default_model()
|
|
19
|
+
from deepagents.middleware.filesystem import FilesystemMiddleware
|
|
20
|
+
from deepagents.middleware.subagents import CompiledSubAgent, SubAgent, SubAgentMiddleware
|
|
30
21
|
|
|
31
|
-
|
|
32
|
-
PlanningMiddleware(),
|
|
33
|
-
FilesystemMiddleware(
|
|
34
|
-
use_longterm_memory=use_longterm_memory,
|
|
35
|
-
),
|
|
36
|
-
SubAgentMiddleware(
|
|
37
|
-
default_subagent_tools=tools, # NOTE: These tools are piped to the general-purpose subagent.
|
|
38
|
-
subagents=subagents if subagents is not None else [],
|
|
39
|
-
model=model,
|
|
40
|
-
is_async=is_async,
|
|
41
|
-
),
|
|
42
|
-
SummarizationMiddleware(
|
|
43
|
-
model=model,
|
|
44
|
-
max_tokens_before_summary=120000,
|
|
45
|
-
messages_to_keep=20,
|
|
46
|
-
),
|
|
47
|
-
AnthropicPromptCachingMiddleware(ttl="5m", unsupported_model_behavior="ignore")
|
|
48
|
-
]
|
|
49
|
-
# Add tool interrupt config if provided
|
|
50
|
-
if tool_configs is not None:
|
|
51
|
-
deepagent_middleware.append(HumanInTheLoopMiddleware(interrupt_on=tool_configs))
|
|
22
|
+
BASE_AGENT_PROMPT = "In order to complete the objective that the user asks of you, you have access to a number of standard tools."
|
|
52
23
|
|
|
53
|
-
if middleware is not None:
|
|
54
|
-
deepagent_middleware.extend(middleware)
|
|
55
24
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
system_prompt=instructions + "\n\n" + BASE_AGENT_PROMPT,
|
|
59
|
-
tools=tools,
|
|
60
|
-
middleware=deepagent_middleware,
|
|
61
|
-
context_schema=context_schema,
|
|
62
|
-
checkpointer=checkpointer,
|
|
63
|
-
store=store,
|
|
64
|
-
)
|
|
25
|
+
def get_default_model() -> ChatAnthropic:
|
|
26
|
+
"""Get the default model for deep agents.
|
|
65
27
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
instructions: str = "",
|
|
69
|
-
middleware: Optional[list[AgentMiddleware]] = None,
|
|
70
|
-
model: Optional[Union[str, LanguageModelLike]] = None,
|
|
71
|
-
subagents: Optional[list[SubAgent | CustomSubAgent]] = None,
|
|
72
|
-
context_schema: Optional[Type[Any]] = None,
|
|
73
|
-
checkpointer: Optional[Checkpointer] = None,
|
|
74
|
-
store: Optional[BaseStore] = None,
|
|
75
|
-
use_longterm_memory: bool = False,
|
|
76
|
-
tool_configs: Optional[dict[str, bool | ToolConfig]] = None,
|
|
77
|
-
):
|
|
78
|
-
"""Create a deep agent.
|
|
79
|
-
This agent will by default have access to a tool to write todos (write_todos),
|
|
80
|
-
four file editing tools: write_file, ls, read_file, edit_file, and a tool to call subagents.
|
|
81
|
-
Args:
|
|
82
|
-
tools: The tools the agent should have access to.
|
|
83
|
-
instructions: The additional instructions the agent should have. Will go in
|
|
84
|
-
the system prompt.
|
|
85
|
-
model: The model to use.
|
|
86
|
-
subagents: The subagents to use. Each subagent should be a dictionary with the
|
|
87
|
-
following keys:
|
|
88
|
-
- `name`
|
|
89
|
-
- `description` (used by the main agent to decide whether to call the sub agent)
|
|
90
|
-
- `prompt` (used as the system prompt in the subagent)
|
|
91
|
-
- (optional) `tools`
|
|
92
|
-
- (optional) `model` (either a LanguageModelLike instance or dict settings)
|
|
93
|
-
- (optional) `middleware` (list of AgentMiddleware)
|
|
94
|
-
context_schema: The schema of the deep agent.
|
|
95
|
-
checkpointer: Optional checkpointer for persisting agent state between runs.
|
|
96
|
-
store: Optional store for persisting longterm memories.
|
|
97
|
-
use_longterm_memory: Whether to use longterm memory - you must provide a store in order to use longterm memory.
|
|
98
|
-
tool_configs: Optional Dict[str, HumanInTheLoopConfig] mapping tool names to interrupt configs.
|
|
28
|
+
Returns:
|
|
29
|
+
ChatAnthropic instance configured with Claude Sonnet 4.
|
|
99
30
|
"""
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
middleware=middleware,
|
|
104
|
-
model=model,
|
|
105
|
-
subagents=subagents,
|
|
106
|
-
context_schema=context_schema,
|
|
107
|
-
checkpointer=checkpointer,
|
|
108
|
-
store=store,
|
|
109
|
-
use_longterm_memory=use_longterm_memory,
|
|
110
|
-
tool_configs=tool_configs,
|
|
111
|
-
is_async=False,
|
|
31
|
+
return ChatAnthropic(
|
|
32
|
+
model_name="claude-sonnet-4-20250514",
|
|
33
|
+
max_tokens=64000,
|
|
112
34
|
)
|
|
113
35
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
36
|
+
|
|
37
|
+
def create_deep_agent(
|
|
38
|
+
model: str | BaseChatModel | None = None,
|
|
39
|
+
tools: Sequence[BaseTool | Callable | dict[str, Any]] | None = None,
|
|
40
|
+
*,
|
|
41
|
+
system_prompt: str | None = None,
|
|
42
|
+
middleware: Sequence[AgentMiddleware] = (),
|
|
43
|
+
subagents: list[SubAgent | CompiledSubAgent] | None = None,
|
|
44
|
+
response_format: ResponseFormat | None = None,
|
|
45
|
+
context_schema: type[Any] | None = None,
|
|
46
|
+
checkpointer: Checkpointer | None = None,
|
|
47
|
+
store: BaseStore | None = None,
|
|
123
48
|
use_longterm_memory: bool = False,
|
|
124
|
-
|
|
125
|
-
|
|
49
|
+
interrupt_on: dict[str, bool | InterruptOnConfig] | None = None,
|
|
50
|
+
debug: bool = False,
|
|
51
|
+
name: str | None = None,
|
|
52
|
+
cache: BaseCache | None = None,
|
|
53
|
+
) -> CompiledStateGraph:
|
|
126
54
|
"""Create a deep agent.
|
|
55
|
+
|
|
127
56
|
This agent will by default have access to a tool to write todos (write_todos),
|
|
128
|
-
four file editing tools: write_file, ls, read_file, edit_file, and a tool to call
|
|
57
|
+
four file editing tools: write_file, ls, read_file, edit_file, and a tool to call
|
|
58
|
+
subagents.
|
|
59
|
+
|
|
129
60
|
Args:
|
|
130
61
|
tools: The tools the agent should have access to.
|
|
131
|
-
|
|
62
|
+
system_prompt: The additional instructions the agent should have. Will go in
|
|
132
63
|
the system prompt.
|
|
64
|
+
middleware: Additional middleware to apply after standard middleware.
|
|
133
65
|
model: The model to use.
|
|
134
66
|
subagents: The subagents to use. Each subagent should be a dictionary with the
|
|
135
67
|
following keys:
|
|
136
68
|
- `name`
|
|
137
|
-
- `description` (used by the main agent to decide whether to call the
|
|
69
|
+
- `description` (used by the main agent to decide whether to call the
|
|
70
|
+
sub agent)
|
|
138
71
|
- `prompt` (used as the system prompt in the subagent)
|
|
139
72
|
- (optional) `tools`
|
|
140
|
-
- (optional) `model` (either a LanguageModelLike instance or dict
|
|
73
|
+
- (optional) `model` (either a LanguageModelLike instance or dict
|
|
74
|
+
settings)
|
|
141
75
|
- (optional) `middleware` (list of AgentMiddleware)
|
|
76
|
+
response_format: A structured output response format to use for the agent.
|
|
142
77
|
context_schema: The schema of the deep agent.
|
|
143
78
|
checkpointer: Optional checkpointer for persisting agent state between runs.
|
|
144
|
-
use_longterm_memory: Whether to use longterm memory - you must provide a store in order to use longterm memory.
|
|
145
79
|
store: Optional store for persisting longterm memories.
|
|
146
|
-
|
|
80
|
+
use_longterm_memory: Whether to use longterm memory - you must provide a store
|
|
81
|
+
in order to use longterm memory.
|
|
82
|
+
interrupt_on: Optional Dict[str, bool | InterruptOnConfig] mapping tool names to
|
|
83
|
+
interrupt configs.
|
|
84
|
+
debug: Whether to enable debug mode. Passed through to create_agent.
|
|
85
|
+
name: The name of the agent. Passed through to create_agent.
|
|
86
|
+
cache: The cache to use for the agent. Passed through to create_agent.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
A configured deep agent.
|
|
147
90
|
"""
|
|
148
|
-
|
|
91
|
+
if model is None:
|
|
92
|
+
model = get_default_model()
|
|
93
|
+
|
|
94
|
+
deepagent_middleware = [
|
|
95
|
+
TodoListMiddleware(),
|
|
96
|
+
FilesystemMiddleware(
|
|
97
|
+
long_term_memory=use_longterm_memory,
|
|
98
|
+
),
|
|
99
|
+
SubAgentMiddleware(
|
|
100
|
+
default_model=model,
|
|
101
|
+
default_tools=tools,
|
|
102
|
+
subagents=subagents if subagents is not None else [],
|
|
103
|
+
default_middleware=[
|
|
104
|
+
TodoListMiddleware(),
|
|
105
|
+
FilesystemMiddleware(
|
|
106
|
+
long_term_memory=use_longterm_memory,
|
|
107
|
+
),
|
|
108
|
+
SummarizationMiddleware(
|
|
109
|
+
model=model,
|
|
110
|
+
max_tokens_before_summary=120000,
|
|
111
|
+
messages_to_keep=20,
|
|
112
|
+
),
|
|
113
|
+
],
|
|
114
|
+
default_interrupt_on=interrupt_on,
|
|
115
|
+
general_purpose_agent=True,
|
|
116
|
+
),
|
|
117
|
+
SummarizationMiddleware(
|
|
118
|
+
model=model,
|
|
119
|
+
max_tokens_before_summary=120000,
|
|
120
|
+
messages_to_keep=20,
|
|
121
|
+
),
|
|
122
|
+
]
|
|
123
|
+
if interrupt_on is not None:
|
|
124
|
+
deepagent_middleware.append(HumanInTheLoopMiddleware(interrupt_on=interrupt_on))
|
|
125
|
+
if middleware is not None:
|
|
126
|
+
deepagent_middleware.extend(middleware)
|
|
127
|
+
|
|
128
|
+
return create_agent(
|
|
129
|
+
model,
|
|
130
|
+
system_prompt=system_prompt + "\n\n" + BASE_AGENT_PROMPT if system_prompt else BASE_AGENT_PROMPT,
|
|
149
131
|
tools=tools,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
model=model,
|
|
153
|
-
subagents=subagents,
|
|
132
|
+
middleware=deepagent_middleware,
|
|
133
|
+
response_format=response_format,
|
|
154
134
|
context_schema=context_schema,
|
|
155
135
|
checkpointer=checkpointer,
|
|
156
136
|
store=store,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
)
|
|
137
|
+
debug=debug,
|
|
138
|
+
name=name,
|
|
139
|
+
cache=cache,
|
|
140
|
+
)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""Middleware for the DeepAgent."""
|
|
2
|
+
|
|
3
|
+
from deepagents.middleware.filesystem import FilesystemMiddleware
|
|
4
|
+
from deepagents.middleware.subagents import CompiledSubAgent, SubAgent, SubAgentMiddleware
|
|
5
|
+
|
|
6
|
+
__all__ = ["CompiledSubAgent", "FilesystemMiddleware", "SubAgent", "SubAgentMiddleware"]
|