
    @'hY              
          d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZmZ d dlmZ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mZ d d	lm Z! d d
l"m#Z# d dl$m%Z% d dl&m'Z'm(Z(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2 dZ3dZ4dedee5e6e7   f   fdZ8de9dee:e5e	de5f   e;e<e9   df   f   de5fdZ=de	de5f   de;e<e9   df   fdZ> G d de2      Z?	 d,dee6e   e7e5ef   e%f   de5de
d    fd!Z@ G d" d#e      ZA G d$ d%e      ZBd&ed'eeeA   eeB   f   de:fd(ZCd)ede7e5ee5   f   fd*ZDd)edee5   fd+ZEy)-    N)copydeepcopy)replace)
AnyCallableLiteralOptionalSequenceTupleTypeUnioncastget_type_hints)	AIMessage
AnyMessageToolCallToolMessageconvert_to_messages)RunnableConfig)get_config_listget_executor_for_config)BaseToolInjectedToolArg)tool)get_all_basemodel_annotations)	BaseModel)	Annotatedget_args
get_origin)GraphBubbleUp)	BaseStore)CommandSend)RunnableCallablezLError: {requested_tool} is not a valid tool, try one of [{available_tools}].z)Error: {error}
 Please fix your mistakes.outputreturnc           	      4   d}t        | t              r| S t        | t              r>t        | D cg c]'  }t        |t              xr |j                  d      |v ) c}      r| S 	 t        j                  | d      S c c}w # t        $ r t        |       cY S w xY w)N)image	image_urltextjsontypeF)ensure_ascii)	
isinstancestrlistalldictgetr+   dumps	Exception)r%   recognized_content_block_typesxs      c/home/kushmeetdev/Regenta/Chatbot/venv/lib/python3.12/site-packages/langgraph/prebuilt/tool_node.pymsg_content_outputr9   0   s    %K"&#	FD	!c 	
 q$SAEE&M5S$SS	
' 
	::f599	
  	v;	s   ,A;$B   BBeflag.c                    t        |t        t        f      r!t        j	                  t        |             }|S t        |t              r|}|S t        |      r
 ||       }|S t        d|       )N)errorzVGot unexpected type of `handle_tool_error`. Expected bool, str or callable. Received: )	r.   booltupleTOOL_CALL_ERROR_TEMPLATEformatreprr/   callable
ValueError)r:   r;   contents      r8   _handle_tool_errorrF   E   s     $u&*11Q1@ N 
D#	 N 
$q' N	 &&*V-
 	
    handlerc                 @   t        j                  |       }t        |j                  j	                               }|r|d   j
                  dv rt        |      dk(  r|d   }n|d   }t        |       }|j
                  |v rt        |j                        }|t        u rKt        |j                        }t        d |D              rt        |      S t        d|j                   d      ||j
                     }t        |j                   v r|fS t        d| d      t        fS )	Nr   )selfcls      c              3   <   K   | ]  }t        |t                y wN)
issubclassr5   ).0args     r8   	<genexpr>z'_infer_handled_types.<locals>.<genexpr>l   s     Bcz#y1B   zAll types in the error handler error annotation must be Exception types. For example, `def custom_handler(e: Union[ValueError, TypeError])`. Got 'z
' instead.a  Arbitrary types are not supported in the error handler signature. Please annotate the error with either a specific Exception type or a union of Exception types. For example, `def custom_handler(e: ValueError)` or `def custom_handler(e: Union[ValueError, TypeError])`. Got ')inspect	signaturer0   
parametersvaluesnamelenr   r   
annotationr   r   r1   r?   rD   r5   __mro__)rH   sigparamsfirst_param
type_hintsoriginargsexception_types           r8   _infer_handled_typesrd   ]   s*   


