
    c
iJ                        d Z ddlmZ ddlZddlZddlmZmZmZm	Z	 ddl
mZmZmZ ddlZddlmZ ddlmZ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mZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ ddZ, G d d          Z-dS )z,Async client for managing runs in LangGraph.    )annotationsN)AsyncIteratorCallableMappingSequence)AnyLiteraloverload)
HttpClient)_get_run_metadata_from_response_sse_to_v2_dict)AllBulkCancelRunsStatusCancelAction
CheckpointCommandConfigContextDisconnectMode
DurabilityIfNotExistsInputMultitaskStrategyOnCompletionBehaviorQueryParamTypesRun	RunCreateRunCreateMetadataRunSelectField	RunStatus
StreamMode
StreamPartStreamPartV2StreamVersionrawAsyncIterator[StreamPart]returnAsyncIterator[StreamPartV2]c               b   K   | 2 3 d{V }t          |j        |j                  }||W V  )6 dS )z:Wrap a raw SSE stream, converting each event to a v2 dict.N)r   eventdata)r%   partv2s      C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langgraph_sdk/_async/runs.py_wrap_stream_v2r/   ,   s]              dTZ33>HHHH ccs   .c                  |   e Zd ZdZddZedddd	d	dddddddddddddddddd
ddd;            Zedddd	d	dddddddddddddddddd<dd?            Zedddd	d	ddddddddddddddd
d@ddC            Zedddd	d	dddddddddddddddDddE            Zdddd	d	dddddddddddddddddddd
dFddKZedddd	d	ddddddddddddddLddN            Zedddd	d	ddddddddddddddddOddP            Zdddd	d	ddddddddddddddddddQddRZdddSddWZeddddddddddddddddXddddYdd\            Z	eddddddddddddddXdddd]dd^            Z	dddddddddddddddddXddddd_dd`Z	dadbdddddcddkZ
dddSddmZd	dndddoddsZddddndddtddwZdddSddyZd	dddddzdd~ZdddSddZdS )
RunsClienta  Client for managing runs in LangGraph.

    A run is a single assistant invocation with optional input, config, context, and metadata.
    This client manages runs, which can be stateful (on threads) or stateless.

    ???+ example "Example"

        ```python
        client = get_client(url="http://localhost:2024")
        run = await client.runs.create(assistant_id="asst_123", thread_id="thread_456", input={"query": "Hello"})
        ```
    httpr   r'   Nonec                    || _         d S N)r2   )selfr2   s     r.   __init__zRunsClient.__init__D   s    			    NvaluesFv1)inputcommandstream_modestream_subgraphsstream_resumablemetadataconfigcontext
checkpointcheckpoint_idcheckpoint_duringinterrupt_beforeinterrupt_afterfeedback_keyson_disconnectwebhookmultitask_strategyif_not_existsafter_secondsheadersparamson_run_createdversion	thread_idstrassistant_idr;   Input | Noner<   Command | Noner=   !StreamMode | Sequence[StreamMode]r>   boolr?   r@   Mapping[str, Any] | NonerA   Config | NonerB   Context | NonerC   Checkpoint | NonerD   
str | NonerE   bool | NonerF   All | Sequence[str] | NonerG   rH   Sequence[str] | NonerI   DisconnectMode | NonerJ   rK   MultitaskStrategy | NonerL   IfNotExists | NonerM   
int | NonerN   Mapping[str, str] | NonerO   QueryParamTypes | NonerP   *Callable[[RunCreateMetadata], None] | NonerQ   Literal['v1']r&   c                   d S r5    r6   rR   rT   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   s                             r.   streamzRunsClient.streamG   s	    : %(Cr8   )r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   Literal['v2']r(   c                   d S r5   rj   rk   s                             r.   rl   zRunsClient.streamf   s	    : '*cr8   )r;   r<   r=   r>   r?   r@   rA   rE   rF   rG   rH   rI   on_completionrL   rJ   rM   rN   rO   rP   rQ   ro   OnCompletionBehavior | Nonec                   d S r5   rj   r6   rR   rT   r;   r<   r=   r>   r?   r@   rA   rE   rF   rG   rH   rI   ro   rL   rJ   rM   rN   rO   rP   rQ   s                          r.   rl   zRunsClient.stream   s	    4 %(Cr8   )r;   r<   r=   r>   r?   r@   rA   rE   rF   rG   rH   rI   ro   rL   rJ   rM   rN   rO   rP   c                   d S r5   rj   rr   s                          r.   rl   zRunsClient.stream   s	    4 '*cr8   )r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   ro   rJ   rK   rL   rM   rN   rO   rP   
durabilityrQ   rt   Durability | Noner$   (AsyncIterator[StreamPart | StreamPartV2]c                  |t          j        dt          d           i d|d|rd |                                D             ndd|	d	|
d
|d|d|d|d|d|d|d|d|d|d|d|d||||||d}|d| dnd}d!fd}| j                            |dd |                                D             ||r|nd          }|d k    rt          |          S |S )"a  Create a run and stream the results.

        Args:
            thread_id: the thread ID to assign to the thread.
                If `None` will create a stateless run.
            assistant_id: The assistant ID or graph name to stream from.
                If using graph name, will default to first assistant created from that graph.
            input: The input to the graph.
            command: A command to execute. Cannot be combined with input.
            stream_mode: The stream mode(s) to use.
            stream_subgraphs: Whether to stream output from subgraphs.
            stream_resumable: Whether the stream is considered resumable.
                If true, the stream can be resumed and replayed in its entirety even after disconnection.
            metadata: Metadata to assign to the run.
            config: The configuration for the assistant.
            context: Static context to add to the assistant.
                !!! version-added "Added in version 0.6.0"
            checkpoint: The checkpoint to resume from.
            checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
            interrupt_before: Nodes to interrupt immediately before they get executed.
            interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
            feedback_keys: Feedback keys to assign to run.
            on_disconnect: The disconnect mode to use.
                Must be one of 'cancel' or 'continue'.
            on_completion: Whether to delete or keep the thread created for a stateless run.
                Must be one of 'delete' or 'keep'.
            webhook: Webhook to call after LangGraph API call is done.
            multitask_strategy: Multitask strategy to use.
                Must be one of 'reject', 'interrupt', 'rollback', or 'enqueue'.
            if_not_exists: How to handle missing thread. Defaults to 'reject'.
                Must be either 'reject' (raise error if missing), or 'create' (create new thread).
            after_seconds: The number of seconds to wait before starting the run.
                Use to schedule future runs.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.
            on_run_created: Callback when a run is created.
            durability: The durability to use for the run. Values are "sync", "async", or "exit".
                "async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
                "sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
                "exit" means checkpoints are only persisted when the run exits, does not save intermediate steps
            version: Stream format version. "v1" (default) returns raw SSE StreamPart
                NamedTuples. "v2" returns typed dicts with `type`, `ns`, and `data` keys.

        Returns:
            Asynchronous iterator of stream results.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024)
            async for chunk in client.runs.stream(
                thread_id=None,
                assistant_id="agent",
                input={"messages": [{"role": "user", "content": "how are you?"}]},
                stream_mode=["values","debug"],
                metadata={"name":"my_run"},
                context={"model_name": "anthropic"},
                interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
                interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
                feedback_keys=["my_feedback_key_1","my_feedback_key_2"],
                webhook="https://my.fake.webhook.com",
                multitask_strategy="interrupt"
            ):
                print(chunk)
            ```

            ```shell

            ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

            StreamPart(event='metadata', data={'run_id': '1ef4a9b8-d7da-679a-a45a-872054341df2'})
            StreamPart(event='values', data={'messages': [{'content': 'how are you?', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'human', 'name': None, 'id': 'fe0a5778-cfe9-42ee-b807-0adaa1873c10', 'example': False}]})
            StreamPart(event='values', data={'messages': [{'content': 'how are you?', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'human', 'name': None, 'id': 'fe0a5778-cfe9-42ee-b807-0adaa1873c10', 'example': False}, {'content': "I'm doing well, thanks for asking! I'm an AI assistant created by Anthropic to be helpful, honest, and harmless.", 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'ai', 'name': None, 'id': 'run-159b782c-b679-4830-83c6-cef87798fe8b', 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None}]})
            StreamPart(event='end', data=None)
            ```

        Nd`checkpoint_during` is deprecated and will be removed in a future version. Use `durability` instead.   
