Ë
    òÏj�›  ã            $       ó"  — d dl Z d dlZd dlmZmZmZ d dlmZmZm	Z	m
Z
mZmZ d dlmZmZmZ d dlmZmZmZmZmZ d dlmZmZmZmZ d dlmZ d dlmZm Z  d d	l!m"Z" d d
l#m$Z$m%Z% d dl&m'Z'm(Z( d dl)m*Z* d dl+m,Z, d dl-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5 d dl6m7Z7 d dl8m9Z9 d dl:m;Z; d dl<m=Z=m>Z>m?Z? d dl@mAZAmBZB eCe;z  ZDeCeEe;   z  ZF e?de9¬«       G d„ de>«      «       ZG e?de9¬«       G d„ de;«      «       ZH ej’                  «       5   ej”                  de9d¬ «        e?d!e9¬«       G d"„ d#eG«      «       ZKddd«        ej’                  «       5   ej”                  de9d¬ «        e?d$e9¬«       G d%„ d&eH«      «       ZLddd«        ej’                  «       5   ej”                  de9¬«        e
d'eGeHz  ¬(«      ZMeEeM   ZNddd«       d)ZOeePz  eeMgef   z  eeMef   z  ZQdLd*eMd+ePd,ed-efd.„ZRd/eQdz  d-efd0„ZS	 dMd1ed2ee   d3eTd-eUfd4„ZVd1ed-efd5„ZWd6ee   d-dfd7„ZX e?d8e9¬«      ddddddddddd9d:dd;œd1ePez  eeMe0e7   gef   z  eeMe0e7   gee   f   z  eeMe0e7   geeef   f   z  eeMe0e7   geeeef      f   z  d2eeez  eCePef   z     eBz  d/eQdz  d<eFeYePeFf   z  dz  d=e dz  d>e dz  d?eNdz  d@eEe   dz  dAe4dz  dBe2dz  dCeZeP   dz  dDeZeP   dz  dEeUdFe	dG   dHePdz  dIed-e,f"dJ„«       Z[e[Z\g dK¢Z]y# 1 sw Y   �Œ»xY w# 1 sw Y   �Œ�xY w# 1 sw Y   �ŒNxY w)Né    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                   ó<   — e Zd ZU dZeee   ef   ed<   e	e
   ed<   y)Ú
AgentStateúThe state of the agent.ÚmessagesÚremaining_stepsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    Ú__annotations__r*   r"   © ó    úc/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/langgraph/prebuilt/chat_agent_executor.pyr2   r2   5   s'   … ñ
 "à˜ Ñ-¨|Ð;Ñ<Ó<à  Ñ0Ô0r<   r2   zTAgentStatePydantic has been deprecated in favor of AgentState in `langchain.agents`.c                   ó:   — e Zd ZU dZeee   ef   ed<   dZ	e