G
$C#..'')*F!9>>_,V1A )K )K#G,
z) 6 67F 6 67BTBB ;&$  + 6 67zC  ((8(89NN222&((  ++:7  <rG   c                       e Zd ZU dZd Zeed<   ddddddeee	e
f      dedeee      d	eeee
d
ef   eee   d
f   f   deddf fdZdeee   eeef   ef   dedee   defdZdeee   eeef   ef   dedee   defdZdee   ded   deeeee   eeee   f   f      fdZdeded   dedefdZdeded   dedefdZ deee   eeef   ef   dee   de!ee   ed   f   fdZ"dedee   fdZ#dedeee   eeef   ef   defdZ$dedee   defdZ%dedeee   eeef   ef   dee   defdZ&d ededed   defd!Z' xZ(S )"ToolNodea  A node that runs the tools called in the last AIMessage.

    It can be used either in StateGraph with a "messages" state key (or a custom key passed via ToolNode's 'messages_key').
    If multiple tool calls are requested, they will be run in parallel. The output will be
    a list of ToolMessages, one for each tool call.

    Tool calls can also be passed directly as a list of `ToolCall` dicts.

    Args:
        tools: A sequence of tools that can be invoked by the ToolNode.
        name: The name of the ToolNode in the graph. Defaults to "tools".
        tags: Optional tags to associate with the node. Defaults to None.
        handle_tool_errors: How to handle tool errors raised by tools inside the node. Defaults to True.
            Must be one of the following:

            - True: all errors will be caught and
                a ToolMessage with a default error message (TOOL_CALL_ERROR_TEMPLATE) will be returned.
            - str: all errors will be caught and
                a ToolMessage with the string value of 'handle_tool_errors' will be returned.
            - tuple[type[Exception], ...]: exceptions in the tuple will be caught and
                a ToolMessage with a default error message (TOOL_CALL_ERROR_TEMPLATE) will be returned.
            - Callable[..., str]: exceptions from the signature of the callable will be caught and
                a ToolMessage with the string value of the result of the 'handle_tool_errors' callable will be returned.
            - False: none of the errors raised by the tools will be caught
        messages_key: The state key in the input that contains the list of messages.
            The same key will be used for the output from the ToolNode.
            Defaults to "messages".

    The `ToolNode` is roughly analogous to:

    ```python
    tools_by_name = {tool.name: tool for tool in tools}
    def tool_node(state: dict):
        result = []
        for tool_call in state["messages"][-1].tool_calls:
            tool = tools_by_name[tool_call["name"]]
            observation = tool.invoke(tool_call["args"])
            result.append(ToolMessage(content=observation, tool_call_id=tool_call["id"]))
        return {"messages": result}
    ```

    Tool calls can also be passed directly to a ToolNode. This can be useful when using
    the Send API, e.g., in a conditional edge:

    ```python
    def example_conditional_edge(state: dict) -> List[Send]:
        tool_calls = state["messages"][-1].tool_calls
        # If tools rely on state or store variables (whose values are not generated
        # directly by a model), you can inject them into the tool calls.
        tool_calls = [
            tool_node.inject_tool_args(call, state, store)
            for call in last_message.tool_calls
        ]
        return [Send("tools", [tool_call]) for tool_call in tool_calls]
    ```

    Important:
        - The input state can be one of the following:
            - A dict with a messages key containing a list of messages.
            - A list of messages.
            - A list of tool calls.
        - If operating on a message list, the last message must be an `AIMessage` with
            `tool_calls` populated.
    rY   toolsNTmessages)rY   tagshandle_tool_errorsmessages_keyri   rj   .rk   r&   c                   t         |   | j                  | j                  ||d       i | _        i | _        i | _        || _        || _        |D ]z  }t        |t              st        |      }|| j                  |j                  <   t        |      | j
                  |j                  <   t        |      | j                  |j                  <   | y )NF)rY   ri   trace)super__init___func_afunctools_by_nametool_to_state_argstool_to_store_argrj   rk   r.   r   create_toolrY   _get_state_args_get_store_arg)rJ   rg   rY   ri   rj   rk   tool_	__class__s          r8   ro   zToolNode.__init__   s     	T[[t$eT24GI;="4( 	GEeX.#E*-2Duzz*2A%2HD##EJJ/1?1FD""5::.	GrG   inputconfigstorec                   | j                  ||      \  }}t        |t        |            }|gt        |      z  }t        |      5 }g |j	                  | j
                  |||      }	d d d        | j                  	|      S # 1 sw Y   xY wrO   )_parse_inputr   rZ   r   map_run_one_combine_tool_outputs)
rJ   rz   r{   r|   
tool_calls
input_typeconfig_listinput_typesexecutoroutputss
             r8   rp   zToolNode._func   s     "&!2!25%!@
J%fc*o>!lS_4$V, 	dmmZkRG	
 ))':>>	 	s   !B  B	c                    K    j                  ||      \  }t        j                   fd|D          d {   } j                  |      S 7 w)Nc              3   D   K   | ]  }j                  |        y wrO   )	_arun_one)rQ   callr{   r   rJ   s     r8   rS   z"ToolNode._afunc.<locals>.<genexpr>  s     N4dnnT:v6Ns    )r~   asynciogatherr   )rJ   rz   r{   r|   r   r   r   s   ` `   @r8   rq   zToolNode._afunc   sU      "&!2!25%!@