stacklevelr;   r<   c                    i | ]
\  }}|||S r5   rj   .0kvs      r.   
<dictcomp>z%RunsClient.stream.<locals>.<dictcomp>3      CCC$!QQ]A]]]r8   rA   rB   r@   r=   r>   r?   rT   rF   rG   rH   rJ   rC   rD   rE   rK   )rL   rI   ro   rM   rt   	/threads/z/runs/streamreshttpx.Responsec                L    rt          |           x}r |           dS dS dS z)Callback function to handle the response.Nr   r   r@   rP   s     r.   on_responsez&RunsClient.stream.<locals>.on_responseP  J     )/Ns/S/S#S8 )x((((() ) ) )r8   POSTc                    i | ]
\  }}|||S r5   rj   r}   s      r.   r   z%RunsClient.stream.<locals>.<dictcomp>X      DDD41aam!Qmmmr8   jsonrO   rN   r   r-   r   r   )warningswarnDeprecationWarningitemsr2   rl   r/   ) r6   rR   rT   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   ro   rJ   rK   rL   rM   rN   rO   rP   rt   rQ   payloadendpointr   r%   s                             `      r.   rl   zRunsClient.stream   s   X (Mv"   #
U#
GNXCC'--//CCCCTX#

 f#
 w#
 #
 ;#
  0#
  0#
 L#
  0#
 #
 ]#
 w#
  *!#
" ]##
$  !2%#
& !"4'#
( +***$1#
 #
 #
8 $ 0	//// 		) 	) 	) 	) 	) 	)
 iDD7==??DDD'5?4  
 
 d??"3'''
r8   )r;   r<   r=   r>   r?   r@   rE   rA   rB   rF   rG   rJ   ro   rL   rM   rN   rO   rP   r   c               
   K   d S r5   rj   )r6   rR   rT   r;   r<   r=   r>   r?   r@   rE   rA   rB   rF   rG   rJ   ro   rL   rM   rN   rO   rP   s                        r.   createzRunsClient.createa  s      0 cr8   )r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rJ   rK   rL   rM   rN   rO   rP   c               
   K   d S r5   rj   )r6   rR   rT   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rJ   rK   rL   rM   rN   rO   rP   s                          r.   r   zRunsClient.create{  s      4 cr8   )r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rJ   rK   rL   ro   rM   rN   rO   rP   rt   c                 K   |t          j        dt          d           i d|d|rd |                                D             ndd|d	|d
|d|	d|
d|d|d|d|d|d|d|d|d|d||||d}d |                                D             }dfd}| j                            |rd| dnd|||r|nd           d{V S ) a<  Create a background run.

        Args:
            thread_id: the thread ID to assign to the thread.
                If `None` will create a stateless run.
            assistant_id: The assistant ID or graph name to stream from.
                If using graph name, will default to first assistant created from that graph.
            input: The input to the graph.
            command: A command to execute. Cannot be combined with input.
            stream_mode: The stream mode(s) to use.
            stream_subgraphs: Whether to stream output from subgraphs.
            stream_resumable: Whether the stream is considered resumable.
                If true, the stream can be resumed and replayed in its entirety even after disconnection.
            metadata: Metadata to assign to the run.
            config: The configuration for the assistant.
            context: Static context to add to the assistant.
                !!! version-added "Added in version 0.6.0"
            checkpoint: The checkpoint to resume from.
            checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
            interrupt_before: Nodes to interrupt immediately before they get executed.
            interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
            webhook: Webhook to call after LangGraph API call is done.
            multitask_strategy: Multitask strategy to use.
                Must be one of 'reject', 'interrupt', 'rollback', or 'enqueue'.
            on_completion: Whether to delete or keep the thread created for a stateless run.
                Must be one of 'delete' or 'keep'.
            if_not_exists: How to handle missing thread. Defaults to 'reject'.
                Must be either 'reject' (raise error if missing), or 'create' (create new thread).
            after_seconds: The number of seconds to wait before starting the run.
                Use to schedule future runs.
            headers: Optional custom headers to include with the request.
            on_run_created: Optional callback to call when a run is created.
            durability: The durability to use for the run. Values are "sync", "async", or "exit".
                "async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
                "sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
                "exit" means checkpoints are only persisted when the run exits, does not save intermediate steps

        Returns:
            The created background run.

        ???+ example "Example Usage"

            ```python

            background_run = await client.runs.create(
                thread_id="my_thread_id",
                assistant_id="my_assistant_id",
                input={"messages": [{"role": "user", "content": "hello!"}]},
                metadata={"name":"my_run"},
                context={"model_name": "openai"},
                interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
                interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
                webhook="https://my.fake.webhook.com",
                multitask_strategy="interrupt"
            )
            print(background_run)
            ```

            ```shell
            --------------------------------------------------------------------------------

            {
                'run_id': 'my_run_id',
                'thread_id': 'my_thread_id',
                'assistant_id': 'my_assistant_id',
                'created_at': '2024-07-25T15:35:42.598503+00:00',
                'updated_at': '2024-07-25T15:35:42.598503+00:00',
                'metadata': {},
                'status': 'pending',
                'kwargs':
                    {
                        'input':
                            {
                                'messages': [
                                    {
                                        'role': 'user',
                                        'content': 'how are you?'
                                    }
                                ]
                            },
                        'config':
                            {
                                'metadata':
                                    {
                                        'created_by': 'system'
                                    },
                                'configurable':
                                    {
                                        'run_id': 'my_run_id',
                                        'user_id': None,
                                        'graph_id': 'agent',
                                        'thread_id': 'my_thread_id',
                                        'checkpoint_id': None,
                                        'assistant_id': 'my_assistant_id'
                                    },
                            },
                        'context':
                            {
                                'model_name': 'openai'
                            }
                        'webhook': "https://my.fake.webhook.com",
                        'temporary': False,
                        'stream_mode': ['values'],
                        'feedback_keys': None,
                        'interrupt_after': ["node_to_stop_after_1","node_to_stop_after_2"],
                        'interrupt_before': ["node_to_stop_before_1","node_to_stop_before_2"]
                    },
                'multitask_strategy': 'interrupt'
            }
            ```
        Nrx   ry   rz   r;   r<   c                    i | ]
\  }}|||S r5   rj   r}   s      r.   r   z%RunsClient.create.<locals>.<dictcomp>+  r   r8   r=   r>   r?   rA   rB   r@   rT   rF   rG   rJ   rC   rD   rE   rK   rL   )ro   rM   rt   c                    i | ]
\  }}|||S r5   rj   r}   s      r.   r   z%RunsClient.create.<locals>.<dictcomp>@  s    EEEDAqq}1a}}}r8   r   r   c                L    rt          |           x}r |           dS dS dS r   r   r   s     r.   r   z&RunsClient.create.<locals>.on_responseB  r   r8   r   /runsr   r   )r   r   r   r   r2   post)r6   rR   rT   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rJ   rK   rL   ro   rM   rN   rO   rP   rt   r   r   s                          `   r.   r   zRunsClient.create  s     V (Mv"   

U
GNXCC'--//CCCCTX

 ;
  0
  0
 f
 w
 
 L
  0
 
 w
 *
  ]!