ed<   y)ÚAgentStatePydanticr3   r4   é   r5   N)r6   r7   r8   r9   r   r   r   r    r:   r5   r"   r;   r<   r=   r?   r?   A   s&   … ñ
 "à˜ Ñ-¨|Ð;Ñ<Ó<à&(€O�^Ô(r<   r?   Úignorez1AgentState has been moved to `langchain.agents`.*)r0   ÚmessagezbAgentStateWithStructuredResponse has been deprecated in favor of AgentState in `langchain.agents`.c                   ó   — e Zd ZU dZeed<   y)Ú AgentStateWithStructuredResponseú2The state of the agent with a structured response.Ústructured_responseN©r6   r7   r8   r9   ÚStructuredResponser:   r;   r<   r=   rD   rD   T   ó   … ñ
 	Aà/Ô/r<   rD   zjAgentStateWithStructuredResponsePydantic has been deprecated in favor of AgentState in `langchain.agents`.c                   ó   — e Zd ZU dZeed<   y)Ú(AgentStateWithStructuredResponsePydanticrE   rF   NrG   r;   r<   r=   rK   rK   e   rI   r<   rK   ÚStateSchema)ÚboundÚPromptÚstateÚkeyÚdefaultÚreturnc                 ó`   — t        | t        «      r| j                  ||«      S t        | ||«      S ©N)Ú
isinstanceÚdictÚgetÚgetattr)rO   rP   rQ   s      r=   Ú_get_state_valuerY   �   s6   € ô �eœTÔ"ð 	�	‰	�#�wÓðô �U˜C Ó)ðr<   Úpromptc                 óÆ  ‡ ‡— ‰ €t        d„ t        ¬«      }|S t        ‰ t        «      r"t	        ‰ ¬«      Št        ˆfd„t        ¬«      }|S t        ‰ t        «      rt        ˆ fd„t        ¬«      }|S t        j                  ‰ «      rt        d ‰ t        ¬«      }|S t        ‰ «      rt        ‰ t        ¬«      }|S t        ‰ t        «      r‰ }|S t        dt        ‰ «      › �«      ‚)Nc                 ó   — t        | d«      S ©Nr4   ©rY   )rO   s    r=   Ú<lambda>z&_get_prompt_runnable.<locals>.<lambda>�   s   € Ô*¨5°*Ô=r<   ©Úname©Úcontentc                 ó$   •— ‰gt        | d«      z   S r]   r^   )rO   Ú_system_messages    €r=   r_   z&_get_prompt_runnable.<locals>.<lambda>’   s   ø€ ˜?Ð+Ô.>¸uÀjÓ.QÒQr<   c                 ó$   •— ‰gt        | d«      z   S r]   r^   )rO   rZ   s    €r=   r_   z&_get_prompt_runnable.<locals>.<lambda>—   s   ø€ ˜6˜(Ô%5°e¸ZÓ%HÒHr<   z"Got unexpected type for `prompt`: )r   ÚPROMPT_RUNNABLE_NAMErU   Ústrr   ÚinspectÚiscoroutinefunctionÚcallabler   Ú
ValueErrorÚtype)rZ   Úprompt_runnablere   s   ` @r=   Ú_get_prompt_runnablero   ‰   sñ   ù€ à€~Ü*Ù=ÔDXô
ˆð< Ðô7 
�FœCÔ	 Ü'4¸VÔ'DˆÜ*ÛQÜ%ô
ˆð2 Ðô+ 
�FœMÔ	*Ü*ÛHÜ%ô
ˆð( Ðô! 
×	$Ñ	$ VÔ	,Ü*ØØÜ%ô
ˆð Ðô 
�&Ô	Ü*ØÜ%ô
ˆð Ðô 
�FœHÔ	%Ø ˆð Ðô Ð=¼dÀ6»l¸^ÐLÓMÐMr<   ÚmodelÚtoolsÚnum_builtinc                 ó:  — t        | t        «      rt        d„ | j                  D «       | «      } t        | t        «      syd| j
                  vry| j
                  d   }t        |«      t        |«      |z
  k7  r&t        dt        |«      › dt        |«      |z
  › �«      ‚t        d„ |D «       «      }t        «       }|D ]H  }|j                  d«      dk(  r	|d   d	   }n|j                  d	«      r|d	   }nŒ8|j                  |«       ŒJ ||z
  x}rt        d
|› d�«      ‚y)Nc              3   óL   K  — | ]  }t        |t        t        f«      r|–— Œ y ­wrT   ©rU   r   r   ©Ú.0Ústeps     r=   Ú	<genexpr>z%_should_bind_tools.<locals>.<genexpr>²   ó'   è ø€ ð á'�DÜ˜d¤_´mÐ$DÔEô Ù'ùó   ‚"$Trq   z`Number of tools in the model.bind_tools() and tools passed to create_react_agent must match Got z tools, expected c              3   ó4   K  — | ]  }|j                   –— Œ y ­wrT   r`   )rw   Útools     r=   ry   z%_should_bind_tools.<locals>.<genexpr>Ç   s   è ø€ Ð1©5 4�T—Y•Y©5ùs   ‚rm   Úfunctionra   zMissing tools 'z' in the model.bind_tools()F)rU   r   ÚnextÚstepsr   ÚkwargsÚlenrl   ÚsetrW   Úadd)	rp   rq   rr   Úbound_toolsÚ
tool_namesÚbound_tool_namesÚ
bound_toolÚbound_tool_nameÚmissing_toolss	            r=   Ú_should_bind_toolsr‹   ­   s<  € ô �%Ô)Ô*Üñà!ŸKšKóð
 ó
