
    }
i%                    f   d dl mZ d dl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mZ d dlmZ d dlmZmZ d d	lmZ d
Z G d de	          ZddZ G d deee         d          Z edi e G d dee                               Z edded e                      Zd d!dZ dS )"    )annotations)	dataclassfieldreplace)AnyGeneric
NamedTuplecast)	BaseStore)	TypedDictUnpack)CONFCONFIG_KEY_RUNTIME)
get_config)
_DC_KWARGSStreamWriter)ContextT)ExecutionInfoRuntimeget_runtimec                  <    e Zd ZU dZdZded<   	 dZded<   	 ddZdS )r   zORead-only execution info/metadata for the execution of current thread/run/node.   intnode_attemptNzfloat | Nonenode_first_attempt_time	overridesr   returnc                     | j         di |S )zAReturn a new execution info object with selected fields replaced. )_replaceselfr   s     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langgraph/runtime.pypatchzExecutionInfo.patch   s    t}))y)))    )r   r   r   r   )__name__
__module____qualname____doc__r   __annotations__r   r$   r   r%   r#   r   r      sY         YYL<,00000F* * * * * *r%   r   _r   r   Nonec                    d S Nr   )r+   s    r#   _no_op_stream_writerr/      s      r%   c                  B    e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   dS )_RuntimeOverridesr   contextBaseStore | Nonestorer   stream_writerr   previousr   execution_infoN)r&   r'   r(   r*   r   r%   r#   r1   r1   "   sK         MMM!!!!!!r%   r1   F)totalc                      e Zd ZU dZ ed          Zded<   	  ed          Zded<   	  ee          Z	ded	<   	  ed          Z
d
ed<   	  ee          Zded<   	 ddZddZddZdS )r   a	  Convenience class that bundles run-scoped context and other runtime utilities.

    This class is injected into graph nodes and middleware. It provides access to
    `context`, `store`, `stream_writer`, `previous`, and `execution_info`.

    !!! note "Accessing `config`"

        `Runtime` does not include `config`. To access `RunnableConfig`, you can inject
        it directly by adding a `config: RunnableConfig` parameter to your node function
        (recommended), or use `get_config()` from `langgraph.config`.

    !!! note
        `ToolRuntime` (from `langgraph.prebuilt`) is a subclass that provides similar
        functionality but is designed specifically for tools. It shares `context`, `store`,
        and `stream_writer` with `Runtime`, and adds tool-specific attributes like `config`,
        `state`, and `tool_call_id`.

    !!! version-added "Added in version v0.6.0"

    Example:

    ```python
    from typing import TypedDict
    from langgraph.graph import StateGraph
    from dataclasses import dataclass
    from langgraph.runtime import Runtime
    from langgraph.store.memory import InMemoryStore


    @dataclass
    class Context:  # (1)!
        user_id: str


    class State(TypedDict, total=False):
        response: str


    store = InMemoryStore()  # (2)!
    store.put(("users",), "user_123", {"name": "Alice"})


    def personalized_greeting(state: State, runtime: Runtime[Context]) -> State:
        '''Generate personalized greeting using runtime context and store.'''
        user_id = runtime.context.user_id  # (3)!
        name = "unknown_user"
        if runtime.store:
            if memory := runtime.store.get(("users",), user_id):
                name = memory.value["name"]

        response = f"Hello {name}! Nice to see you again."
        return {"response": response}


    graph = (
        StateGraph(state_schema=State, context_schema=Context)
        .add_node("personalized_greeting", personalized_greeting)
        .set_entry_point("personalized_greeting")
        .set_finish_point("personalized_greeting")
        .compile(store=store)
    )

    result = graph.invoke({}, context=Context(user_id="user_123"))
    print(result)
    # > {'response': 'Hello Alice! Nice to see you again.'}
    ```

    1. Define a schema for the runtime context.
    2. Create a store to persist memories and other information.
    3. Use the runtime context to access the `user_id`.
    N)defaultr   r2   r3   r4   r   r5   r   r6   )default_factoryr   r7   otherRuntime[ContextT]r   c                    t          |j        p| j        |j        p| j        |j        t          ur|j        n| j        |j        | j        n|j        |j                  S )zMerge two runtimes together.

        If a value is not provided in the other runtime, the value from the current runtime is used.
        Nr2   r4   r5   r6   r7   )r   r2   r4   r5   r/   r6   r7   )r"   r<   s     r#   mergezRuntime.merge   sk    
 M1T\++"*>>>  --#&+n&<T]]%. /
 
 
 	
r%   r   #Unpack[_RuntimeOverrides[ContextT]]c                    t          | fi |S )z@Replace the runtime with a new runtime with the given overrides.)r   r!   s     r#   overridezRuntime.override   s     t))y)))r%   c                D    t          |  | j        j        di |          S )zBReturn a new runtime with selected execution_info fields replaced.)r7   r   )r   r7   r$   r!   s     r#   patch_execution_infozRuntime.patch_execution_info   s5    44.4AAyAA
 
 
 	
r%   )r<   r=   r   r=   )r   rA   r   r=   )r   r   r   r=   )r&   r'   r(   r)   r   r2   r*   r4   r/   r5   r6   r   r7   r@   rC   rE   r   r%   r#   r   r   *   s        F FP d+++G++++5 $eD111E1111C"'%0D"E"E"EMEEEE4E$'''H''''
 %*E-$H$H$HNHHHHL
 
 
 
* * * *
 
 
 
 
 
r%   r   Nr?   context_schematype[ContextT] | Noner=   c                    t          t          t                   t                      t                                       t                              }|S )zGet the runtime for the current graph run.

    Args:
        context_schema: Optional schema used for type hinting the return type of the runtime.

    Returns:
        The runtime for the current graph run.
    )r
   r   r   r   r   getr   )rF   runtimes     r#   r   r      s5     78$jll4&8&<&<=O&P&PQQGNr%   )r+   r   r   r,   r   r.   )rF   rG   r   r=   )!
__future__r   dataclassesr   r   r   typingr   r   r	   r
   langgraph.store.baser   typing_extensionsr   r   langgraph._internal._constantsr   r   langgraph.configr   langgraph.typesr   r   langgraph.typingr   __all__r   r/   r1   r   DEFAULT_RUNTIMEr   r   r%   r#   <module>rV      s   " " " " " " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 * * * * * * / / / / / / / / C C C C C C C C ' ' ' ' ' ' 4 4 4 4 4 4 4 4 % % % % % %
5* * * * *J * * * . - - -" " " " "	78#4E " " " " Zw
 w
 w
 w
 w
gh w
 w
 w
t '
& =??        r%   