JN:N
 
 ))':>>	
s   6AAAr   r   )r0   r2   r   c                    t        d |D              s|dk(  r|S | j                  |iS g }d }|D ]  }t        |t              r|j                  t        j
                  u rt        |j                  t              r~t        d |j                  D              rb|r:t        |t        t        t           |j                        |j                  z         }t        t        j
                  |j                        }|j                  |       |j                  |dk(  r|gn| j                  |gi        |r|j                  |       |S )Nc              3   <   K   | ]  }t        |t                y wrO   )r.   r"   )rQ   r%   s     r8   rS   z1ToolNode._combine_tool_outputs.<locals>.<genexpr>  s     E6:fg.ErT   r0   c              3   <   K   | ]  }t        |t                y wrO   )r.   r#   )rQ   sends     r8   rS   z1ToolNode._combine_tool_outputs.<locals>.<genexpr>  s     KtJtT2KrT   )goto)graphr   )anyrk   r.   r"   r   PARENTr   r0   r1   r   r   r#   append)rJ   r   r   combined_outputsparent_commandr%   s         r8   r   zToolNode._combine_tool_outputs  s    EWEE(F27T9J9JG8TT  	
 -1 	F&'*LLGNN2"6;;5Kv{{KK%)0*!%d4j.2E2E!F!T*
 *1w~~FKK)X$++F3 '' *f 4VH4;L;Lvh:W#	* ##N3rG   r   c                    | j                  |      x}r|S 	 i |ddi}| j                  |d      j                  ||      }t        |t              r| j                  |||      S t        |t              r7t        t        t         t"        f   t%        |j&                              |_        |S t)        d|d    d	t+        |             # t        $ r}|d }~wt        $ r}t        | j                  t              r| j                  }n2t        | j                        rt        | j                        }nt        f}| j                  rt        ||      s|t        || j                        }	t        |	|d   |d   d      cY d }~S d }~ww xY w