ˆô �eœ_Ô-Øà�e—l‘lÑ"Øà—,‘,˜wÑ'€KÜ
ˆ5ƒz”S˜Ó%¨Ñ3Ò3ÜðÜ˜“J�<Ð0´°[Ó1AÀKÑ1OÐ0PðRó
ð 	
ô
 Ñ1©5Ó1Ó1€JÜ“uÐÛ!ˆ
à�>‰>˜&Ó! ZÒ/Ø(¨Ñ4°VÑ<‰Oà�^‰^˜FÔ#Ø(¨Ñ0‰Oð à×Ñ˜_Õ-ð "ð #Ð%5Ñ5Ð5€}Ð5Ü˜?¨=¨/Ð9TÐUÓVÐVàr<   c                 óæ   — t        | t        «      rt        d„ | j                  D «       | «      } t        | t        «      r| j
                  } t        | t        «      st        dt        | «      › �«      ‚| S )zKGet the underlying model from a RunnableBinding or return the model itself.c              3   óL   K  — | ]  }t        |t        t        f«      r|–— Œ y ­wrT   ru   rv   s     r=   ry   z_get_model.<locals>.<genexpr>à   rz   r{   zXExpected `model` to be a ChatModel or RunnableBinding (e.g. model.bind_tools(...)), got )	rU   r   r   r€   r   rM   r   Ú	TypeErrorrm   )rp   s    r=   Ú
_get_modelr�   Ü   sr   € ä�%Ô)Ô*Üñà!ŸKšKóð
 ó
ˆô �%œÔ)Ø—‘ˆä�eœ]Ô+ÜØfÔgkÐlqÓgrÐfsÐtó
ð 	
ð €Lr<   r4   c                 óf  — | D ��cg c]%  }t        |t        «      r|j                  D ]  }|‘Œ Œ' }}}| D �ch c]  }t        |t        «      sŒ|j                  ’Œ! }}|D �cg c]  }|d   |vr|‘Œ }}|syt        d|dd › d�t        j                  ¬«      }t        |«      ‚c c}}w c c}w c c}w )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.)rB   Ú
error_code)	rU   r   Ú
tool_callsr   Útool_call_idr   r   ÚINVALID_CHAT_HISTORYrl   )r4   rB   Ú	tool_callÚall_tool_callsÚtool_call_ids_with_resultsÚtool_calls_without_resultsÚerror_messages          r=   Ú_validate_chat_historyrœ   ó   sù   € ñ  ôáˆGÜ�gœyÔ)Ø ×+Ô+ˆIò 	ð ,ð 	Øð ñ ñ -5ó"Ù,4 ¼
À7ÌKÕ8Xˆ×Ó¨Hð ð "ñ
 (ó"á'ˆIØ�T‰?Ð"<Ñ<ò 	Ø'ð ð "ñ
 &Øä(ð7Ø7QÐRTÐSTÐ7UÐ6Vð Wgðgô ×1Ñ1ô€Mô �]Ó
#Ð#ùó1ùò"ùò"s   †*B#·B)ÁB)Á!B.z‚create_react_agent has been moved to `langchain.agents`. Please update your import to `from langchain.agents import create_agent`.FÚv2)rZ   Úresponse_formatÚpre_model_hookÚpost_model_hookÚstate_schemaÚcontext_schemaÚcheckpointerÚstoreÚinterrupt_beforeÚinterrupt_afterÚdebugÚversionra   rž   rŸ   r    r¡   r¢   r£   r¤   r¥   r¦   r§   r¨   ©Úv1r�   ra   Údeprecated_kwargsc          	      óî  ‡ ‡‡‡‡‡‡‡‡'‡(‡)‡*‡+‡,‡-‡.‡/— |j                  dt        «      x}t        urt        j                  dt        ¬«       |€|}t        |«      dkD  rt        d|› �«      ‚‰dvrt        d‰› d	�«      ‚‰�Jd
dh}‰�|j                  d«       t        t        ‰«      «      }|t        |«      z
  x}rt        d|› d�«      ‚‰€‰�t        nt        Šg }t        |t        «      r&t        |j                   j#                  «       «      }|}nm|D �cg c]  }t        |t$        «      sŒ|‘Œ }}t        |D �cg c]  }t        |t$        «      rŒ|‘Œ c}«      }t        |j                   j#                  «       «      }t        ‰ t&        t(        f«       xr t+        ‰ «      Š-‰-xr t-        j.                  ‰ «      Š,t        |«      dkD  }‰-s†t        ‰ t&        «      r	 ddlm} t7        t8         |‰ «      «      Š t;        ‰ |t        |«      ¬«      r3t        ||z   «      dkD  r"t7        t8        ‰ «      j=                  ||z   «      Š t?        ‰«      ‰ z  Š/ndŠ/|D �ch c]  }|j@                  sŒ|jB                  ’Œ c}Š.dtD        dtF        tH           dtJ        fˆ-ˆ ˆˆ/fd„Š*dtD        dtF        tH           dtJ        fˆ,ˆ-ˆ ˆˆ/fd„Š(dtD        dtL        dtN        fˆ.fd„Š'dtD        dtD        fˆˆfd„Š)dtD        dtF        tH           dtP        dtD        fˆ'ˆ)ˆ*ˆ,ˆ-ˆˆ/fd„}dtD        dtF        tH           dtP        dtD        fˆ'ˆ(ˆ)ˆ-ˆˆ/fd„}‰�Mt        ‰tR        «      r/tU        ‰tV        «      rddl,m-}  |dt        t\           df‰¬ «      }n G d!„ d‰«      }|}n‰}dtD        dtF        tH           dtP        dtD        fˆ*ˆ,ˆfd"„}dtD        dtF        tH           dtP        dtD        fˆ(ˆfd#„} |sét_        ‰|¬$«      }!|!ja                  d%tc        ||«      |¬&«       ‰�'|!ja                  d'‰«       |!je                  d'd%«       d'Š+nd%Š+|!jg                  ‰+«       ‰�$|!ja                  d(‰«       |!je                  d%d(«       ‰�C|!ja                  d)tc        || «      «       ‰�|!je                  d(d)«       n|!je                  d%d)«       |!ji                  ||	|
