22from  deepagents .model  import  get_default_model 
33from  deepagents .tools  import  write_todos , write_file , read_file , ls , edit_file 
44from  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 
66from  langchain_core .tools  import  BaseTool 
77from  langchain_core .language_models  import  LanguageModelLike 
88
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 
919from  langgraph .prebuilt  import  create_react_agent 
1020
1121StateSchema  =  TypeVar ("StateSchema" , bound = DeepAgentState )
@@ -30,11 +40,16 @@ def create_deep_agent(
3040    model : Optional [Union [str , LanguageModelLike ]] =  None ,
3141    subagents : list [SubAgent ] =  None ,
3242    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 ,
3348):
3449    """Create a deep agent. 
3550
3651    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 . 
3853
3954    Args: 
4055        tools: The additional tools the agent should have access to. 
@@ -48,9 +63,18 @@ def create_deep_agent(
4863                - `prompt` (used as the system prompt in the subagent) 
4964                - (optional) `tools` 
5065        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. 
5170    """ 
71+     
5272    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+ 
5478    if  model  is  None :
5579        model  =  get_default_model ()
5680    state_schema  =  state_schema  or  DeepAgentState 
@@ -62,9 +86,26 @@ def create_deep_agent(
6286        state_schema 
6387    )
6488    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+     
65103    return  create_react_agent (
66104        model ,
67105        prompt = prompt ,
68106        tools = all_tools ,
69107        state_schema = state_schema ,
108+         post_model_hook = selected_post_model_hook ,
109+         config_schema = config_schema ,
110+         checkpointer = checkpointer ,
70111    )
0 commit comments