Nr,   	tool_callrY   )r;   idr=   )rE   rY   tool_call_idstatuszTool z returned unexpected type: )_validate_tool_callrr   invoker    r5   r.   rj   r?   rC   rd   rF   r   r"   _validate_tool_commandr   r   r/   r0   r9   rE   	TypeErrorr,   
rJ   r   r   r{   invalid_tool_messagerz   responser:   handled_typesrE   s
             r8   r   zToolNode._run_one3  s    $(#;#;D#AAA'' 	5t545E))$v,7>>ufMH@ h(..xzJJ+.#c4i "4X5E5E"F H OV~%@h@PQ A  	G 	$1159'+'>'>$112 4T5L5L M "+ ***Q2N -QT5L5LM&\!$Z	 	s*   *C 	FCFBF=FFc                 2  K   | j                  |      x}r|S 	 i |ddi}| j                  |d      j                  ||       d {   }t        |t              r| j                  |||      S t        |t              r7t        t        t         t"        f   t%        |j&                              |_        |S t)        d|d    d	t+        |             7 # t        $ r}|d }~wt        $ r}t        | j                  t              r| j                  }n2t        | j                        rt        | j                        }nt        f}| j                  rt        ||      s|t        || j                        }	t        |	|d   |d   d      cY d }~S d }~ww xY wwr   )r   rr   ainvoker    r5   r.   rj   r?   rC   rd   rF   r   r"   r   r   r   r/   r0   r9   rE   r   r,   r   s
             r8   r   zToolNode._arun_onej  s     $(#;#;D#AAA''!	5t545E!//V=EEeVTTHB h(..xzJJ+.#c4i "4X5E5E"F H OV~%@h@PQ S U  	G 	$1159'+'>'>$112 4T5L5L M "+ ***Q2N -QT5L5LM&\!$Z	 !	sT   F-C CC BFC 	FCF+BF	F
FFFc                    t        |t              r:t        |d   t              r|d   j                  d      dk(  rd}|}||fS d}|d   }nbt        |t              r&|j                  | j                  g       x}rd}|d   }n,t        || j                  d       x}rd}|d   }nt        d      t        |t              st        d      |j                  D cg c]  }| j                  |||       }}||fS c c}w )	Nr,   r   r   r0   r2   zNo message found in inputz Last message is not an AIMessage)
r.   r0   r2   r3   rk   getattrrD   r   r   inject_tool_args)rJ   rz   r|   r   r   messagerh   r   s           r8   r~   zToolNode._parse_input  s    eT"%)T*uRy}}V/D/S)
"
!:--#
&+Bit$eii@Q@QSU6V*V(*VJrlG (9(94@@X@JrlG899'9-?@@ CJBTBT
:>D!!$u5

 
 :%%
s   C6c                     |d   x}| j                   vrPt        j                  |dj                  | j                   j	                                     }t        |||d   d      S y )NrY   , )requested_toolavailable_toolsr   r=   )rY   r   r   )rr    INVALID_TOOL_NAME_ERROR_TEMPLATErA   joinkeysr   )rJ   r   r   rE   s       r8   r   zToolNode._validate_tool_call  sm    "6l*N43E3EE6==- $		$*<*<*A*A*C D > G n4:g  rG   r   c           	         | j                   |d      }|rt        |t              rt        |j                               }t	        |      dk(  r|d   | j
                  k(  s|d   | j
                  |i}nUd|d    d}t        d |j                         D              r!dj                  d |D              }|d	| d
z  }t        |      t        |t              r+|j                         D ci c]  \  }}||r||   n| }	}}n1|j                         D ci c]  \  }}||rt        ||      n| }	}}i |d   |	|d<   |S c c}}w c c}}w )NrY   rM   r   z Invalid input to ToolNode. Tool z$ requires graph state dict as input.c              3       K   | ]  }|  y wrO    )rQ   state_fields     r8   rS   z)ToolNode._inject_state.<locals>.<genexpr>  s     J{{Js   r   c              3   &   K   | ]	  }|s|  y wrO   r   )rQ   fs     r8   rS   z)ToolNode._inject_state.<locals>.<genexpr>  s     3T!RSA3Ts   z State should contain fields .rb   )rs   r.   r0   rX   rZ   rk   r   r   rD   r2   itemsr   )
rJ   r   rz   
state_argsrequired_fieldserr_msgrequired_fields_strtool_argr   tool_state_argss
             r8   _inject_statezToolNode._inject_state  s    ,,Yv->?
*UD1":#4#4#67OO$)#A&$*;*;;"1%-**E2 7y7H6I J1 2  Jj6G6G6IJJ*.))3T3T*T'!>?R>SSTUUG ))eT" .8-=-=-?)Hk %,FO  .8-=-=-?)Hk '%5%OO 



	& s   *EEc                 h    | j                   |d      }|s|S |t        d      i |d   ||i|d<   |S )NrY   zgCannot inject store into tools with InjectedStore annotations - please compile your graph with a store.rb   )rt   rD   )rJ   r   r|   	store_args       r8   _inject_storezToolNode._inject_store  sd     **9V+<=	=: 