||‰¬*«      S dtD        dt&        t        tj           z  fˆˆˆfd+„}"t_        ‰xs t        |¬$«      }!|!ja                  d%tc        ||«      |¬&«       |!ja                  d,|«       ‰�'|!ja                  d'‰«       |!je                  d'd%«       d'Š+nd%Š+|!jg                  ‰+«       g }#‰+d,g}$‰�6|!ja                  d(‰«       |#jm                  d(«       |!je                  d%d(«       n|#jm                  d,«       ‰�B|!ja                  d)tc        || «      «       ‰�|$jm                  d)«       n?|#jm                  d)«       n-‰�|$jm                  tn        «       n|#jm                  tn        «       ‰�5dtD        dt&        t        tj           z  fˆ+ˆfd-„}%|!jq                  d(|%|$¬.«       |!jq                  d%|"|#¬.«       dtD        dt&        fˆ+ˆ.fd/„}&‰.r|!jq                  d,|&‰+tn        g¬.«       n|!je                  d,‰+«       |!ji                  ||	|
||‰¬*«      S c c}w c c}w # t4        $ r t5        d«      ‚w xY wc c}w )0a*  Creates an agent graph that calls tools in a loop until a stopping condition is met.

    !!! warning

        This function is deprecated in favor of
        [`create_agent`][langchain.agents.create_agent] from the `langchain`
        package, which provides an equivalent agent factory with a flexible
        middleware system. For migration guidance, see
        [Migrating from LangGraph v0](https://docs.langchain.com/oss/python/migrate/langgraph-v1).

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

            - **Static model**: A chat model instance (e.g.,
                [`ChatOpenAI`][langchain_openai.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.

            !!! example "Dynamic model"

                ```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,
            - 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'.r4   r5   rF   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.)rr   rO   ÚruntimerR   c                 ó6   •— ‰rt        ‰«       ‰| |«      z  S ‰S )zBResolve the model to use, handling both static and dynamic models.©ro   )rO   r¯   Úis_dynamic_modelrp   rZ   Ústatic_models     €€€€r=   Ú_resolve_modelz*create_react_agent.<locals>._resolve_modelW  s%   ø€ ñ Ü'¨Ó/±%¸¸wÓ2GÑGÐGàÐr<   c              “   ó„   •K  — ‰r ‰| |«      ƒ d{  –—† }t        ‰«      |z  S ‰rt        ‰«       ‰| |«      z  S ‰S 7 Œ+­w)zHAsync resolve the model to use, handling both static and dynamic models.Nr±   )rO   r¯   Úresolved_modelÚis_async_dynamic_modelr²   rp   rZ   r³   s      €€€€€r=   Ú_aresolve_modelz+create_react_agent.<locals>._aresolve_model`  sP   øè ø€ ñ "Ù#(¨°Ó#8×8ˆNÜ'¨Ó/°.Ñ@Ð@ÙÜ'¨Ó/±%¸¸wÓ2GÑGÐGàÐð 9ús   ƒA ’>“,A Úresponsec                 óà   •— t        |t        «      xr |j                  }t        |t        «      rt        ˆfd„|j                  D «       «      nd}t	        | dd «      }|�|dk  r|ry|dk  r|ryy)Nc              3   ó,   •K  — | ]  }|d    ‰v –— Œ y­w©ra   Nr;   ©rw   ÚcallÚshould_return_directs     €r=   ry   zEcreate_react_agent.<locals>._are_more_steps_needed.<locals>.<genexpr>o  s   øè ø€ ÐUÑAT¸��V‘Ð 4Ô4ÑATùó   ƒFr5   é   Té   )rU   r   r”   ÚallrY   )rO   r¹   Úhas_tool_callsÚall_tools_return_directr5   r¿   s        €r=   Ú_are_more_steps_neededz2create_react_agent.<locals>._are_more_steps_neededl  sy   ø€ Ü# H¬iÓ8ÒP¸X×=PÑ=Pˆô ˜(¤IÔ.ô ÓUÀ×ATÒATÓUÔUàð 	 ô
 +¨5Ð2CÀTÓJˆØÐ&Ø Ò"Ñ'>ØØ  1Ò$©Øàr<   c                 óú   •— ‰� t        | d«      xs t        | d«      }d| › �}nt        | d«      }d| › �}|€t        |«      ‚t        |«       t        ‰t        «      rt        ‰t        «      r	|| _        | S || d<   | S )NÚllm_input_messagesr4   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 )rY   rl   rœ   rU   rm   Ú
issubclassr)   r4   )rO   r4   Ú	error_msgrŸ   r¡   s      €€r=   Ú_get_model_input_statez2create_react_agent.<locals>._get_model_input_state|  s¢   ø€ ØÐ%ä  Ð(<Ó=ò5ä! %¨Ó4ð ð pÐpuÐovÐw‰Iä'¨¨zÓ:ˆHàOÐPUÈwÐWð ð ÐÜ˜YÓ'Ð'ä˜xÔ(ä�l¤DÔ)¬j¸ÄyÔ.QØ%ˆEŒNð ˆð !)ˆE�*Ñàˆr<   Úconfigc                 ó(  •— ‰
rd}t        |«      ‚ ‰| «      }‰r* ‰	| |«      }t        t        |j                  ||«      «      }n t        t        ‰j                  ||«      «      }‰|_         ‰| |«      rdt        |j
                  d¬«      giS d|giS )NúˆAsync model callable provided but agent invoked synchronously. Use agent.ainvoke() or agent.astream(), or provide a sync model callable.r4   ú/Sorry, need more steps to process this request.©r‘   rc   )ÚRuntimeErrorr
   r   Úinvokera   r‘   )rO   r¯   rÌ   ÚmsgÚmodel_inputÚdynamic_modelr¹   rÆ   rË   r´   r·   r²   ra   r³   s          €€€€€€€r=   Ú