"  !2#
$ !"4%
& ]'
( +*$-
 
 
0 FEGMMOOEEE	) 	) 	) 	) 	) 	)
 Y^^,5B(	((((7'5?4 $ 
 
 
 
 
 
 
 
 	
r8   rN   rO   payloadsbuiltins.list[RunCreate]builtins.list[Run]c               t   K   ddfd|D             }| j                             d|||           d{V S )	z,Create a batch of stateless background runs.r   r   c                >    d |                                  D             S )Nc                    i | ]
\  }}|||S r5   rj   r}   s      r.   r   zCRunsClient.create_batch.<locals>.filter_payload.<locals>.<dictcomp>Y  s    FFFTQAqr8   )r   )r   s    r.   filter_payloadz/RunsClient.create_batch.<locals>.filter_payloadX  s    FFW]]__FFFFr8   c                &    g | ]} |          S rj   rj   )r~   r   r   s     r.   
<listcomp>z+RunsClient.create_batch.<locals>.<listcomp>[  s#    DDDNN7++DDDr8   z/runs/batchr   rN   rO   N)r   r   )r2   r   )r6   r   rN   rO   filteredr   s        @r.   create_batchzRunsClient.create_batchO  s      	G 	G 	G 	G EDDD8DDDY^^'& $ 
 
 
 
 
 
 
 
 	
r8   T)r;   r<   r@   rA   rB   rC   rD   rE   rF   rG   rJ   rI   rK   rL   rM   raise_errorrN   rO   rP   r   $builtins.list[dict] | dict[str, Any]c               
   K   d S r5   rj   )r6   rR   rT   r;   r<   r@   rA   rB   rC   rD   rE   rF   rG   rJ   rI   rK   rL   rM   r   rN   rO   rP   s                         r.   waitzRunsClient.wait`  s      2 03sr8   )r;   r<   r@   rA   rB   rE   rF   rG   rJ   rI   ro   rL   rM   r   rN   rO   rP   c               
   K   d S r5   rj   )r6   rR   rT   r;   r<   r@   rA   rB   rE   rF   rG   rJ   rI   ro   rL   rM   r   rN   rO   rP   s                       r.   r   zRunsClient.wait{  s      . 03sr8   )r;   r<   r@   rA   rB   rC   rD   rE   rF   rG   rJ   rI   ro   rK   rL   rM   r   rN   rO   rP   rt   c                 K   |
t          j        dt          d           i d|d|rd |                                D             ndd|d	|d
|d|d|d|d|d|d|	d|d|
d|d|d|d|d|i}|d| dnd}d$fd}| j                            |dd |                                D             ||r|nd           d{V }|rzt          |t                    red |v rat          |d          t                    rFt          |d          	                    d!           d"|d          	                    d#                     |S )%a  Create a run, wait until it finishes and return the final state.

        Args:
            thread_id: the thread ID to create the run on.
                If `None` will create a stateless run.
            assistant_id: The assistant ID or graph name to run.
                If using graph name, will default to first assistant created from that graph.
            input: The input to the graph.
            command: A command to execute. Cannot be combined with input.
            metadata: Metadata to assign to the run.
            config: The configuration for the assistant.
            context: Static context to add to the assistant.
                !!! version-added "Added in version 0.6.0"
            checkpoint: The checkpoint to resume from.
            checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
            interrupt_before: Nodes to interrupt immediately before they get executed.
            interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
            webhook: Webhook to call after LangGraph API call is done.
            on_disconnect: The disconnect mode to use.
                Must be one of 'cancel' or 'continue'.
            on_completion: Whether to delete or keep the thread created for a stateless run.
                Must be one of 'delete' or 'keep'.
            multitask_strategy: Multitask strategy to use.
                Must be one of 'reject', 'interrupt', 'rollback', or 'enqueue'.
            if_not_exists: How to handle missing thread. Defaults to 'reject'.
                Must be either 'reject' (raise error if missing), or 'create' (create new thread).
            after_seconds: The number of seconds to wait before starting the run.
                Use to schedule future runs.
            headers: Optional custom headers to include with the request.
            on_run_created: Optional callback to call when a run is created.
            durability: The durability to use for the run. Values are "sync", "async", or "exit".
                "async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
                "sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
                "exit" means checkpoints are only persisted when the run exits, does not save intermediate steps

        Returns:
            The output of the run.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            final_state_of_run = await client.runs.wait(
                thread_id=None,
                assistant_id="agent",
                input={"messages": [{"role": "user", "content": "how are you?"}]},
                metadata={"name":"my_run"},
                context={"model_name": "anthropic"},
                interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
                interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
                webhook="https://my.fake.webhook.com",
                multitask_strategy="interrupt"
            )
            print(final_state_of_run)
            ```

            ```shell
            -------------------------------------------------------------------------------------------------------------------------------------------

            {
                'messages': [
                    {
                        'content': 'how are you?',
                        'additional_kwargs': {},
                        'response_metadata': {},
                        'type': 'human',
                        'name': None,
                        'id': 'f51a862c-62fe-4866-863b-b0863e8ad78a',
                        'example': False
                    },
                    {
                        'content': "I'm doing well, thanks for asking! I'm an AI assistant created by Anthropic to be helpful, honest, and harmless.",
                        'additional_kwargs': {},
                        'response_metadata': {},
                        'type': 'ai',
                        'name': None,
                        'id': 'run-bf1cd3c6-768f-4c16-b62d-ba6f17ad8b36',
                        'example': False,
                        'tool_calls': [],
                        'invalid_tool_calls': [],
                        'usage_metadata': None
                    }
                ]
            }
            ```

        Nrx   ry   rz   r;   r<   c                    i | ]