u
	& rG   c                     |d   | j                   vr|S t        |      }| j                  ||      }| j                  ||      }|S )at  Injects the state and store into the tool call.

        Tool arguments with types annotated as `InjectedState` and `InjectedStore` are
        ignored in tool schemas for generation purposes. This method injects them into
        tool calls for tool invocation.

        Args:
            tool_call (ToolCall): The tool call to inject state and store into.
            input (Union[list[AnyMessage], dict[str, Any], BaseModel]): The input state
                to inject.
            store (Optional[BaseStore]): The store to inject.

        Returns:
            ToolCall: The tool call with injected state and store.
        rY   )rr   r   r   r   )rJ   r   rz   r|   tool_call_copytool_call_with_statetool_call_with_stores          r8   r   zToolNode.inject_tool_args  sS    2 VD$6$66#'	?#11.%H#112FN##rG   commandc           	         t        |j                  t              r|dvr,t        d| j                   d|j                   d|d    d      t        |      }t        t        t        t        f   |j                        xs i }|j                  | j                  g       }nXt        |j                  t              r<|dk7  rt        d|j                   d|d    d      t        |      }|j                  }n|S t        |      }d	}|D ]2  }t        |t              s|j                  |d
   k(  s'|d   |_        d}4 |j                  #|s!|dk(  rdnd}	t        d|d    d| d|	 d      |S )N)r2   r   zFTools can provide a dict in Command.update only when using dict with 'z' key as ToolNode input, got: z for tool 'rY   'r0   zpTools can provide a list of messages in Command.update only when using list of messages as ToolNode input, got: Fr   Tr2   z]`Command(update={"messages": [ToolMessage("Success", tool_call_id=tool_call_id), ...]}, ...)`zO`Command(update=[ToolMessage("Success", tool_call_id=tool_call_id), ...], ...)`zDExpected to have a matching ToolMessage in Command.update for tool 'z', got: z. Every tool call (LLM requesting to call a tool) in the message history MUST have a corresponding ToolMessage. You can fix it by modifying the tool to return r   )r.   updater2   rD   rk   r   r   r/   r   r3   r0   r   r   r   rY   r   )
rJ   r   r   r   updated_commandstate_updatemessages_updatehas_matching_tool_messager   example_updates
             r8   r   zToolNode._validate_tool_command2  s    gnnd+!77 \]a]n]n\o p#NN+;tF|nAG 
 'w/OS#X0F0FGM2L*..t/@/@"EO-V# #NN+;tF|nAG 
 'w/O-44ON .o>$)!& 	1Gg{3##tDz1#F|,0)	1   (1J ' pf 
 VW[\bWcVddlm|l} ~BBPAQQRT 
 rG   ))__name__
__module____qualname____doc__rY   r/   __annotations__r
   r   r   r   r	   r0   r>   r?   r,   r5   ro   r   r2   r   r   r   r!   rp   rq   r   r   r"   r   r   r   r   r   r~   r   r   r   r   r   __classcell__)ry   s   @r8   rf   rf      sZ   ?B D# $( &Gh012G 	G
 tCy!G "#xS)5i#1E+FF