call_modelz&create_react_agent.<locals>.call_model•  s°   ø€ ñ "ð1ð ô
 ˜sÓ#Ð#á,¨UÓ3ˆáá*¨5°'Ó:ˆMÜœI }×';Ñ';¸KÈÓ'PÓQ‰HäœI |×':Ñ':¸;ÈÓ'OÓPˆHð ˆŒá! %¨Ô2àÜØ#Ÿ;™;Ø Qôððð ð ˜X˜JÐ'Ð'r<   c              “   óN  •K  —  ‰| «      }‰	r: ‰| |«      ƒ d {  –—† }t        t        |j                  ||«      ƒ d {  –—† «      }n(t        t        ‰j                  ||«      ƒ d {  –—† «      }‰
|_         ‰| |«      rdt        |j                  d¬«      giS d|giS 7 Œ„7 Œb7 Œ;­w)Nr4   rÏ   rÐ   )r
   r   Úainvokera   r‘   )rO   r¯   rÌ   rÔ   rÕ   r¹   rÆ   r¸   rË   r²   ra   r³   s         €€€€€€r=   Úacall_modelz'create_react_agent.<locals>.acall_model¸  s´   øè ø€ ñ -¨UÓ3ˆáñ #2°%¸Ó"A×AˆMÜœI¨]×-BÑ-BÀ;ÐPVÓ-W×'WÓX‰HäœI¨\×-AÑ-AÀ+ÈvÓ-V×'VÓWˆHð ˆŒÙ! %¨Ô2àÜØ#Ÿ;™;Ø Qôððð ð ˜X˜JÐ'Ð'ð# BøØ'Wøà'Vús1   ƒB%šB›#B%¾B!
