2
2
from deepagents .model import get_default_model
3
3
from deepagents .tools import write_todos , write_file , read_file , ls , edit_file
4
4
from deepagents .state import DeepAgentState
5
- from typing import Sequence , Union , Callable , Any , TypeVar , Type , Optional
5
+ from typing import Sequence , Union , Callable , Any , TypeVar , Type , Optional , Dict
6
6
from langchain_core .tools import BaseTool
7
7
from langchain_core .language_models import LanguageModelLike
8
8
9
+ from deepagents .local_tools import (
10
+ write_file as local_write_file ,
11
+ read_file as local_read_file ,
12
+ ls as local_ls ,
13
+ glob as local_glob ,
14
+ grep as local_grep ,
15
+ str_replace_based_edit_tool ,
16
+ )
17
+ from deepagents .interrupt import create_interrupt_hook , ToolInterruptConfig
18
+ from langgraph .types import Checkpointer
9
19
from langgraph .prebuilt import create_react_agent
10
20
11
21
StateSchema = TypeVar ("StateSchema" , bound = DeepAgentState )
@@ -30,11 +40,16 @@ def create_deep_agent(
30
40
model : Optional [Union [str , LanguageModelLike ]] = None ,
31
41
subagents : list [SubAgent ] = None ,
32
42
state_schema : Optional [StateSchemaType ] = None ,
43
+ interrupt_config : Optional [ToolInterruptConfig ] = None ,
44
+ config_schema : Optional [Type [Any ]] = None ,
45
+ checkpointer : Optional [Checkpointer ] = None ,
46
+ post_model_hook : Optional [Callable ] = None ,
47
+ local_filesystem : bool = False ,
33
48
):
34
49
"""Create a deep agent.
35
50
36
51
This agent will by default have access to a tool to write todos (write_todos),
37
- and then four file editing tools: write_file, ls, read_file, edit_file .
52
+ and then four file editing tools: write_file, ls, read_file, str_replace_based_edit_tool .
38
53
39
54
Args:
40
55
tools: The additional tools the agent should have access to.
@@ -48,9 +63,18 @@ def create_deep_agent(
48
63
- `prompt` (used as the system prompt in the subagent)
49
64
- (optional) `tools`
50
65
state_schema: The schema of the deep agent. Should subclass from DeepAgentState
66
+ interrupt_config: Optional Dict[str, HumanInterruptConfig] mapping tool names to interrupt configs.
67
+
68
+ config_schema: The schema of the deep agent.
69
+ checkpointer: Optional checkpointer for persisting agent state between runs.
51
70
"""
71
+
52
72
prompt = instructions + base_prompt
53
- built_in_tools = [write_todos , write_file , read_file , ls , edit_file ]
73
+ if local_filesystem :
74
+ built_in_tools = [write_todos , local_write_file , local_read_file , local_ls , local_glob , local_grep , str_replace_based_edit_tool ]
75
+ else :
76
+ built_in_tools = [write_todos , write_file , read_file , ls , edit_file ]
77
+
54
78
if model is None :
55
79
model = get_default_model ()
56
80
state_schema = state_schema or DeepAgentState
@@ -62,9 +86,26 @@ def create_deep_agent(
62
86
state_schema
63
87
)
64
88
all_tools = built_in_tools + list (tools ) + [task_tool ]
89
+
90
+ # Should never be the case that both are specified
91
+ if post_model_hook and interrupt_config :
92
+ raise ValueError (
93
+ "Cannot specify both post_model_hook and interrupt_config together. "
94
+ "Use either interrupt_config for tool interrupts or post_model_hook for custom post-processing."
95
+ )
96
+ elif post_model_hook is not None :
97
+ selected_post_model_hook = post_model_hook
98
+ elif interrupt_config is not None :
99
+ selected_post_model_hook = create_interrupt_hook (interrupt_config )
100
+ else :
101
+ selected_post_model_hook = None
102
+
65
103
return create_react_agent (
66
104
model ,
67
105
prompt = prompt ,
68
106
tools = all_tools ,
69
107
state_schema = state_schema ,
108
+ post_model_hook = selected_post_model_hook ,
109
+ config_schema = config_schema ,
110
+ checkpointer = checkpointer ,
70
111
)
0 commit comments