G G 
G0?cN
? ? 	"? 
?*?cN
? ? 	"? 
?$* k"*  89*  
eGT+.S${:K5K0LLM	N	* X55 895 	5
 
5n66 896 	6
 
6p!&cN
!& 	"!& 
tH~w'CDD	E!&F
 
Xk5J 
++ cN
+ 
+Z!*29*=	&$$ cN
$ 	"$ 
$B66 6 89	6
 
6rG   rf   staterk   )rg   __end__c                    t        | t              r| d   }nMt        | t              r| j                  |g       x}r|d   }n#t	        | |g       x}r|d   }nt        d|        t        |d      rt        |j                        dkD  ryy)aG  Use in the conditional_edge to route to the ToolNode if the last message

    has tool calls. Otherwise, route to the end.

    Args:
        state (Union[list[AnyMessage], dict[str, Any], BaseModel]): The state to check for
            tool calls. Must have a list of messages (MessageGraph) or have the
            "messages" key (StateGraph).

    Returns:
        The next node to route to.


    Examples:
        Create a custom ReAct-style agent with tools.

        ```pycon
        >>> from langchain_anthropic import ChatAnthropic
        >>> from langchain_core.tools import tool
        ...
        >>> from langgraph.graph import StateGraph
        >>> from langgraph.prebuilt import ToolNode, tools_condition
        >>> from langgraph.graph.message import add_messages
        ...
        >>> from typing import Annotated
        >>> from typing_extensions import TypedDict
        ...
        >>> @tool
        >>> def divide(a: float, b: float) -> int:
        ...     """Return a / b."""
        ...     return a / b
        ...
        >>> llm = ChatAnthropic(model="claude-3-haiku-20240307")
        >>> tools = [divide]
        ...
        >>> class State(TypedDict):
        ...     messages: Annotated[list, add_messages]
        >>>
        >>> graph_builder = StateGraph(State)
        >>> graph_builder.add_node("tools", ToolNode(tools))
        >>> graph_builder.add_node("chatbot", lambda state: {"messages":llm.bind_tools(tools).invoke(state['messages'])})
        >>> graph_builder.add_edge("tools", "chatbot")
        >>> graph_builder.add_conditional_edges(
        ...     "chatbot", tools_condition
        ... )
        >>> graph_builder.set_entry_point("chatbot")
        >>> graph = graph_builder.compile()
        >>> graph.invoke({"messages": {"role": "user", "content": "What's 329993 divided by 13662?"}})
        ```
    r   z/No messages found in input state to tool_edge: r   r   rg   r   )	r.   r0   r2   r3   r   rD   hasattrrZ   r   )r   rk   
ai_messagerh   s       r8   tools_conditionr   k  s    l %2Y
	E4	 %))L"2M&Mh&Mb\
UL"5	5	5b\
J5'RSSz<(S1F1F-G!-KrG   c                   (    e Zd ZdZddee   ddfdZy)InjectedStatea  Annotation for a Tool arg that is meant to be populated with the graph state.

    Any Tool argument annotated with InjectedState will be hidden from a tool-calling
    model, so that the model doesn't attempt to generate the argument. If using
    ToolNode, the appropriate graph state field will be automatically injected into
    the model-generated tool args.

    Args:
        field: The key from state to insert. If None, the entire state is expected to
            be passed in.

    Example:
        ```python
        from typing import List
        from typing_extensions import Annotated, TypedDict

        from langchain_core.messages import BaseMessage, AIMessage
        from langchain_core.tools import tool

        from langgraph.prebuilt import InjectedState, ToolNode


        class AgentState(TypedDict):
            messages: List[BaseMessage]
            foo: str

        @tool
        def state_tool(x: int, state: Annotated[dict, InjectedState]) -> str:
            '''Do something with state.'''
            if len(state["messages"]) > 2:
                return state["foo"] + str(x)
            else:
                return "not enough messages"

        @tool
        def foo_tool(x: int, foo: Annotated[str, InjectedState("foo")]) -> str:
            '''Do something else with state.'''
            return foo + str(x + 1)

        node = ToolNode([state_tool, foo_tool])

        tool_call1 = {"name": "state_tool", "args": {"x": 1}, "id": "1", "type": "tool_call"}
        tool_call2 = {"name": "foo_tool", "args": {"x": 1}, "id": "2", "type": "tool_call"}
        state = {
            "messages": [AIMessage("", tool_calls=[tool_call1, tool_call2])],
            "foo": "bar",
        }
        node.invoke(state)
        ```

        ```pycon
        [
            ToolMessage(content='not enough messages', name='state_tool', tool_call_id='1'),
            ToolMessage(content='bar2', name='foo_tool', tool_call_id='2')
        ]
        ```
    Nfieldr&   c                     || _         y rO   )r   )rJ   r   s     r8   ro   zInjectedState.__init__  s	    