¿(B%Á'B#
Á(8B%Â!B%Â#B%)Úcreate_modelÚCallModelInputSchema.)rÈ   Ú__base__c                   ó   — e Zd ZU ee   ed<   y)ú0create_react_agent.<locals>.CallModelInputSchemarÈ   N)r6   r7   r8   Úlistr   r:   r;   r<   r=   rÛ   rÞ   á  s   … Ø$(¨Ñ$4Ô4r<   c                 ó(  •— ‰rd}t        |«      ‚t        | d«      }‰}t        ‰t        «      r‰\  }}t	        |¬«      gt        |«      z   } ‰
| |«      }t        |«      j                  t        t        |«      «      }|j                  ||«      }	d|	iS )NrÎ   r4   rb   rF   )rÑ   rY   rU   Útupler   rß   r�   Úwith_structured_outputr
   ÚStructuredResponseSchemarÒ   )rO   r¯   rÌ   rÓ   r4   Ústructured_response_schemaÚsystem_promptr¶   Úmodel_with_structured_outputr¹   r´   r·   rž   s             €€€r=   Úgenerate_structured_responsez8create_react_agent.<locals>.generate_structured_responseè  s¯   ø€ ñ "ð\ð ô ˜sÓ#Ð#ä# E¨:Ó6ˆØ%4Ð"Ü�o¤uÔ-Ø8GÑ5ˆMÐ5Ü%¨mÔ<Ð=ÄÀXÃÑNˆHá'¨¨wÓ7ˆÜ'1Øó(
ç
 Ñ
 ÜÔ)Ð+EÓFó
ð 	%ð
 0×6Ñ6°xÀÓHˆØ% xÐ0Ð0r<   c              “   ó:  •K  — t        | d«      }‰
}t        ‰
t        «      r‰
\  }}t        |¬«      gt	        |«      z   } ‰	| |«      ƒ d {  –—† }t        |«      j                  t        t        |«      «      }|j                  ||«      ƒ d {  –—† }d|iS 7 ŒJ7 Œ
­w)Nr4   rb   rF   )
rY   rU   rá   r   rß   r�   râ   r
   rã   rØ   )rO   r¯   rÌ   r4   rä   rå   r¶   ræ   r¹   r¸   rž   s            €€r=   Úagenerate_structured_responsez9create_react_agent.<locals>.agenerate_structured_response  sª   øè ø€ ô $ E¨:Ó6ˆØ%4Ð"Ü�o¤uÔ-Ø8GÑ5ˆMÐ5Ü%¨mÔ<Ð=ÄÀXÃÑNˆHá.¨u°gÓ>×>ˆÜ'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§   ra   c                 óþ   •— t        | d«      }|d   }t        |t        «      r|j                  s‰�y‰�yt        S ‰dk(  ry‰dk(  r3‰�y|j                  D �cg c]  }t        dt        d|| ¬	«      «      ‘Œ c}S y c c}w )
Nr4   éÿÿÿÿr    rç   rª   rq   r�   Útool_call_with_context©Ú__typer—   rO   )rY   rU   r   r”   r   r&   r-   )rO   r4   Úlast_messager¾   r    rž   r¨   s       €€€r=   Úshould_continuez+create_react_agent.<locals>.should_continue?  s¬   ø€ Ü# E¨:Ó6ˆØ ‘|ˆä˜,¬	Ô2¸,×:QÒ:QØÐ*Ø(Ø Ð,Ø5ä�
ð ˜$ŠØØ˜D’Ø"Ð.Ø,ð !-× 7Ò 7ó
ñ !8˜ô ØÜ+Ø#;Ø&*Ø"'ôõð !8ñ
ð 
ð !ùò
s   ÁA:rq   c                 ó’  •— t        | d«      }|D �cg c]  }t        |t        «      sŒ|j                  ‘Œ! }}t	        d„ t        |«      D «       «      }|j                  D �cg c]  }|d   |vsŒ|‘Œ }}|r&|D �cg c]  }t        dt        d|| ¬«      «      ‘Œ c}S t        |d   t        «      r‰S ‰	�yt        S c c}w c c}w c c}w )	aw  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.
            r4   c              3   óB   K  — | ]  }t        |t        «      sŒ|–— Œ y ­wrT   )rU   r   )rw   Úms     r=   ry   zEcreate_react_agent.<locals>.post_model_hook_router.<locals>.<genexpr>¤  s   è ø€ ð #Ù-�a´¸A¼yÕ1I”Ñ-ùs   ‚˜r‘   rq   rî   rï   rí   rç   )
