
    i1              $          S SK r S SKrS SKJrJrJr  S SKJrJrJ	r	J
r
JrJr  S SKJrJrJr  S SKJrJrJrJrJr  S SKJrJrJrJr  S SKJr  S SKJrJ r   S S	K!J"r"  S S
K#J$r$J%r%  S SK&J'r'J(r(  S SK)J*r*  S SK+J,r,  S SK-J.r.  S SK/J0r0  S SK1J2r2  S SK3J4r4J5r5  S SK6J7r7  S SK8J9r9  S SK:J;r;  S SK<J=r=J>r>J?r?  S SK@JArAJBrB  \C\;-  rD\C\E\;   -  rF\?" S\9S9 " S S\>5      5       rG\?" S\9S9 " S S\;5      5       rH\R                  " 5          \R                  " S\9SS 9  \?" S!\9S9 " S" S#\G5      5       rKSSS5        \R                  " 5          \R                  " S\9S$S 9  \?" S%\9S9 " S& S'\H5      5       rLSSS5        \
" S(\G\H-  S)9rM\E\M   rNS*rO\\P-  \\M/\4   -  \\M\4   -  rQSMS+\MS,\PS-\S.\4S/ jjrRS0\QS-  S.\4S1 jrS SNS2\S3\\   S4\TS.\U4S5 jjrVS2\S.\4S6 jrWS7\\   S.S4S8 jrX\?" S9\9S9SSSSSSSSSSS:S;SS<.S2\P\-  \\M\0\7   /\4   -  \\M\0\7   /\\   4   -  \\M\0\7   /\\\4   4   -  \\M\0\7   /\\\\4      4   -  S3\\\-  \C\P\4   -     \B-  S0\QS-  S=\F\Y\P\F4   -  S-  S>\ S-  S?\ S-  S@\NS-  SA\E\   S-  SB\4S-  SC\2S-  SD\Z\P   S-  SE\Z\P   S-  SF\USG\	SH   SI\PS-  SJ\S.\,4"SK jj5       r[\[r\/ SLQr]g! , (       d  f       GN= f! , (       d  f       GN`= f)O    N)	AwaitableCallableSequence)	AnnotatedAnyLiteralTypeVarcastget_type_hints)BaseChatModelLanguageModelInputLanguageModelLike)	AIMessage
AnyMessageBaseMessageSystemMessageToolMessage)RunnableRunnableBindingRunnableConfigRunnableSequence)BaseTool)RunnableCallableRunnableLike)MISSING)	ErrorCodecreate_error_message)END
StateGraph)add_messages)CompiledStateGraph)RemainingSteps)Runtime)	BaseStore)CheckpointerSend)ContextT)LangGraphDeprecatedSinceV10)	BaseModel)NotRequired	TypedDict
deprecated)ToolCallWithContextToolNodezxAgentState has been moved to `langchain.agents`. Please update your import to `from langchain.agents import AgentState`.categoryc                   D    \ rS rSr% Sr\\\   \4   \	S'   \
\   \	S'   Srg)
AgentState5   The state of the agent.messagesremaining_steps N)__name__
__module____qualname____firstlineno____doc__r   r   r   r    __annotations__r*   r"   __static_attributes__r7       `/home/james-whalen/.local/lib/python3.13/site-packages/langgraph/prebuilt/chat_agent_executor.pyr2   r2   5   s'    
 "-|;<< 00r?   r2   zAgentStatePydantic has been moved to `langchain.agents`. Please update your import to `from langchain.agents import AgentStatePydantic`.c                   B    \ rS rSr% Sr\\\   \4   \	S'   Sr
\\	S'   Srg)AgentStatePydanticA   r4   r5      r6   r7   N)r8   r9   r:   r;   r<   r   r   r   r    r=   r6   r"   r>   r7   r?   r@   rB   rB   A   s&    
 "-|;<<&(O^(r?   rB   ignorez/AgentState has been moved to langchain.agents.*)r0   messagezAgentStateWithStructuredResponse has been moved to `langchain.agents`. Please update your import to `from langchain.agents import AgentStateWithStructuredResponse`.c                   $    \ rS rSr% Sr\\S'   Srg) AgentStateWithStructuredResponseT   2The state of the agent with a structured response.structured_responser7   Nr8   r9   r:   r;   r<   StructuredResponser=   r>   r7   r?   r@   rH   rH   T       
 	A//r?   rH   z7AgentStatePydantic has been moved to langchain.agents.*zAgentStateWithStructuredResponsePydantic has been moved to `langchain.agents`. Please update your import to `from langchain.agents import AgentStateWithStructuredResponsePydantic`.c                   $    \ rS rSr% Sr\\S'   Srg)(AgentStateWithStructuredResponsePydantice   rJ   rK   r7   NrL   r7   r?   r@   rP   rP   e   rN   r?   rP   StateSchema)boundPromptstatekeydefaultreturnc                 f    [        U [        5      (       a  U R                  X5      $ [        XU5      $ N)