rG   rO   )r   r   r   r   r	   r/   ro   r   rG   r8   r   r     s    8thsm t rG   r   c                       e Zd ZdZy)InjectedStorea  Annotation for a Tool arg that is meant to be populated with LangGraph store.

    Any Tool argument annotated with InjectedStore will be hidden from a tool-calling
    model, so that the model doesn't attempt to generate the argument. If using
    ToolNode, the appropriate store field will be automatically injected into
    the model-generated tool args. Note: if a graph is compiled with a store object,
    the store will be automatically propagated to the tools with InjectedStore args
    when using ToolNode.

    !!! Warning
        `InjectedStore` annotation requires `langchain-core >= 0.3.8`

    Example:
        ```python
        from typing import Any
        from typing_extensions import Annotated

        from langchain_core.messages import AIMessage
        from langchain_core.tools import tool

        from langgraph.store.memory import InMemoryStore
        from langgraph.prebuilt import InjectedStore, ToolNode

        store = InMemoryStore()
        store.put(("values",), "foo", {"bar": 2})

        @tool
        def store_tool(x: int, my_store: Annotated[Any, InjectedStore()]) -> str:
            '''Do something with store.'''
            stored_value = my_store.get(("values",), "foo").value["bar"]
            return stored_value + x

        node = ToolNode([store_tool])

        tool_call = {"name": "store_tool", "args": {"x": 1}, "id": "1", "type": "tool_call"}
        state = {
            "messages": [AIMessage("", tool_calls=[tool_call])],
        }

        node.invoke(state, store=store)
        ```

        ```pycon
        {
            "messages": [
                ToolMessage(content='3', name='store_tool', tool_call_id='1'),
            ]
        }
        ```
    N)r   r   r   r   r   rG   r8   r   r     s    1rG   r   type_arginjection_typec                     t        |       st        | t              rt        |       ryt        |       }|t        u s|t
        u rt        fdt        |       D              S y)NTc              3   6   K   | ]  }t        |        y wrO   )_is_injection)rQ   tar   s     r8   rS   z _is_injection.<locals>.<genexpr>+  s     R=^4Rs   F)r.   r,   rP   r   r   r   r   r   )r   r   origin_s    ` r8   r   r   "  sW     (N+8T"z(N'K"G%7i/Rx?QRRRrG   r   c                    | j                         }i }t        |      j                         D ]  \  }}t        |      D cg c]  }t	        |t
              r| }}t        |      dkD  rt        d| d| d      t        |      dk(  r7|d   }t        |t
              r|j                  r|j                  ||<   d ||<    |S c c}w )NrM   zXA tool argument should not be annotated with InjectedState more than once. Received arg  with annotations r   r   )
get_input_schemar   r   r   r   r   rZ   rD   r.   r   )r   full_schematool_args_to_state_fieldsrY   type_r   
injections	injections           r8   rv   rv   /  s    '')K&(4[AGGI e %UO
X}5 

 

 z?Q&&*V+=j\L  _!"1I)]3	2;//)$/26)$/%& %$%
s   Cc                 &   | j                         }t        |      j                         D ]`  \  }}t        |      D cg c]  }t	        |t
              r| }}t        |      dkD  rt        d| d| d       Ot        |      dk(  r|c S b y c c}w )NrM   zXA tool argument should not be annotated with InjectedStore more than once. Received arg r   r   )r   r   r   r   r   r   rZ   rD   )r   r   rY   r   r   r   s         r8   rw   rw   I  s    '')K4[AGGI e %UO
X}5 

 

 z?Q&&*V+=j\L _!K  
s   B)rh   )Fr   rU   r+   r   r   dataclassesr   typingr   r   r   r	   r
   r   r   r   r   r   langchain_core.messagesr   r   r   r   r   langchain_core.runnablesr   langchain_core.runnables.configr   r   langchain_core.toolsr   r   r   ru   langchain_core.tools.baser   pydanticr   typing_extensionsr   r   r   langgraph.errorsr    langgraph.store.baser!   langgraph.typesr"   r#   langgraph.utils.runnabler$   r   r@   r/   r0   r2   r9   r5   r>   r?   r,   rF   rd   rf   r   r   r   r   rv   rw   r   rG   r8   <module>r     s           4 ; 4 C  = = * * ) 5 S ! H s uS$t*_'= * cd9os"#	% 	0$(38"4 $tIPS?S9T $Nd dR #@j!4S>9<=@@  @F<O <~2O 2j

#(m)<d=>Q)Q#R
	
%( %tC#,>'? %4 hsm rG   