rY   rU   r   r•   r   Úreversedr”   r&   r-   r   )
rO   r4   rõ   Útool_messagesÚlast_ai_messageÚcÚpending_tool_callsr¾   Ú
entrypointrž   s
           €€r=   Úpost_model_hook_routerz2create_react_agent.<locals>.post_model_hook_router—  sÿ   ø€ ô (¨¨zÓ:ˆHá(0óÙ(0 1´J¸qÄ+Õ4N�—“¨ð ð ô #ñ #Ü# HÔ-ó#ó ˆOð +×5Ò5ó"Ù5�a¸¸4¹ÈÒ9U’Ð5ð ð "ñ "ñ !3ó
ñ !3˜ô ØÜ+Ø#;Ø&*Ø"'ôõð !3ñ
ð 
ô ˜H R™L¬+Ô6Ø!Ð!Ø Ð,Ø5ä�
ùò7ùò"ùò

s   ’B:¨B:Á!B?Á.B?Á:C)Úpath_mapc                 ó  •— t        t        | d«      «      D ]*  }t        |t        «      s n|j                  ‰v sŒ$t
        c S  t        t        «      r0|j                  r$t        ˆfd„|j                  D «       «      rt
        S ‰S )Nr4   c              3   ó,   •K  — | ]  }|d    ‰v –— Œ y­wr¼   r;   r½   s     €r=   ry   zCcreate_react_agent.<locals>.route_tool_responses.<locals>.<genexpr>Ô  s   øè ø€ ÐQÁL¸D�4˜‘<Ð#7Ô7ÁLùrÀ   )	rö   rY   rU   r   ra   r   r   r”   Úany)rO   rõ   rû   r¿   s     €€r=   Úroute_tool_responsesz0create_react_agent.<locals>.route_tool_responsesÊ  sh   ø€ ÜÔ*¨5°*Ó=Ö>ˆAÜ˜a¤Ô-ÙØ�v‰vÐ-Ò-Ü’