\  }}|||S r5   rj   r}   s      r.   r   z#RunsClient.wait.<locals>.<dictcomp>  r   r8   rA   rB   r@   rT   rF   rG   rJ   rC   rD   rK   rE   rL   rI   ro   rM   rt   r   z
/runs/waitr   r   c                L    rt          |           x}r |           dS dS dS r   r   r   s     r.   r   z$RunsClient.wait.<locals>.on_response&  r   r8   r   c                    i | ]
\  }}|||S r5   rj   r}   s      r.   r   z#RunsClient.wait.<locals>.<dictcomp>.  r   r8   r   	__error__errorz: messager   )
r   r   r   r   r2   request_reconnect
isinstancedict	Exceptionget)r6   rR   rT   r;   r<   r@   rA   rB   rC   rD   rE   rF   rG   rJ   rI   ro   rK   rL   rM   r   rN   rO   rP   rt   r   r   r   responses                         `     r.   r   zRunsClient.wait  sv     d (Mv"   

U
GNXCC'--//CCCCTX

 f
 w
 
 L
  0
 
 w
 *
 ]
 !"4
  !2
  ]!
" ]#
$ ]%
& ]'
( *)
 
. 2;1F-	----L 		) 	) 	) 	) 	) 	)
 44DD7==??DDD'5?4 5 
 
 
 
 
 
 
 
 	8T**	 x''8K0$77 ( K(,,W55__+9N9R9RS\9]9]__   r8   
   r   )limitoffsetstatusselectrN   rO   r   intr   r   RunStatus | Noner   $builtins.list[RunSelectField] | Nonec                  K   ||d}|||d<   |r||d<   |r|                     |           | j                            d| d||           d{V S )a  List runs.

        Args:
            thread_id: The thread ID to list runs for.
            limit: The maximum number of results to return.
            offset: The number of results to skip.
            status: The status of the run to filter by.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            The runs for the thread.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            await client.runs.list(
                thread_id="thread_id",
                limit=5,
                offset=5,
            )
            ```

        )r   r   Nr   r   r   r   rO   rN   )updater2   r   )	r6   rR   r   r   r   r   rN   rO   query_paramss	            r.   listzRunsClient.list>  s      J (
 (
 %+L" 	,%+L" 	('''Y]](	(((w # 
 
 
 
 
 
 
 
 	
r8   run_idc               X   K   | j                             d| d| ||           d{V S )aU  Get a run.

        Args:
            thread_id: The thread ID to get.
            run_id: The run ID to get.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            `Run` object.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            run = await client.runs.get(
                thread_id="thread_id_to_delete",
                run_id="run_id_to_delete",
            )
            ```

        r   /runs/r   N)r2   r   r6   rR   r   rN   rO   s        r.   r   zRunsClient.getp  sZ      > Y]]1	111176 # 
 
 
 
 
 
 
 
 	
r8   	interrupt)r   actionrN   rO   r   r   r   c                  K   |rdnd|d}|r|                     |           |r+| j                            d| d| dd||           d	{V S | j                            d| d| dd	||
           d	{V S )a]  Get a run.

        Args:
            thread_id: The thread ID to cancel.
            run_id: The run ID to cancel.
            wait: Whether to wait until run has completed.
            action: Action to take when cancelling the run. Possible values
                are `interrupt` or `rollback`. Default is `interrupt`.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            `None`

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            await client.runs.cancel(
                thread_id="thread_id_to_cancel",
                run_id="run_id_to_cancel",
                wait=True,
                action="interrupt"
            )
            ```

           r   )r   r   r   r   z/cancelr   r   N)r   rO   rN   )r   r2   r   r   )r6   rR   r   r   r   rN   rO   r   s           r.   cancelzRunsClient.cancel  s     L $AA1
 
  	(''' 	44<I<<V<<<#	 5          <I<<V<<<#	 (         r8   )rR   run_idsr   r   rN   rO   r   BulkCancelRunsStatus | Nonec                  K   i }|r||d<   |r||d<   |r||d<   d|i}|r|                     |           | j                            d|||           d{V  dS )a  Cancel one or more runs.

        Can cancel runs by thread ID and run IDs, or by status filter.

        Args:
            thread_id: The ID of the thread containing runs to cancel.
            run_ids: List of run IDs to cancel.
            status: Filter runs by status to cancel. Must be one of
                `"pending"`, `"running"`, or `"all"`.
            action: Action to take when cancelling the run. Possible values
                are `"interrupt"` or `"rollback"`. Default is `"interrupt"`.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            `None`

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            # Cancel all pending runs
            await client.runs.cancel_many(status="pending")
            # Cancel specific runs on a thread
            await client.runs.cancel_many(
                thread_id="my_thread_id",
                run_ids=["run_1", "run_2"],
                action="rollback",
            )
            ```

        rR   r   r   r   z/runs/cancelr   N)r   r2   r   )	r6   rR   r   r   r   rN   rO   r   r   s	            r.   cancel_manyzRunsClient.cancel_many  s      T #% 	-#,GK  	)!(GI 	' &GH(0&'9 	('''inn	  
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   r   c               \   K   | j                             d| d| dd||           d{V S )a  Block until a run is done. Returns the final state of the thread.

        Args:
            thread_id: The thread ID to join.
            run_id: The run ID to join.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            `None`

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            result =await client.runs.join(
                thread_id="thread_id_to_join",
                run_id="run_id_to_join"
            )
            ```

        r   r   z/joinGETr   N)r2   r   r   s        r.   joinzRunsClient.join  sd      < Y006	66666	 1 
 
 
 
 
 
 
 
 	
r8   )cancel_on_disconnectr=   rN   rO   last_event_idr   (StreamMode | Sequence[StreamMode] | Noner   c                   ||d}|r|                     |           | j                            d| d| dd|i |rd|ini |pi pd          S )	a  Stream output from a run in real-time, until the run is done.
        Output is not buffered, so any output produced before this call will
        not be received here.

        Args:
            thread_id: The thread ID to join.
            run_id: The run ID to join.
            cancel_on_disconnect: Whether to cancel the run when the stream is disconnected.
            stream_mode: The stream mode(s) to use. Must be a subset of the stream modes passed
                when creating the run. Background runs default to having the union of all
                stream modes.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.
            last_event_id: The last event ID to use for the stream.

        Returns:
            The stream of parts.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            async for part in client.runs.join_stream(
                thread_id="thread_id_to_join",
                run_id="run_id_to_join",
                stream_mode=["values", "debug"]
            ):
                print(part)
            ```

        )r   r=   r   r   z/streamr   zLast-Event-IDNr   )r   r2   rl   )	r6   rR   r   r   r=   rN   rO   r   r   s	            r.   join_streamzRunsClient.join_stream-  s    V %9&
 
  	('''y8	888887DLO]33"=b     	
 	
 		
r8   c               \   K   | j                             d| d| ||           d{V  dS )aS  Delete a run.

        Args:
            thread_id: The thread ID to delete.
            run_id: The run ID to delete.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            `None`

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            await client.runs.delete(
                thread_id="thread_id_to_delete",
                run_id="run_id_to_delete"
            )
            ```

        r   r   r   N)r2   deleter   s        r.   r   zRunsClient.deleteh  sf      < i1	111176  
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   )r2   r   r'   r3   )4rR   rS   rT   rS   r;   rU   r<   rV   r=   rW   r>   rX   r?   rX   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r_   rG   r_   rH   r`   rI   ra   rJ   r]   rK   rb   rL   rc   rM   rd   rN   re   rO   rf   rP   rg   rQ   rh   r'   r&   )4rR   rS   rT   rS   r;   rU   r<   rV   r=   rW   r>   rX   r?   rX   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r_   rG   r_   rH   r`   rI   ra   rJ   r]   rK   rb   rL   rc   rM   rd   rN   re   rO   rf   rP   rg   rQ   rm   r'   r(   ).rR   r3   rT   rS   r;   rU   r<   rV   r=   rW   r>   rX   r?   rX   r@   rY   rA   rZ   rE   r^   rF   r_   rG   r_   rH   r`   rI   ra   ro   rp   rL   rc   rJ   r]   rM   rd   rN   re   rO   rf   rP   rg   rQ   rh   r'   r&   ).rR   r3   rT   rS   r;   rU   r<   rV   r=   rW   r>   rX   r?   rX   r@   rY   rA   rZ   rE   r^   rF   r_   rG   r_   rH   r`   rI   ra   ro   rp   rL   rc   rJ   r]   rM   rd   rN   re   rO   rf   rP   rg   rQ   rm   r'   r(   )8rR   r]   rT   rS   r;   rU   r<   rV   r=   rW   r>   rX   r?   rX   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r_   rG   r_   rH   r`   rI   ra   ro   rp   rJ   r]   rK   rb   rL   rc   rM   rd   rN   re   rO   rf   rP   rg   rt   ru   rQ   r$   r'   rv   )*rR   r3   rT   rS   r;   rU   r<   rV   r=   rW   r>   rX   r?   rX   r@   rY   rE   r^   rA   rZ   rB   r[   rF   r_   rG   r_   rJ   r]   ro   rp   rL   rc   rM   rd   rN   re   rO   rf   rP   rg   r'   r   ).rR   rS   rT   rS   r;   rU   r<   rV   r=   rW   r>   rX   r?   rX   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r_   rG   r_   rJ   r]   rK   rb   rL   rc   rM   rd   rN   re   rO   rf   rP   rg   r'   r   )2rR   r]   rT   rS   r;   rU   r<   rV   r=   rW   r>   rX   r?   rX   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r_   rG   r_   rJ   r]   rK   rb   rL   rc   ro   rp   rM   rd   rN   re   rO   rf   rP   rg   rt   ru   r'   r   )r   r   rN   re   rO   rf   r'   r   ),rR   rS   rT   rS   r;   rU   r<   rV   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r_   rG   r_   rJ   r]   rI   ra   rK   rb   rL   rc   rM   rd   r   rX   rN   re   rO   rf   rP   rg   r'   r   )(rR   r3   rT   rS   r;   rU   r<   rV   r@   rY   rA   rZ   rB   r[   rE   r^   rF   r_   rG   r_   rJ   r]   rI   ra   ro   rp   rL   rc   rM   rd   r   rX   rN   re   rO   rf   rP   rg   r'   r   )0rR   r]   rT   rS   r;   rU   r<   rV   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r_   rG   r_   rJ   r]   rI   ra   ro   rp   rK   rb   rL   rc   rM   rd   r   rX   rN   re   rO   rf   rP   rg   rt   ru   r'   r   )rR   rS   r   r   r   r   r   r   r   r   rN   re   rO   rf   r'   r   )
rR   rS   r   rS   rN   re   rO   rf   r'   r   )rR   rS   r   rS   r   rX   r   r   rN   re   rO   rf   r'   r3   )rR   r]   r   r`   r   r   r   r   rN   re   rO   rf   r'   r3   )
rR   rS   r   rS   rN   re   rO   rf   r'   r   )rR   rS   r   rS   r   rX   r=   r   rN   re   rO   rf   r   r]   r'   r&   )
rR   rS   r   rS   rN   re   rO   rf   r'   r3   )__name__
__module____qualname____doc__r7   r
   rl   r   r   r   r   r   r   r   r   r   r   rj   r8   r.   r1   r1   6   s             #"&9A!&!&-1 $"&(,$()-7;6:.2/3"7;,0$(,0)-EI!%7( ( ( ( ( X(<  #"&9A!&!&-1 $"&(,$()-7;6:.2/3"7;,0$(,0)-EI5* * * * * X*<  #"&9A!&!&-1 $)-7;6:.2/359,0"$(,0)-EI!%1( ( ( ( ( X(6  #"&9A!&!&-1 $)-7;6:.2/359,0"$(,0)-EI/* * * * * X*@ #"&9A!&!&-1 $"&(,$()-7;6:.2/359"7;,0$(,0)-EI(,!%;b b b b b bH  #"&9A!&!&-1)- $"&7;6:"59,0$(,0)-EI-     X2  #"&9A!&!&-1 $"&(,$()-7;6:"7;,0$(,0)-EI1     X@ #"&9A!&!&-1 $"&(,$()-7;6:"7;,059$(,0)-EI(,5v
 v
 v
 v
 v
 v
