
    Zi                    f   S SK Jr  S SKJrJrJr  S SKJrJrJ	r	  S SK
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Jr  S S
KJr  Sr\" SSS9 " S S5      5       r\" SSS9 " S S5      5       rSS jr " S S\\\   SS9r\" S0 \D6 " S S\\   5      5       r \ " SS\SSS9r!SSS jjr"g)     )annotations)	dataclassfieldreplace)AnyGenericcast)	BaseStore)BaseUser)	TypedDictUnpack)CONFCONFIG_KEY_RUNTIME)
get_config)
_DC_KWARGSStreamWriter)ContextT)r   ExecutionInfoRuntime
ServerInfoget_runtimeT)frozenslotsc                      \ rS rSr% SrS\S'    S\S'    S\S'    SrS\S	'    SrS\S
'    SrS\S'    Sr	S\S'    SS jr
Srg)r      zORead-only execution info/metadata for the execution of current thread/run/node.strcheckpoint_idcheckpoint_nstask_idNz
str | None	thread_idrun_id   intnode_attemptzfloat | Nonenode_first_attempt_timec                    [        U 40 UD6$ )zAReturn a new execution info object with selected fields replaced.r   self	overridess     k/var/www/eduai.edurigo.com/question_generate/ques_gen_env/lib/python3.13/site-packages/langgraph/runtime.pypatchExecutionInfo.patch5   s    t)y))     )r*   r   returnr   )__name__
__module____qualname____firstlineno____doc____annotations__r    r!   r$   r%   r,   __static_attributes__r/   r.   r+   r   r      sc    Y6=L0 Iz H FJA L#<,0\0F*r.   r   c                  @    \ rS rSr% SrS\S'    S\S'    SrS\S'   S	rg)
r   :   zmMetadata injected by LangGraph Server. None when running open-source LangGraph without LangSmith deployments.r   assistant_idgraph_idNzBaseUser | Noneuserr/   )r1   r2   r3   r4   r5   r6   r<   r7   r/   r.   r+   r   r   :   s%    w5M1 D/ r.   r   c                    g Nr/   )_s    r+   _no_op_stream_writerr@   M   s    #r.   c                  R    \ rS rSr% S\S'   S\S'   S\S'   S\S	'   S
\S'   S\S'   Srg)_RuntimeOverridesP   r   contextBaseStore | Nonestorer   stream_writerr   previousr   execution_infoServerInfo | Noneserver_infor/   N)r1   r2   r3   r4   r6   r7   r/   r.   r+   rB   rB   P   s%    M!!""r.   rB   F)totalc                      \ rS rSr% Sr\" SS9rS\S'    \" SS9rS\S'    \" \	S9r
S	\S
'    \" SS9rS\S'    \" SS9rS\S'    \" SS9rS\S'    SS jr    SS jrSS jrSrg)r   Y   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   rD   rE   rF   r   rG   r   rH   zExecutionInfo | NonerI   rJ   rK   c           	        [        UR                  =(       d    U R                  UR                  =(       d    U R                  UR                  [        La  UR                  OU R                  UR
                  c  U R
                  OUR
                  UR                  =(       d    U R                  UR                  =(       d    U R                  S9$ )z{Merge two runtimes together.

If a value is not provided in the other runtime, the value from the current runtime is used.
)rD   rF   rG   rH   rI   rK   )r   rD   rF   rG   r@   rH   rI   rK   )r)   others     r+   mergeRuntime.merge   s    
 MM1T\\+++""*>>  --##&+nn&<T]]%.. //F43F3F))=T-=-=	
 		
r.   c                    [        U 40 UD6$ )z@Replace the runtime with a new runtime with the given overrides.r'   r(   s     r+   overrideRuntime.override   s     t)y))r.   c                ~    U R                   c  Sn[        U5      e[        U U R                   R                  " S0 UD6S9$ )zBReturn a new runtime with selected execution_info fields replaced.z2Cannot patch execution_info before it has been set)rI   r/   )rI   RuntimeErrorr   r,   )r)   r*   msgs      r+   patch_execution_infoRuntime.patch_execution_info   sE    &FCs##..44AyA
 	
r.   r/   )rQ   Runtime[ContextT]r0   r\   )r*   z#Unpack[_RuntimeOverrides[ContextT]]r0   r\   )r*   r   r0   r\   )r1   r2   r3   r4   r5   r   rD   r6   rF   r@   rG   rH   rI   rK   rR   rU   rZ   r7   r/   r.   r+   r   r   Y   s    FP d+GX+5 $D1E1C"'0D"EM<E4$'Hc'
 ,1+>N(>2 &+4%8K"8w
 *>*	*
r.   r   N)rD   rF   rG   rH   rI   c                x    [        [        [           [        5       [           R                  [        5      5      nU$ )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   )context_schemaruntimes     r+   r   r      s-     78$jl4&8&<&<=O&PQGNr.   )r?   r   r0   Noner/   r>   )r_   ztype[ContextT] | Noner0   r\   )#
__future__r   dataclassesr   r   r   typingr   r   r	   langgraph.store.baser
   langgraph_sdk.auth.typesr   typing_extensionsr   r   langgraph._internal._constantsr   r   langgraph.configr   langgraph.typesr   r   langgraph.typingr   __all__r   r   r@   rB   r   DEFAULT_RUNTIMEr   r/   r.   r+   <module>rn      s    " 1 1 % % * - / C ' 4 % $d#* * $*B $d#  $$ .#	78#4E # Z@
gh @
 @
F 
&r.   