ð	 ?ô �aœÔ#¨¯ªÜÓQÀAÇLÂLÓQÔQÜ�
àÐr<   )9Úpopr   ÚwarningsÚwarnr(   r‚   rŽ   rl   r„   rƒ   r   rD   r2   rU   r.   rß   Útools_by_nameÚvaluesrV   rh   r   rk   ri   rj   Úlangchain.chat_modelsr®   ÚImportErrorr
   r   r‹   Ú
bind_toolsro   Úreturn_directra   rL   r#   r'   r   r   Úboolr   rm   rÉ   r)   ÚpydanticrÚ   r   r   Úadd_noder   Úadd_edgeÚset_entry_pointÚcompiler&   Úappendr   Úadd_conditional_edges)0rp   rq   rZ   rž   rŸ   r    r¡   r¢   r£   r¤   r¥   r¦   r§   r¨   ra   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_agentr    s˜  ÿÿø€ ðh +×.Ñ.¨ÄÓHÐHˆÜñô 	�‰ØeÜ0õ	
ð
 Ð!Ø*ˆNä
ÐÓ Ò!ÜØEÐFWÐEXÐYó
ð 	
ð �lÑ"ÜØ˜w˜iÐ'NÐOó
ð 	
ð ÐØ#Ð%6Ð7ˆØÐ&Ø×ÑÐ3Ô4äœ.¨Ó6Ó7ˆØ(¬3¨{Ó+;Ñ;Ð;ˆ<Ð;ÜÐ7¸°~ÐEUÐVÓWÐWàÐð Ð*õ -äð 	ð %'ÐÜ�%œÔ"Ü˜E×/Ñ/×6Ñ6Ó8Ó9ˆØ‰	á(-ÓE© 1´¸A¼tÕ1DšQ¨ÐÐEÜ©ÓJ© A´jÀÄDÕ6Iša¨ÑJÓKˆ	Ü˜I×3Ñ3×:Ñ:Ó<Ó=ˆä% e¬c´8¨_Ó=Ð=ÒQÄ(È5Ã/ÐØ-ÒT´'×2MÑ2MÈeÓ2TÐä˜|Ó,¨qÑ0ÐáÜ�eœSÔ!ðõô œ©¸Ó(>Ó?ˆEô ˜u lÄÐDUÓ@VÕWÜ�LÐ#4Ñ4Ó5¸Ò9äœ¨Ó.×9Ñ9ØÐ0Ñ0óˆEô )=¸VÓ(DÀuÑ(L‰ð ˆñ -9ÓL©L q¸A¿O»O˜AŸF›F¨LÑLÐð Üð Ü%,¬XÑ%6ð ä	÷ ð  ð
 Üð
 Ü%,¬XÑ%6ð
 ä	÷
 ñ 
 ð¤kð ¼[ð ÌTõ ð ¤kð ´kö ð2!(Üð!(Ü%,¬XÑ%6ð!(Ü@Nð!(ä	÷!(ó !(ðF(Üð(Ü%,¬XÑ%6ð(Ü@Nð(ä	÷(ò (ð8 Ð!ä�l¤DÔ)¬j¸ÄyÔ.Qå-á'Ø&Ü$(¬Ñ$4°cÐ#:Ø%ô‰Lô5 |ô 5ð 0‰Là#ˆð1Üð1Ü%,¬XÑ%6ð1Ü@Nð1ä	÷1ð21Üð1Ü%,¬XÑ%6ð1Ü@Nð1ä	ö1ñ$  ä¨<ÈÔWˆØ×ÑØÜ˜Z¨Ó5Ø%ð 	ô 	
ð
 Ð%Ø×ÑÐ.°Ô?Ø×ÑÐ.°Ô8Ø)‰Jà ˆJà× Ñ  Ô,àÐ&Ø×ÑÐ/°ÔAØ×Ñ˜gÐ'8Ô9àÐ&Ø×ÑØ.Ü Ø0Ø1óôð Ð*Ø×!Ñ!Ð"3Ð5SÕTà×!Ñ! 'Ð+IÔJà×ÑØ%ØØ-Ø+ØØð  ó 
ð 	
ðœ{ð ¬s´T¼$±ZÑ/?÷ ô> Ø!Ò/¤ZÀô€Hð
 ×ÑØÜ˜ [Ó1Ø!ð ô ð
 ×Ñ�g˜yÔ)ð Ð!Ø×ÑÐ*¨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   Ä[Ä,[Ä;[Å[Ç[ É[2É*[2Û[/)r  Úcreate_tool_calling_executorr2   r?   rD   rK   rT   )r   )^ri   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.   rV   rH   rm   rã   r2   r?   Úcatch_warningsÚfilterwarningsrD   rK   rL   ÚStateSchemaTyperg   rh   rN   rY   ro   Úintr  r‹   r�   rœ   rá   rß   r  r  Ú__all__r;   r<   r=   Ú<module>r9     sø  ðÛ Û ß 9Ñ 9÷÷ ÷ñ ÷
õ ÷ó õ *ß HÝ /ß <ß +Ý 0Ý 4Ý ,Ý %Ý *ß .Ý %Ý :Ý ß @Ñ @ç Fà˜IÑ%Ð Ø $ y¡/Ñ1Ð ñ Ø~Ø(ôô1�ó 1ó	ð1ñ ØZØ(ôô)˜ó )ó	ð)ð €X×ÑÕØ€H×ÑØØ,ØCõñ ØlØ,ôô0¨:ó 0ó	ð0÷ ð" €X×ÑÕØ€H×ÑØØ,Øfõñ ØtØ,ôô0Ð3Eó 0ó	ð0÷ ð" €X×ÑÕØ€H×ÑØØ,õñ ˜-¨zÐ<NÑ/NÔO€KØ˜;Ñ'€O÷ ð  Ð ð Ø	ñ
à�ˆ}Ð0Ð0Ñ1ñ2ð ˆ{Ð.Ð.Ñ/ñ0ð ñ˜Kð ¨cð ¸Cð È3ó ð! ¨$¡ð !°8ó !ðJ MNñ,Øð,Ø%-¨hÑ%7ð,ØFIð,à	ó,ð^Ð'ð ¨Mó ð.$Ø�{Ñ#ð$à	ó$ñ> ð IØ(ôð$ !ð Ø*.Ø+/Ø+/Ø'+Ø(,Ø"Ø)-Ø(,ØØ#'Øò9TØØñà�˜W XÑ.Ð/°Ð>Ñ?ñ@ð �˜W XÑ.Ð/°¸=Ñ1IÐIÑJñKð Ø	�g˜hÑ'Ð(¨(Ð3EÀ{Ð3RÑ*SÐSññ	ð Ø	�g˜hÑ'Ð(Ø�(Ð-¨{Ð:Ñ;Ñ<ð	>ññ
ðTð �H˜xÑ'¨$¨s°C¨x©.Ñ8Ñ9¸HÑDðTð �T‰MðTð .ØˆCÐ)Ð)Ñ*ñ+à
ñðTð$ ! 4Ñ'ð%Tð& " DÑ(ð'Tð( " DÑ(ð)Tð* ˜‘I Ñ$ð+Tð,  Ñ%ð-Tð. �tÑð/Tð0 ˜3‘i $Ñ&ð1Tð2 ˜#‘Y Ñ%ð3Tð4 ð5Tð6 �ZÑ ð7Tð8 �‰*ð9Tð: ð;Tð< ò=Tó	ðTðp  2Ð ò�÷G Ñú÷" Ñú÷" Ñús$   Ä.K*Å
.K7Æ'LË*K4Ë7LÌL