isinstancedictgetgetattr)rU   rV   rW   s      r@   _get_state_valuer_   |   s5     eT"" 			# U)r?   promptc                   ^ ^ T c  [        S [        S9nU$ [        T [        5      (       a  [	        T S9m[        U4S j[        S9nU$ [        T [        5      (       a  [        U 4S j[        S9nU$ [
        R                  " T 5      (       a  [        S T [        S9nU$ [        T 5      (       a  [        T [        S9nU$ [        T [        5      (       a  T nU$ [        S[        T 5       35      e)Nc                     [        U S5      $ Nr5   r_   )rU   s    r@   <lambda>&_get_prompt_runnable.<locals>.<lambda>   s    *5*=r?   namecontentc                 $   > T/[        U S5      -   $ rc   rd   )rU   _system_messages    r@   re   rf      s    ?+.>uj.QQr?   c                 $   > T/[        U S5      -   $ rc   rd   )rU   r`   s    r@   re   rf      s    6(%5eZ%HHr?   z"Got unexpected type for `prompt`: )r   PROMPT_RUNNABLE_NAMEr[   strr   inspectiscoroutinefunctioncallabler   
ValueErrortype)r`   prompt_runnablerl   s   ` @r@   _get_prompt_runnablerv      s    ~*=DX
< 7 
FC	 	 '4V'D*Q%
2 + 
FM	*	**H%
( ! 
	$	$V	,	,*%
  
&		*%
  
FH	%	%   =d6l^LMMr?   modeltoolsnum_builtinc                 n   [        U [        5      (       a  [        S U R                   5       U 5      n [        U [        5      (       d  gSU R
                  ;  a  gU R
                  S   n[        U5      [        U5      U-
  :w  a&  [        S[        U5       S[        U5      U-
   35      e[        S U 5       5      n[        5       nU HP  nUR                  S5      S:X  a	  US   S	   nOUR                  S	5      (       a  US	   nOM?  UR                  U5        MR     XE-
  =n(       a  [        S
U S35      eg)Nc              3   `   #    U  H$  n[        U[        [        45      (       d  M   Uv   M&     g 7frZ   r[   r   r   .0steps     r@   	<genexpr>%_should_bind_tools.<locals>.<genexpr>   (      'Dd_m$DE '   .	.Trx   z`Number of tools in the model.bind_tools() and tools passed to create_react_agent must match Got z tools, expected c              3   8   #    U  H  oR                   v   M     g 7frZ   rg   )r~   tools     r@   r   r      s     154YY5s   rt   functionrh   zMissing tools 'z' in the model.bind_tools()F)r[   r   nextstepsr   kwargslenrs   setr]   add)	rw   rx   ry   bound_tools
tool_namesbound_tool_names
bound_toolbound_tool_namemissing_toolss	            r@   _should_bind_toolsr      sB    %)**!KK
 
 e_--ell",,w'K
5zS%33J<0[1AK1O0PR
 	

 1511Ju!
>>&!Z/(4V<O^^F##(0O _- " #55}5?=/9TUVVr?   c                    [        U [        5      (       a  [        S U R                   5       U 5      n [        U [        5      (       a  U R
                  n [        U [        5      (       d  [        S[        U 5       35      eU $ )zKGet the underlying model from a RunnableBinding or return the model itself.c              3   `   #    U  H$  n[        U[        [        45      (       d  M   Uv   M&     g 7frZ   r|   r}   s     r@   r   _get_model.<locals>.<genexpr>   r   r   zXExpected `model` to be a ChatModel or RunnableBinding (e.g. model.bind_tools(...)), got )	r[   r   r   r   r   rS   r   	TypeErrorrt   )rw   s    r@   
_get_modelr      s{    %)**!KK
 
 %))e]++fgklqgrfst
 	
 Lr?   r5   c                    U  VVs/ s H0  n[        U[        5      (       d  M  UR                    H  nUPM     M2     nnnU  Vs1 s H&  n[        U[        5      (       d  M  UR                  iM(     nnU Vs/ s H  nUS   U;  d  M  UPM     nnU(       d  g[        SUSS  S3[        R                  S9n[        U5      es  snnf s  snf s  snf )zLValidate that all tool calls in AIMessages have a corresponding ToolMessage.idNz{Found AIMessages with tool_calls that do not have a corresponding ToolMessage. Here are the first few of those tool calls:    z.

Every tool call (LLM requesting to call a tool) in the message history MUST have a corresponding ToolMessage (result of a tool invocation to return to the LLM) - this is required by most LLM providers.)rF   
error_code)	r[   r   
tool_callsr   tool_call_idr   r   INVALID_CHAT_HISTORYrs   )r5   rF   	tool_callall_tool_callstool_call_ids_with_resultstool_calls_without_resultserror_messages          r@   _validate_chat_historyr      s     Ggy) 	 !++I 	 , 	   -5",4
7K8XH  "
 ("'IT?"<< 	'  "
 &(77QRTST7U6V Wgg 11M ]
##1""s"   CCC!C7CCzcreate_react_agent has been moved to `langchain.agents`. Please update your import to `from langchain.agents import create_agent`.Fv2)r`   response_formatpre_model_hookpost_model_hookstate_schemacontext_schemacheckpointerstoreinterrupt_beforeinterrupt_afterdebugversionrh   r   r   r   r   r   r   r   r   r   r   r   v1r   rh   deprecated_kwargsc          	        ^ ^^^^^^^^'^(^)^*^+^,^-^.^/ UR                  S[        5      =n[        La  [        R                  " S[        S9  Uc  Un[        U5      S:  a  [        SU 35      eTS;  a  [        ST S	35      eTbP  S
S1nTb  UR                  S5        [        [        T5      5      nU[        U5      -
  =n(       a  [        SU S35      eTc  Tb  [        O[        m/ n[        U[        5      (       a&  [        UR                   R#                  5       5      nUnOU Vs/ s H  n[        U[$        5      (       d  M  UPM     nn[        U Vs/ s H  n[        U[$        5      (       a  M  UPM     sn5      n[        UR                   R#                  5       5      n[        T [&        [(        45      (       + =(       a    [+        T 5      m-T-=(       a    [,        R.                  " T 5      m,[        U5      S:  nT-(       d  [        T [&        5      (       a   SSKJn  [7        [8        U" T 5      5      m [;        T U[        U5      S9(       a4  [        UU-   5      S:  a"  [7        [8        T 5      R=                  UU-   5      m [?        T5      T -  m/OSm/U Vs1 s H"  nUR@                  (       d  M  URB                  iM$     snm.S[D        S[F        [H           S[J        4U-U UU/4S jjm*S[D        S[F        [H           S[J        4U,U-U UU/4S jjm(S[D        S[L        S[N        4U.4S jjm'S[D        S[D        4UU4S jjm)S[D        S[F        [H           S[P        S[D        4U'U)U*U,U-UU/4S jjnS[D        S[F        [H           S[P        S[D        4U'U(U)U-UU/4S jjnTbT  [        T[R        5      (       a1  [U        T[V        5      (       a  SSK,J-n  U" S[        [\           S4TS 9nO " S! ST5      nUnOTnS[D        S[F        [H           S[P        S[D        4U*U,U4S" jjnS[D        S[F        [H           S[P        S[D        4U(U4S# jjn U(       d  [_        TUS$9n!U!Ra                  S%[c        UU5      US&9  Tb'  U!Ra                  S'T5        U!Re                  S'S%5        S'm+OS%m+U!Rg                  T+5        Tb$  U!Ra                  S(T5        U!Re                  S%S(5        TbD  U!Ra                  S)[c        UU 5      5        Tb  U!Re                  S(S)5        OU!Re                  S%S)5        U!Ri                  UU	U
UUTS*9$ S[D        S[&        [        [j           -  4UUU4S+ jjn"[_        T=(       d    [        US$9n!U!Ra                  S%[c        UU5      US&9  U!Ra                  S,U5        Tb'  U!Ra                  S'T5        U!Re                  S'S%5        S'm+OS%m+U!Rg                  T+5        / n#T+S,/n$Tb6  U!Ra                  S(T5        U#Rm                  S(5        U!Re                  S%S(5        OU#Rm                  S,5        TbC  U!Ra                  S)[c        UU 5      5        Tb  U$Rm                  S)5        O@U#Rm                  S)5        O.Tb  U$Rm                  [n        5        OU#Rm                  [n        5        Tb4  S[D        S[&        [        [j           -  4U+U4S- jjn%U!Rq                  S(U%U$S.9  U!Rq                  S%U"U#S.9  S[D        S[&        4U+U.4S/ jjn&T.(       a  U!Rq                  S,U&T+[n        /S.9  OU!Re                  S,T+5        U!Ri                  UU	U
UUTS*9$ s  snf s  snf ! [4         a    [5        S5      ef = fs  snf )0a&  Creates an agent graph that calls tools in a loop until a stopping condition is met.

For more details on using `create_react_agent`, visit [Agents](https://langchain-ai.github.io/langgraph/agents/overview/) documentation.

Args:
    model: The language model for the agent. Supports static and dynamic
        model selection.

        - **Static model**: A chat model instance (e.g., `ChatOpenAI()`) or
          string identifier (e.g., `"openai:gpt-4"`)
        - **Dynamic model**: A callable with signature
          `(state, runtime) -> BaseChatModel` that returns different models
          based on runtime context
          If the model has tools bound via `.bind_tools()` or other configurations,
          the return type should be a Runnable[LanguageModelInput, BaseMessage]
          Coroutines are also supported, allowing for asynchronous model selection.

        Dynamic functions receive graph state and runtime, enabling
        context-dependent model selection. Must return a `BaseChatModel`
        instance. For tool calling, bind tools using `.bind_tools()`.
        Bound tools must be a subset of the `tools` parameter.

        Dynamic model example:
        ```python
        from dataclasses import dataclass

        @dataclass
        class ModelContext:
            model_name: str = "gpt-3.5-turbo"

        # Instantiate models globally
        gpt4_model = ChatOpenAI(model="gpt-4")
        gpt35_model = ChatOpenAI(model="gpt-3.5-turbo")

        def select_model(state: AgentState, runtime: Runtime[ModelContext]) -> ChatOpenAI:
            model_name = runtime.context.model_name
            model = gpt4_model if model_name == "gpt-4" else gpt35_model
            return model.bind_tools(tools)
        ```

        !!! note "Dynamic Model Requirements"

            Ensure returned models have appropriate tools bound via
            `.bind_tools()` and support required functionality. Bound tools
            must be a subset of those specified in the `tools` parameter.

    tools: A list of tools or a `ToolNode` instance.
        If an empty list is provided, the agent will consist of a single LLM node without tool calling.
    prompt: An optional prompt for the LLM. Can take a few different forms:

        - str: This is converted to a SystemMessage and added to the beginning of the list of messages in state["messages"].
        - SystemMessage: this is added to the beginning of the list of messages in state["messages"].
        - Callable: This function should take in full graph state and the output is then passed to the language model.
        - Runnable: This runnable should take in full graph state and the output is then passed to the language model.

    response_format: An optional schema for the final agent output.

        If provided, output will be formatted to match the given schema and returned in the 'structured_response' state key.
        If not provided, `structured_response` will not be present in the output state.
        Can be passed in as:

            - an OpenAI function/tool schema,
            - a JSON Schema,
            - a TypedDict class,
            - or a Pydantic class.
            - a tuple (prompt, schema), where schema is one of the above.
                The prompt will be used together with the model that is being used to generate the structured response.

        !!! Important
            `response_format` requires the model to support `.with_structured_output`

        !!! Note
            The graph will make a separate call to the LLM to generate the structured response after the agent loop is finished.
            This is not the only strategy to get structured responses, see more options in [this guide](https://langchain-ai.github.io/langgraph/how-tos/react-agent-structured-output/).

    pre_model_hook: An optional node to add before the `agent` node (i.e., the node that calls the LLM).
        Useful for managing long message histories (e.g., message trimming, summarization, etc.).
        Pre-model hook must be a callable or a runnable that takes in current graph state and returns a state update in the form of
            ```python
            # At least one of `messages` or `llm_input_messages` MUST be provided
            {
                # If provided, will UPDATE the `messages` in the state
                "messages": [RemoveMessage(id=REMOVE_ALL_MESSAGES), ...],
                # If provided, will be used as the input to the LLM,
                # and will NOT UPDATE `messages` in the state
                "llm_input_messages": [...],
                # Any other state keys that need to be propagated
                ...
            }
            ```

        !!! Important
            At least one of `messages` or `llm_input_messages` MUST be provided and will be used as an input to the `agent` node.
            The rest of the keys will be added to the graph state.

        !!! Warning
            If you are returning `messages` in the pre-model hook, you should OVERWRITE the `messages` key by doing the following:

            ```python
            {
                "messages": [RemoveMessage(id=REMOVE_ALL_MESSAGES), *new_messages]
                ...
            }
            ```
    post_model_hook: An optional node to add after the `agent` node (i.e., the node that calls the LLM).
        Useful for implementing human-in-the-loop, guardrails, validation, or other post-processing.
        Post-model hook must be a callable or a runnable that takes in current graph state and returns a state update.

        !!! Note
            Only available with `version="v2"`.
    state_schema: An optional state schema that defines graph state.
        Must have `messages` and `remaining_steps` keys.
        Defaults to `AgentState` that defines those two keys.
        !!! Note
            `remaining_steps` is used to limit the number of steps the react agent can take.
            Calculated roughly as `recursion_limit` - `total_steps_taken`.
            If `remaining_steps` is less than 2 and tool calls are present in the response,
            the react agent will return a final AI Message with
            the content "Sorry, need more steps to process this request.".
            No `GraphRecusionError` will be raised in this case.

    context_schema: An optional schema for runtime context.
    checkpointer: An optional checkpoint saver object. This is used for persisting
        the state of the graph (e.g., as chat memory) for a single thread (e.g., a single conversation).
    store: An optional store object. This is used for persisting data
        across multiple threads (e.g., multiple conversations / users).
    interrupt_before: An optional list of node names to interrupt before.
        Should be one of the following: "agent", "tools".
        This is useful if you want to add a user confirmation or other interrupt before taking an action.
    interrupt_after: An optional list of node names to interrupt after.
        Should be one of the following: "agent", "tools".
        This is useful if you want to return directly or run additional processing on an output.
    debug: A flag indicating whether to enable debug mode.
    version: Determines the version of the graph to create.
        Can be one of:

        - `"v1"`: The tool node processes a single message. All tool
            calls in the message are executed in parallel within the tool node.
        - `"v2"`: The tool node processes a tool call.
            Tool calls are distributed across multiple instances of the tool
            node using the [Send](https://langchain-ai.github.io/langgraph/concepts/low_level/#send)
            API.
    name: An optional name for the CompiledStateGraph.
        This name will be automatically used when adding ReAct agent graph to another graph as a subgraph node -
        particularly useful for building multi-agent systems.

!!! warning "`config_schema` Deprecated"
    The `config_schema` parameter is deprecated in v0.6.0 and support will be removed in v2.0.0.
    Please use `context_schema` instead to specify the schema for run-scoped context.


Returns:
    A compiled LangChain runnable that can be used for chat interactions.

The "agent" node calls the language model with the messages list (after applying the prompt).
If the resulting AIMessage contains `tool_calls`, the graph will then call the ["tools"][langgraph.prebuilt.tool_node.ToolNode].
The "tools" node executes the tools (1 tool per `tool_call`) and adds the responses to the messages list
as `ToolMessage` objects. The agent node then calls the language model again.
The process repeats until no more `tool_calls` are present in the response.
The agent then returns the full list of messages as a dictionary containing the key "messages".

``` mermaid
    sequenceDiagram
        participant U as User
        participant A as LLM
        participant T as Tools
        U->>A: Initial input
        Note over A: Prompt + LLM
        loop while tool_calls present
            A->>T: Execute tools
            T-->>A: ToolMessage for each tool_calls
        end
        A->>U: Return final state
```

Example:
    ```python
    from langgraph.prebuilt import create_react_agent

    def check_weather(location: str) -> str:
        '''Return the weather forecast for the specified location.'''
        return f"It's always sunny in {location}"

    graph = create_react_agent(
        "anthropic:claude-3-7-sonnet-latest",
        tools=[check_weather],
        prompt="You are a helpful assistant",
    )
    inputs = {"messages": [{"role": "user", "content": "what is the weather in sf"}]}
    for chunk in graph.stream(inputs, stream_mode="updates"):
        print(chunk)
    ```
config_schemazW`config_schema` is deprecated and will be removed. Please use `context_schema` instead.r/   Nr   z7create_react_agent() got unexpected keyword arguments: r   zInvalid version z'. Supported versions are 'v1' and 'v2'.r5   r6   rK   zMissing required key(s) z in state_schema)init_chat_modelzsPlease install langchain (`pip install langchain`) to use '<provider>:<model>' string syntax for `model` parameter.)ry   rU   runtimerX   c                 >   > T(       a  [        T5      T" X5      -  $ T$ )zBResolve the model to use, handling both static and dynamic models.rv   )rU   r   is_dynamic_modelrw   r`   static_models     r@   _resolve_model*create_react_agent.<locals>._resolve_modelC  s#     '/%2GGGr?   c                    >#    T(       a  T" X5      I Sh  vN n[        T5      U-  $ T(       a  [        T5      T" X5      -  $ T$  N/7f)zHAsync resolve the model to use, handling both static and dynamic models.Nr   )rU   r   resolved_modelis_async_dynamic_modelr   rw   r`   r   s      r@   _aresolve_model+create_react_agent.<locals>._aresolve_modelL  sK      "#(#88N'/.@@'/%2GGG 9s   AA0Aresponsec                   > [        U[        5      =(       a    UR                  n[        U[        5      (       a  [        U4S jUR                   5       5      OSn[	        U SS 5      nUb  US:  a  U(       a  gUS:  a  U(       a  gg)Nc              3   2   >#    U  H  oS    T;   v   M     g7frh   Nr7   r~   callshould_return_directs     r@   r   Ecreate_react_agent.<locals>._are_more_steps_needed.<locals>.<genexpr>[  s     UATV 44AT   Fr6      T   )r[   r   r   allr_   )rU   r   has_tool_callsall_tools_return_directr6   r   s        r@   _are_more_steps_needed2create_react_agent.<locals>._are_more_steps_neededX  s|    #Hi8PX=P=P (I.. UATATUU 	 
 +52CTJ&"'> 1$r?   c                   > Tb%  [        U S5      =(       d    [        U S5      nSU  3nO[        U S5      nSU  3nUc  [        U5      e[        U5        [        T[        5      (       a  [        T[        5      (       a  Xl        U $ XS'   U $ )Nllm_input_messagesr5   zUExpected input to call_model to have 'llm_input_messages' or 'messages' key, but got z=Expected input to call_model to have 'messages' key, but got )r_   rs   r   r[   rt   
issubclassr)   r5   )rU   r5   	error_msgr   r   s      r@   _get_model_input_state2create_react_agent.<locals>._get_model_input_stateh  s    % (<=5!%4  ppuovwI'z:HOPUwW  Y''x(lD))jy.Q.Q%N  !)*r?   configc                 8  > T
(       a  Sn[        U5      eT" U 5      nT(       a(  T	" X5      n[        [        UR                  XB5      5      nO[        [        TR                  XB5      5      nTUl        T" X5      (       a  S[        UR
                  SS9/0$ SU/0$ )NAsync model callable provided but agent invoked synchronously. Use agent.ainvoke() or agent.astream(), or provide a sync model callable.r5   /Sorry, need more steps to process this request.r   rj   )RuntimeErrorr
   r   invokerh   r   )rU   r   r   msgmodel_inputdynamic_modelr   r   r   r   r   r   rh   r   s          r@   
call_model&create_react_agent.<locals>.call_model  s     "1 
 s##,U3*5:MI}';';K'PQHI|':':;'OPH !%22#;; Q  XJ''r?   c                 T  >#    T" U 5      nT	(       a8  T" X5      I S h  vN n[        [        UR                  X25      I S h  vN 5      nO'[        [        TR                  X25      I S h  vN 5      nT
Ul        T" X5      (       a  S[        UR                  SS9/0$ SU/0$  N Nb N<7f)Nr5   r   r   )r
   r   ainvokerh   r   )rU   r   r   r   r   r   r   r   r   r   rh   r   s         r@   acall_model'create_react_agent.<locals>.acall_model  s      -U3 #2%"AAMI]-B-B;-W'WXHI\-A-A+-V'VWH !%22#;; Q  XJ''# B'W'Vs3   B(B""B(B$
'B()B&
*9B($B(&B()create_modelCallModelInputSchema.)r   __base__c                   &    \ rS rSr% \\   \S'   Srg)0create_react_agent.<locals>.CallModelInputSchemai  r   r7   N)r8   r9   r:   r;   listr   r=   r>   r7   r?   r@   r   r     s    $($44r?   c                 0  > T(       a  Sn[        U5      e[        U S5      nTn[        T[        5      (       a  Tu  pe[	        US9/[        U5      -   nT
" X5      n[        U5      R                  [        [        U5      5      nUR                  XB5      n	SU	0$ )Nr   r5   ri   rK   )r   r_   r[   tupler   r   r   with_structured_outputr
   StructuredResponseSchemar   )rU   r   r   r   r5   structured_response_schemasystem_promptr   model_with_structured_outputr   r   r   r   s             r@   generate_structured_response8create_react_agent.<locals>.generate_structured_response  s     "\  s###E:6%4"ou--8G5M%m<=XNH'7'1(

 
 )+EF
 	%
 066xH%x00r?   c                 8  >#    [        U S5      nT
n[        T
[        5      (       a  T
u  pT[        US9/[	        U5      -   nT	" X5      I S h  vN n[        U5      R                  [        [        U5      5      nUR                  X25      I S h  vN nSU0$  NI N
7f)Nr5   ri   rK   )
r_   r[   r   r   r   r   r   r
   r   r   )rU   r   r   r5   r   r   r   r   r   r   r   s            r@   agenerate_structured_response9create_react_agent.<locals>.agenerate_structured_response  s      $E:6%4"ou--8G5M%m<=XNH.u>>'1(

 
 )+EF
 	%
 6==hOO%x00 ? Ps%   A	BBA BB	BB)r   r   agent)input_schemar   r   r   )r   r   r   r   r   rh   c                   > [        U S5      nUS   n[        U[        5      (       a  UR                  (       d  Tb  gTb  g[        $ TS:X  a  gTS:X  a4  Tb  gUR                   Vs/ s H  n[        S[        SUU S	95      PM     sn$ g s  snf )
Nr5   r   r   r   rx   r   tool_call_with_context__typer   rU   )r_   r[   r   r   r   r&   r-   )rU   r5   last_messager   r   r   r   s       r@   should_continue+create_react_agent.<locals>.should_continue+  s    #E:6|,	22,:Q:Q*( ,5
 $D"., !- 7 7
 !8 +#;&*"' !8
 
 !
s   &B	rx   c                   > [        U S5      nU Vs/ s H&  n[        U[        5      (       d  M  UR                  PM(     nn[	        S [        U5       5       5      nUR                   Vs/ s H  oUS   U;  d  M  UPM     nnU(       a&  U Vs/ s H  n[        S[        SUU S95      PM     sn$ [        US   [        5      (       a  T$ T	b  g[        $ s  snf s  snf s  snf )	a;  Route to the next node after post_model_hook.

Routes to one of:
* "tools": if there are pending tool calls without a corresponding message.
* "generate_structured_response": if no pending tool calls exist and response_format is specified.
* END: if no pending tool calls exist and no response_format is specified.
r5   c              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7frZ   )r[   r   )r~   ms     r@   r   Ecreate_react_agent.<locals>.post_model_hook_router.<locals>.<genexpr>  s      #-aAy1I-s   (	(r   rx   r   r  r   r   )
r_   r[   r   r   r   reversedr   r&   r-   r   )
rU   r5   r  tool_messageslast_ai_messagecpending_tool_callsr   
entrypointr   s
           r@   post_model_hook_router2create_react_agent.<locals>.post_model_hook_router  s    (z:H(0(01Jq+4N   # ##H-# O +55"5a49U5  " " !3
 !3 +#;&*"' !3
 
 HRL+66!! ,5
7"

s   CC*C:CC)path_mapc                 >  > [        [        U S5      5       H2  n[        U[        5      (       d    OUR                  T;   d  M,  [
        s  $    [        W[        5      (       a;  UR                  (       a*  [        U4S jUR                   5       5      (       a  [
        $ T$ )Nr5   c              3   2   >#    U  H  oS    T;   v   M     g7fr   r7   r   s     r@   r   Ccreate_react_agent.<locals>.route_tool_responses.<locals>.<genexpr>  s     QLD<#77Lr   )	r
  r_   r[   r   rh   r   r   r   any)rU   r  r  r   s     r@   route_tool_responses0create_react_agent.<locals>.route_tool_responses  sq    *5*=>Aa--vv--
	 ? a##QALLQQQ
r?   )9popr   warningswarnr(   r   r   rs   r   r   r   rH   r2   r[   r.   r   tools_by_namevaluesr\   ro   r   rr   rp   rq   langchain.chat_modelsr   ImportErrorr
   r   r   
bind_toolsrv   return_directrh   rR   r#   r'   r   r   boolr   rt   r   r)   pydanticr   r   r   add_noder   add_edgeset_entry_pointcompiler&   appendr   add_conditional_edges)0rw   rx   r`   r   r   r   r   r   r   r   r   r   r   r   rh   r   r   required_keysschema_keysmissing_keysllm_builtin_toolstool_classes	tool_nodettool_calling_enabledr   r   r   r   r   r   r   r   workflowr  agent_pathspost_model_hook_pathsr  r  r   r   r   r   r  r   r   r   r   s0   ` `````      ``                        @@@@@@@@@r@   create_react_agentr5    s   J +..HH 	e0	

 !*N
!EFWEXY
 	
 l"wi'NO
 	
 #%67&34.67(3{+;;;<;7~EUVWW * - 	 %'%""E//6689	(-E1At1DQEJAjD6IaJK	I33::<=%ec8_==Q(5/-T'2M2Me2T|,q0eS!! (>?E ulDU@VWL#4459.9900E )=V(Du(L  -9LLqAOOFAFFLL  %,X%6 	   
 
 %,X%6
 	
  
 k [ T  k k  2!(!(%,X%6!(@N!(	!( !(F((%,X%6(@N(	( (8 !lD))jy.Q.Q-'&$($4c#:%L5| 5 0L#11%,X%61@N1	1 1211%,X%61@N1	1 1$  <WZ5% 	 	

 %.?.8)J J  ,&/Ag'89&. 01 *!!"35ST!!'+IJ%-+   
 	
{ sT$Z/?  > !/ZH
 [1!  
 gy) !*N;*G4%

 Z(K'1 "+_=,-'#457# "*,-	
 &!(()GH=>&!((-s#"%	+ %	#T
:J %	 %	N 	&&"* 	' 	
 "" # K C   &&)Z4E 	' 	
 	':.
 !)'   i FJ  !T . Ms0   '\4\4\92\9\> ]0]>])r5  create_tool_calling_executorr2   rB   rH   rP   rZ   )r   )^rp   r  collections.abcr   r   r   typingr   r   r   r	   r
   r   langchain_core.language_modelsr   r   r   langchain_core.messagesr   r   r   r   r   langchain_core.runnablesr   r   r   r   langchain_core.toolsr   langgraph._internal._runnabler   r   langgraph._internal._typingr   langgraph.errorsr   r   langgraph.graphr   r   langgraph.graph.messager    langgraph.graph.stater!   langgraph.managedr"   langgraph.runtimer#   langgraph.store.baser$   langgraph.typesr%   r&   langgraph.typingr'   langgraph.warningsr(   r#  r)   typing_extensionsr*   r+   r,   langgraph.prebuilt.tool_noder-   r.   r\   rM   rt   r   r2   rB   catch_warningsfilterwarningsrH   rP   rR   StateSchemaTypern   ro   rT   r_   rv   intr"  r   r   r   r   r   r5  r6  __all__r7   r?   r@   <module>rP     s     9 9  
   * H / < + 0 4 , % * . % :  @ @ FI% $y/1  ~(1 1	1  O() )	) ,A  	o,0: 0	0 " ,I  	,03E 0	0 " m:8J+JK{#  	
}0012 {../0 K c C 3 !$ !8 !J MN,,%-h%7,FI,	,^' M .${#$	$>  I($ ! *.+/+/'+(,")-(,#'9EWX./>?@ WX./=1IIJK 	gh'((3E{3R*SS	 	gh'((-{:;<	>
E Hx'$sCx.89HDE TME .C))*+
E$ !4'%E& "D('E( "D()E* I$+E, %-E. t/E0 3i$&1E2 #Y%3E4 5E6 Z 7E8 *9E: ;E< =E	ER  2 _ " s   =(J->(J?-
J<?
K