x -1)-
 
 
 
 
 
"  #"&-1 $"&(,$()-7;6:"/37;,0$( ,0)-EI/3 3 3 3 3 X34  #"&-1 $"&)-7;6:"/359,0$( ,0)-EI+3 3 3 3 3 X3: #"&-1 $"&(,$()-7;6:"/3597;,0$( ,0)-EI(,3h h h h h h\ #'7;,0)-0
 0
 0
 0
 0
 0
n -1)-!
 !
 !
 !
 !
 !
P *,0)-8 8 8 8 8 8z !%(,.2*,0)-9
 9
 9
 9
 9
 9
@ -1)-#
 #
 #
 #
 #
 #
T &+@D,0)-$(9
 9
 9
 9
 9
 9
@ -1)- 
  
  
  
  
  
  
  
r8   r1   )r%   r&   r'   r(   ).r   
__future__r   builtinsr   collections.abcr   r   r   r   typingr   r	   r
   httpxlanggraph_sdk._async.httpr   langgraph_sdk._shared.utilitiesr   r   langgraph_sdk.schemar   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r/   r1   rj   r8   r.   <module>r      s   2 2 " " " " " "   F F F F F F F F F F F F ) ) ) ) ) ) ) ) ) )  0 0 0 0 0 0                                                        6   R
 R
 R
 R
 R
 R
 R
 R
 R
 R
r8   