
    -UiJ)             
         U d Z ddlmZ ddlZddlZddlZddlZ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ZddlZddlmZ ddl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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z=  ej|                  e?      Z@d	ZAd9d:d
ZB	 	 	 	 	 	 d;dZCd<dZD ej                  d      ZF	 	 	 	 d=dZGddddd	 	 	 	 	 	 	 	 	 d>dZH G d d      ZI G d d      ZJd?dZKd@dZL G d d      ZM G d d      ZN G d d      ZO G d d      ZP G d d       ZQddddd	 	 	 	 	 	 	 	 	 dAd"ZR G d# d!      ZS G d$ d%      ZTd?d&ZUd@d'ZV G d( d)      ZW G d* d+      ZX G d, d-      ZY G d. d/      ZZ G d0 d1      Z[dBd2Z\g Z]d3e^d4<   dCd5Z_ ej                  d67      dDd8       Zaedebeceeb   eeb   f   eceeb   eeb   eeb   eeb   f   ej                  f   Zey)Ea  The LangGraph client implementations connect to the LangGraph API.

This module provides both asynchronous ([get_client(url="http://localhost:2024"))](#get_client) or [LangGraphClient](#LangGraphClient))
and synchronous ([get_sync_client(url="http://localhost:2024"))](#get_sync_client) or [SyncLanggraphClient](#SyncLanggraphClient))
clients to interacting with the LangGraph API's core resources such as
Assistants, Threads, Runs, and Cron jobs, as well as its persistent
document Store.
    )annotationsN)AsyncIteratorIteratorSequence)AnyCallableLiteralOptionalUnionoverload)QueryParamTypes) All	AssistantAssistantSortByAssistantVersionCancelAction
CheckpointCommandConfigCronDisconnectModeGraphSchemaIfNotExistsItemJsonListNamespaceResponseMultitaskStrategyOnCompletionBehaviorOnConflictBehaviorRun	RunCreateRunCreateMetadata	RunStatusSearchItemsResponse	SortOrder
StreamMode
StreamPart	SubgraphsThreadThreadSortByThreadStateThreadStatusThreadUpdateStateResponse)
SSEDecoderaiter_lines_rawiter_lines_raw)	x-api-keyc                    | r| S dD ]L  }t        j                  | d      x}s|j                         j                  d      j                  d      c S  y)zGet the API key from the environment.
    Precedence:
        1. explicit argument
        2. LANGGRAPH_API_KEY
        3. LANGSMITH_API_KEY
        4. LANGCHAIN_API_KEY
    )	LANGGRAPH	LANGSMITH	LANGCHAIN_API_KEY"'N)osgetenvstrip)api_keyprefixenvs      p/home/jay/workspace/tools/ai-image-gen/jaaz-app/server/venv/lib/python3.12/site-packages/langgraph_sdk/client.py_get_api_keyr@   K   s]     9 5))vhh/003099;$$S)//445     c                    |xs i }t         D ]  }||v st        d| d       ddt        j                   i|}t	        |       } | r| |d<   |S )z1Combine api_key and custom user-provided headers.zCannot set reserved header 'r8   z
User-Agentzlanggraph-sdk-py/r1   )RESERVED_HEADERS
ValueErrorlanggraph_sdk__version__r@   )r<   custom_headersheaderheaderss       r?   _get_headersrJ   [   s     $)rN" G^#;F81EFFG
 	)-*C*C)DE
G 7#G&NrA   c                8   t        | d      r%t        | j                        r| j                         S t        | d      r%t        | j                        r| j                         S t	        | t
        t        f      rt        |       S t        dt        |        d      )N
model_dumpdictzObject of type z is not JSON serializable)
hasattrcallablerL   rM   
isinstanceset	frozensetlist	TypeErrortype)objs    r?   _orjson_defaultrW   o   sw    sL!hs~~&>~~	f	(388"4xxz	C#y)	*Cy/$s)4MNOOrA   z5(\/threads\/(?P<thread_id>.+))?\/runs\/(?P<run_id>.+)c                    | j                   j                  d      x}rFt        j                  |      x}r/t	        |j                  d      |j                  d      xs d      S y)z/Extract run metadata from the response headers.zContent-Locationrun_id	thread_idN)rY   rZ   )rI   get_RUN_METADATA_PATTERNsearchr"   group)responsecontent_locationmatchs      r?   _get_run_metadata_from_responserb      sh     %,,001CDDD&--.>??? ;;x(kk+.6$
 	

 rA   )urlr<   rI   timeoutLangGraphClientc           
        d}| gt         j                  j                  d      dk(  r* t               dd      }t        j                  |       d} n	 ddlm} d}  t               |d	      }|t        j                  d      }t        j                  | ||t        j                  |      nt        j                  dddd      t        ||            }t        |      S # t        $ r d
} Y w xY w)a  Get a LangGraphClient instance.

    Args:
        url: The URL of the LangGraph API.
        api_key: The API key. If not provided, it will be read from the environment.
            Precedence:
                1. explicit argument
                2. LANGGRAPH_API_KEY
                3. LANGSMITH_API_KEY
                4. LANGCHAIN_API_KEY
        headers: Optional custom headers
        timeout: Optional timeout configuration for the HTTP client.
            Accepts an httpx.Timeout instance, a float (seconds), or a tuple of timeouts.
            Tuple format is (connect, read, write, pool)
            If not provided, defaults to connect=5s, read=300s, write=300s, and pool=5s.

    Returns:
        LangGraphClient: The top-level client for accessing AssistantsClient,
        ThreadsClient, RunsClient, and CronClient.

    ???+ example "Example"

        ```python
        from langgraph_sdk import get_client

        # get top-level LangGraphClient
        client = get_client(url="http://localhost:8123")

        # example usage: client.<model>.<method_name>()
        assistants = await client.assistants.get(assistant_id="some_uuid")
        ```
    N$__LANGGRAPH_DEFER_LOOPBACK_TRANSPORTtruez/noauth)app	root_pathz
http://apir   )ri   )rj   http://localhost:8123   retries,  connectreadwritepoolbase_url	transportrd   rI   )r9   environr[   get_asgi_transport_registered_transportsappendlanggraph_api.serverri   	ExceptionhttpxAsyncHTTPTransportAsyncClientTimeoutrJ   re   )rc   r<   rI   rd   rw   ri   clients          r?   
get_clientr      s    P 59I
{::>>@AVK,*,KI")))4C.4"0.0	J	 ,,Q7	 " MM'"qs#AFWg.	F 6""  .-.s   C   C.-C.c                      e Zd ZdZddZy)re   a  Top-level client for LangGraph API.

    Attributes:
        assistants: Manages versioned configuration for your graphs.
        threads: Handles (potentially) multi-turn interactions, such as conversational threads.
        runs: Controls individual invocations of the graph.
        crons: Manages scheduled operations.
        store: Interfaces with persistent, shared data storage.
    c                (   t        |      | _        t        | j                        | _        t	        | j                        | _        t        | j                        | _        t        | j                        | _	        t        | j                        | _        y N)
HttpClienthttpAssistantsClient
assistantsThreadsClientthreads
RunsClientruns
CronClientcronsStoreClientstoreselfr   s     r?   __init__zLangGraphClient.__init__   s^    v&	*4995$TYY/tyy)			*
 +
rA   Nr   zhttpx.AsyncClientreturnNone__name__
__module____qualname____doc__r    rA   r?   re   re      s    ,rA   c                      e Zd ZdZddZdddd	 	 	 	 	 	 	 	 	 ddZddd	 	 	 	 	 	 	 	 	 ddZddd	 	 	 	 	 	 	 	 	 ddZddd	 	 	 	 	 	 	 	 	 dd	Zdddd
	 	 	 	 	 	 	 	 	 ddZ	ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
y)r   zHandle async requests to the LangGraph API.

    Adds additional error messaging & content handling above the
    provided httpx client.

    Attributes:
        client (httpx.AsyncClient): Underlying HTTPX async client.
    c                    || _         y r   r   r   s     r?   r   zHttpClient.__init__   	    rA   NparamsrI   on_responsec                 K   | j                   j                  |||       d{   }|r ||       	 |j                          t        |       d{   S 7 2# t        j                  $ rn}|j                          d{  7  j                         }t        j                  dk\  r|j                  |       |t        j                  d| |       |d}~ww xY w7 w)Send a GET request.r   rI   N      Error from langgraph-api: exc_info)r   r[   raise_for_statusr~   HTTPStatusErrorareaddecodesysversion_infoadd_noteloggererror_adecode_jsonr   pathr   rI   r   rebodys           r?   r[   zHttpClient.get   s      ++//$vw/GGN	  #1%%% H
 $$ 	'')OO++-D7*

4  G 9$@1MG	 &sK   "CACA CCCC,C?B ACCCrI   r   c               &  K   |t        |       d{   \  }}ni d}}|r|j                  |       | j                  j                  |||       d{   }|r ||       	 |j	                          t        |       d{   S 7 s7 4# t
        j                  $ rn}|j                          d{  7  j                         }	t        j                  dk\  r|j                  |	       |t        j                  d|	 |       |d}~ww xY w7 wzSend a POST request.NrA   rI   contentr   r   r   )_aencode_jsonupdater   postr   r~   r   r   r   r   r   r   r   r   r   
r   r   jsonrI   r   request_headersr   r   r   r   s
             r?   r   zHttpClient.post  s     -:4-@'@$OW')3WO""7+++""4'"RRN	  #1%%%% (A S
 $$ 	'')OO++-D7*

4  G 9$@1MG	 &s_   DBA DB	D$B 4DDD	DDD1B42ADDDc                 K   t        |       d{   \  }}|r|j                  |       | j                  j                  |||       d{   }|r ||       	 |j	                          t        |       d{   S 7 n7 4# t
        j                  $ rn}|j                          d{  7  j                         }	t        j                  dk\  r|j                  |	       |t        j                  d|	 |       |d}~ww xY w7 w)Send a PUT request.Nr   r   r   r   )r   r   r   putr   r~   r   r   r   r   r   r   r   r   r   r   s
             r?   r   zHttpClient.put,  s      *7t)<#< ""7+++//$/QQN	  #1%%% $= R
 $$ 	'')OO++-D7*

4  G 9$@1MG	 &^   D
B ;D
BD
B -D
;D<D
D
DD *B-+AD  DD
c                 K   t        |       d{   \  }}|r|j                  |       | j                  j                  |||       d{   }|r ||       	 |j	                          t        |       d{   S 7 n7 4# t
        j                  $ rn}|j                          d{  7  j                         }	t        j                  dk\  r|j                  |	       |t        j                  d|	 |       |d}~ww xY w7 w)Send a PATCH request.Nr   r   r   r   )r   r   r   patchr   r~   r   r   r   r   r   r   r   r   r   r   s
             r?   r   zHttpClient.patchF  s      *7t)<#< ""7+++##D/7#SSN	  #1%%% $= T
 $$ 	'')OO++-D7*

4  G 9$@1MG	 &r   r   rI   r   c                 K   | j                   j                  d|||       d{   }|r ||       	 |j                          y7  # t        j                  $ rn}|j                          d{  7  j                         }t        j                  dk\  r|j                  |       |t        j                  d| |       |d}~ww xY ww)Send a DELETE request.DELETEr   rI   Nr   r   r   )r   requestr   r~   r   r   r   r   r   r   r   r   r   r   r   rI   r   r   r   r   s           r?   deletezHttpClient.delete`  s      ++%%h4%QQN	 	 R
 $$ 	'')OO++-D7*

4  G 9$@1MG	s?   #CACA CC	C.A1/ACC		Cr   r   rI   r   c                K   t        |       d{   \  }}d|d<   d|d<   |r|j                  |       | j                  j                  |||||      4 d{   }	|r ||	       	 |	j	                          |	j                  j                  d
d      j!                  d      d   }d|vrt        j"                  d|      t%               }t'        |	      2 3 d{   }|j                  |j)                  d            }|-| 37 7 # t
        j                  $ rn}
|	j                          d{  7  j                         }t        j                  dk\  r|
j                  |       |
t        j                  d| |
	       |
d}
~
ww xY w7 6 ddd      d{  7   y# 1 d{  7  sw Y   yxY ww)zStream results using SSE.Ntext/event-streamAcceptno-storeCache-ControlrI   r   r   r   r   r   content-type ;r   JExpected response header Content-Type to contain 'text/event-stream', got    
)line)r   r   r   streamr   r~   r   r   r   r   r   r   r   r   rI   r[   	partitionTransportErrorr.   r/   rstripr   r   methodr   r   rI   r   r   r   resr   r   content_typedecoderr   sses                   r?   r   zHttpClient.streamv  s     *7t)<#< $7!+5(""7+;;%%D/76 & 
 	 	C $$& ;;??>2>HHMaPL",6**'*, 
 !lG-c2  dnn$++e*<n=?IE $=	 (( !iik))113##w.JJt$  LL#=dV!DqLQ 21	 	 	 	 	s   F>DAF>DF>F)*D:AF)FFF!$F)F)F>F>F#F6D97AFFF)FF)F>"F%#F>)F;/F20F;7F>r   
r   strr   Optional[QueryParamTypes]rI   Optional[dict[str, str]]r   *Optional[Callable[[httpx.Response], None]]r   r   
r   r   r   Optional[dict]rI   r   r   r   r   r   
r   r   r   rM   rI   r   r   r   r   r   
r   r   r   zOptional[Any]rI   r   r   r   r   r   )r   r   r   r   r   r   r   r   rI   r   r   r   r   AsyncIterator[StreamPart]r   r   r   r   r   r[   r   r   r   r   r   r   rA   r?   r   r      s    -1,0BF&& *	&
 *& @& 
&8 -1BF&& 	&
 *& @& 
&F -1BF&& 	&
 *& @& 
&> -1BF&& 	&
 *& @& 
&< #,0BF 	
 * @ 
6  $,0,0BF-- -
 - *- *- @- 
#-rA   r   c                  K   | i d fS t        j                         j                  d t        j                  | t
        t        j                  t        j                  z         d {   }t        t        |            }d}||d}||fS 7 #wNzapplication/json)zContent-LengthzContent-Type)
asyncioget_running_looprun_in_executororjsondumpsrW   OPT_SERIALIZE_NUMPYOPT_NON_STR_KEYSr   lenr   r   content_lengthr   rI   s        r?   r   r     s     |4x))+;;""V%<%<< D T^N%L!/NGD=s   A"B
$B%$B
c                   K   | j                          d {   }|r;t        j                         j                  d t        j
                  |       d {   S d S 7 C7 wr   )r   r   r   r   r   loadsr   r   s     r?   r   r     sT     ?D  &&(88v||TRR  Rs!   AA<AAAAc                     e Zd ZdZddZdd	 	 	 	 	 ddZddd	 	 	 	 	 	 	 ddZdd	 	 	 	 	 dd	Z	 	 ddd	 	 	 	 	 	 	 	 	 dd
Z	 dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	ddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
dd	 	 	 	 	 ddZdddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d dZ	 	 	 d!dd	 	 	 	 	 	 	 	 	 	 	 d"dZdd	 	 	 	 	 	 	 d#dZy)$r   a]  Client for managing assistants in LangGraph.

    This class provides methods to interact with assistants,
    which are versioned configurations of your graph.

    ???+ example "Example"

        ```python
        client = get_client(url="http://localhost:2024")
        assistant = await client.assistants.get("assistant_id_123")
        ```
    c                    || _         y r   r   r   r   s     r?   r   zAssistantsClient.__init__  	    	rA   NrI   c               ^   K   | j                   j                  d| |       d{   S 7 w)a  Get an assistant by ID.

        Args:
            assistant_id: The ID of the assistant to get.
            headers: Optional custom headers to include with the request.

        Returns:
            Assistant: Assistant Object.

        ???+ example "Example Usage"

            ```python
            assistant = await client.assistants.get(
                assistant_id="my_assistant_id"
            )
            print(assistant)
            ```

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

            {
                'assistant_id': 'my_assistant_id',
                'graph_id': 'agent',
                'created_at': '2024-06-25T17:10:33.109781+00:00',
                'updated_at': '2024-06-25T17:10:33.109781+00:00',
                'config': {},
                'metadata': {'created_by': 'system'},
                'version': 1,
                'name': 'my_assistant'
            }
            ```
        /assistants/r  Nr   r[   r   assistant_idrI   s      r?   r[   zAssistantsClient.get  s-     H YY]]\,#@']RRRR   $-+-FxrayrI   c               f   K   | j                   j                  d| dd|i|       d{   S 7 w)a  Get the graph of an assistant by ID.

        Args:
            assistant_id: The ID of the assistant to get the graph of.
            xray: Include graph representation of subgraphs. If an integer value is provided, only subgraphs with a depth less than or equal to the value will be included.
            headers: Optional custom headers to include with the request.

        Returns:
            Graph: The graph information for the assistant in JSON format.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            graph_info = await client.assistants.get_graph(
                assistant_id="my_assistant_id"
            )
            print(graph_info)
            ```

            ```shell

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

            {
                'nodes':
                    [
                        {'id': '__start__', 'type': 'schema', 'data': '__start__'},
                        {'id': '__end__', 'type': 'schema', 'data': '__end__'},
                        {'id': 'agent','type': 'runnable','data': {'id': ['langgraph', 'utils', 'RunnableCallable'],'name': 'agent'}},
                    ],
                'edges':
                    [
                        {'source': '__start__', 'target': 'agent'},
                        {'source': 'agent','target': '__end__'}
                    ]
            }
            ```


        r  /graphr  r   Nr  r   r  r  rI   s       r?   	get_graphzAssistantsClient.get_graph  sB     ` YY]]<./PW # 
 
 	
 
   (1/1c               `   K   | j                   j                  d| d|       d{   S 7 w)ac  Get the schemas of an assistant by ID.

        Args:
            assistant_id: The ID of the assistant to get the schema of.
            headers: Optional custom headers to include with the request.

        Returns:
            GraphSchema: The graph schema for the assistant.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            schema = await client.assistants.get_schemas(
                assistant_id="my_assistant_id"
            )
            print(schema)
            ```

            ```shell

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

            {
                'graph_id': 'agent',
                'state_schema':
                    {
                        'title': 'LangGraphInput',
                        '$ref': '#/definitions/AgentState',
                        'definitions':
                            {
                                'BaseMessage':
                                    {
                                        'title': 'BaseMessage',
                                        'description': 'Base abstract Message class. Messages are the inputs and outputs of ChatModels.',
                                        'type': 'object',
                                        'properties':
                                            {
                                             'content':
                                                {
                                                    'title': 'Content',
                                                    'anyOf': [
                                                        {'type': 'string'},
                                                        {'type': 'array','items': {'anyOf': [{'type': 'string'}, {'type': 'object'}]}}
                                                    ]
                                                },
                                            'additional_kwargs':
                                                {
                                                    'title': 'Additional Kwargs',
                                                    'type': 'object'
                                                },
                                            'response_metadata':
                                                {
                                                    'title': 'Response Metadata',
                                                    'type': 'object'
                                                },
                                            'type':
                                                {
                                                    'title': 'Type',
                                                    'type': 'string'
                                                },
                                            'name':
                                                {
                                                    'title': 'Name',
                                                    'type': 'string'
                                                },
                                            'id':
                                                {
                                                    'title': 'Id',
                                                    'type': 'string'
                                                }
                                            },
                                        'required': ['content', 'type']
                                    },
                                'AgentState':
                                    {
                                        'title': 'AgentState',
                                        'type': 'object',
                                        'properties':
                                            {
                                                'messages':
                                                    {
                                                        'title': 'Messages',
                                                        'type': 'array',
                                                        'items': {'$ref': '#/definitions/BaseMessage'}
                                                    }
                                            },
                                        'required': ['messages']
                                    }
                            }
                    },
                'config_schema':
                    {
                        'title': 'Configurable',
                        'type': 'object',
                        'properties':
                            {
                                'model_name':
                                    {
                                        'title': 'Model Name',
                                        'enum': ['anthropic', 'openai'],
                                        'type': 'string'
                                    }
                            }
                    }
            }
            ```

        r  /schemasr  Nr  r  s      r?   get_schemaszAssistantsClient.get_schemas*  s;     ` YY]]<.17 # 
 
 	
 
s   %.,.c                  K   |.| j                   j                  d| d| d|i|       d{   S | j                   j                  d| dd|i|       d{   S 7 07 w)a  Get the schemas of an assistant by ID.

        Args:
            assistant_id: The ID of the assistant to get the schema of.
            namespace: Optional namespace to filter by.
            recurse: Whether to recursively get subgraphs.
            headers: Optional custom headers to include with the request.

        Returns:
            Subgraphs: The graph schema for the assistant.

        Nr  /subgraphs/recurser   
/subgraphsr  r   r  	namespacer!  rI   s        r?   get_subgraphszAssistantsClient.get_subgraphs  s     (  |nK	{C!7+ '    |nJ7!7+ '   s!   ,A#A+A#A!A#!A#metadatar  	if_existsnamerI   descriptionc                  K   d|i}	|r||	d<   |r||	d<   |r||	d<   |r||	d<   |r||	d<   |r||	d<   | j                   j                  d|	|	       d
{   S 7 w)a  Create a new assistant.

        Useful when graph is configurable and you want to create different assistants based on different configurations.

        Args:
            graph_id: The ID of the graph the assistant should use. The graph ID is normally set in your langgraph.json configuration.
            config: Configuration to use for the graph.
            metadata: Metadata to add to assistant.
            assistant_id: Assistant ID to use, will default to a random UUID if not provided.
            if_exists: How to handle duplicate creation. Defaults to 'raise' under the hood.
                Must be either 'raise' (raise error if duplicate), or 'do_nothing' (return existing assistant).
            name: The name of the assistant. Defaults to 'Untitled' under the hood.
            headers: Optional custom headers to include with the request.
            description: Optional description of the assistant.
                The description field is available for langgraph-api server version>=0.0.45

        Returns:
            Assistant: The created assistant.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            assistant = await client.assistants.create(
                graph_id="agent",
                config={"configurable": {"model_name": "openai"}},
                metadata={"number":1},
                assistant_id="my-assistant-id",
                if_exists="do_nothing",
                name="my_name"
            )
            ```
        graph_idconfigr'  r  r(  r)  r*  /assistantsr   Nr   r   
r   r,  r-  r'  r  r(  r)  rI   r*  payloads
             r?   createzAssistantsClient.create  s     \ #
  &GH"*GJ&2GN##,GK "GFO%0GM"YY^^M^QQQQs   AAAAr,  r-  r'  r)  rI   r*  c                  K   i }|r||d<   |r||d<   |r||d<   |r||d<   |r||d<   | j                   j                  d| ||       d{   S 7 w)	a  Update an assistant.

        Use this to point to a different graph, update the configuration, or change the metadata of an assistant.

        Args:
            assistant_id: Assistant to update.
            graph_id: The ID of the graph the assistant should use.
                The graph ID is normally set in your langgraph.json configuration. If None, assistant will keep pointing to same graph.
            config: Configuration to use for the graph.
            metadata: Metadata to merge with existing assistant metadata.
            name: The new name for the assistant.
            headers: Optional custom headers to include with the request.
            description: Optional description of the assistant.
                The description field is available for langgraph-api server version>=0.0.45

        Returns:
            Assistant: The updated assistant.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            assistant = await client.assistants.update(
                assistant_id='e280dad7-8618-443f-87f1-8e41841c180f',
                graph_id="other-graph",
                config={"configurable": {"model_name": "anthropic"}},
                metadata={"number":2}
            )
            ```

        r,  r-  r'  r)  r*  r  r   Nr   r   	r   r  r,  r-  r'  r)  rI   r*  r1  s	            r?   r   zAssistantsClient.update  s     T #%"*GJ &GH"*GJ"GFO%0GM"YY__<.) % 
 
 	
 
   A
AAAc               `   K   | j                   j                  d| |       d{    y7 w)a  Delete an assistant.

        Args:
            assistant_id: The assistant ID to delete.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            await client.assistants.delete(
                assistant_id="my_assistant_id"
            )
            ```

        r  r  Nr   r   r  s      r?   r   zAssistantsClient.delete8  s,     2 iil^<gNNN   $.,.
   r   )r'  r,  limitoffsetsort_by
sort_orderrI   c                  K   ||d}|r||d<   |r||d<   |r||d<   |r||d<   | j                   j                  d||       d{   S 7 w)	a  Search for assistants.

        Args:
            metadata: Metadata to filter by. Exact match filter for each KV pair.
            graph_id: The ID of the graph to filter by.
                The graph ID is normally set in your langgraph.json configuration.
            limit: The maximum number of results to return.
            offset: The number of results to skip.
            sort_by: The field to sort by.
            sort_order: The order to sort by.
            headers: Optional custom headers to include with the request.

        Returns:
            list[Assistant]: A list of assistants.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            assistants = await client.assistants.search(
                metadata = {"name":"my_name"},
                graph_id="my_graph_id",
                limit=5,
                offset=5
            )
            ```
        r<  r=  r'  r,  r>  r?  /assistants/searchr   Nr/  )	r   r'  r,  r<  r=  r>  r?  rI   r1  s	            r?   r]   zAssistantsClient.searchS  sy     N #
 "*GJ"*GJ!(GI$.GL!YY^^  $ 
 
 	
 
s   AAA
Ac               z   K   ||d}|r||d<   | j                   j                  d| d||       d{   S 7 w)a  List all versions of an assistant.

        Args:
            assistant_id: The assistant ID to get versions for.
            metadata: Metadata to filter versions by. Exact match filter for each KV pair.
            limit: The maximum number of versions to return.
            offset: The number of versions to skip.
            headers: Optional custom headers to include with the request.

        Returns:
            list[AssistantVersion]: A list of assistant versions.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            assistant_versions = await client.assistants.get_versions(
                assistant_id="my_assistant_id"
            )
            ```
        rA  r'  r  	/versionsr   Nr/  r   r  r'  r<  r=  rI   r1  s          r?   get_versionszAssistantsClient.get_versions  sY     @ #
 "*GJYY^^<.	2' $ 
 
 	
 
   2;9;c               j   K   d|i}| j                   j                  d| d||       d{   S 7 w)aP  Change the version of an assistant.

        Args:
            assistant_id: The assistant ID to delete.
            version: The version to change to.
            headers: Optional custom headers to include with the request.

        Returns:
            Assistant: Assistant Object.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            new_version_assistant = await client.assistants.set_latest(
                assistant_id="my_assistant_id",
                version=3
            )
            ```

        versionr  /latestr   Nr/  r   r  rI  rI   r1  s        r?   
set_latestzAssistantsClient.set_latest  sF     : $-g"6YY^^<.0w $ 
 
 	
 
s   *313r   r   r   r   r  r   rI   r   r   r   r  r   r  zUnion[int, bool]rI   r   r   zdict[str, list[dict[str, Any]]]r  r   rI   r   r   r   NF
r  r   r$  Optional[str]r!  boolrI   r   r   r(   r   r,  rS  r-  Optional[Config]r'  r   r  rS  r(  Optional[OnConflictBehavior]r)  rS  rI   r   r*  rS  r   r   r  r   r,  rS  r-  rV  r'  r   r)  rS  rI   r   r*  rS  r   r   r  r   rI   r   r   r   )r'  r   r,  rS  r<  intr=  rZ  r>  zOptional[AssistantSortBy]r?  Optional[SortOrder]rI   r   r   list[Assistant]Nr;  r   r  r   r'  r   r<  rZ  r=  rZ  rI   r   r   zlist[AssistantVersion]r  r   rI  rZ  rI   r   r   r   r   r   r   r   r   r[   r  r  r%  r2  r   r   r]   rF  rL  r   rA   r?   r   r     s    IM$S$S-E$S	$ST "',02
2
 	2

 *2
 
)2
j IMr
r
-Er
	r
n $(	 -1 ! 	 * 
H $(<R
 &*26",0%)<R<R !<R
 <R $<R 0<R <R *<R #<R 
<RD #'#'",0%)9
9
  	9

 !9
 9
 9
 *9
 #9
 
9
~ -1	OO *	O
 
O< "&-1*.,06
 6
  	6

 6
 6
 +6
 (6
 *6
 
6
v '
 -1'
'
 '
 	'

 '
 *'
 
 '
\ -1!
!
 !

 *!
 
!
rA   r   c            	      v   e Zd ZdZddZdd	 	 	 	 	 ddZddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdd	 	 	 	 	 	 	 ddZdd	 	 	 	 	 dd	Zdddd
ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	dd	 	 	 	 	 ddZ
	 	 dddd	 	 	 	 	 	 	 	 	 	 	 ddZddddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd
ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy) r   a  Client for managing threads in LangGraph.

    A thread maintains the state of a graph across multiple interactions/invocations (aka runs).
    It accumulates and persists the graph's state, allowing for continuity between separate
    invocations of the graph.

    ???+ example "Example"

        ```python
        client = get_client(url="http://localhost:2024"))
        new_thread = await client.threads.create(metadata={"user_id": "123"})
        ```
    c                    || _         y r   r  r  s     r?   r   zThreadsClient.__init__  r  rA   Nr  c               ^   K   | j                   j                  d| |       d{   S 7 w)aQ  Get a thread by ID.

        Args:
            thread_id: The ID of the thread to get.
            headers: Optional custom headers to include with the request.

        Returns:
            Thread: Thread object.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            thread = await client.threads.get(
                thread_id="my_thread_id"
            )
            print(thread)
            ```

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

            {
                'thread_id': 'my_thread_id',
                'created_at': '2024-07-18T18:35:15.540834+00:00',
                'updated_at': '2024-07-18T18:35:15.540834+00:00',
                'metadata': {'graph_id': 'agent'}
            }
            ```

        	/threads/r  Nr  r   rZ   rI   s      r?   r[   zThreadsClient.get  s-     F YY]]Yyk#:G]LLLLr  r'  rZ   r(  
superstepsr,  rI   c               D  K   i }|r||d<   |s|ri |xs i |rd|ini |d<   |r||d<   |rA|D 	cg c]0  }d|d   D 	cg c]  }	|	d   |	j                  d      |	d   d	 c}	i2 c}	}|d
<   | j                  j                  d||       d{   S c c}	w c c}	}w 7 w)ax  Create a new thread.

        Args:
            metadata: Metadata to add to thread.
            thread_id: ID of thread.
                If None, ID will be a randomly generated UUID.
            if_exists: How to handle duplicate creation. Defaults to 'raise' under the hood.
                Must be either 'raise' (raise error if duplicate), or 'do_nothing' (return existing thread).
            supersteps: Apply a list of supersteps when creating a thread, each containing a sequence of updates.
                Each update has `values` or `command` and `as_node`. Used for copying a thread between deployments.
            graph_id: Optional graph ID to associate with the thread.
            headers: Optional custom headers to include with the request.

        Returns:
            Thread: The created thread.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            thread = await client.threads.create(
                metadata={"number":1},
                thread_id="my-thread-id",
                if_exists="raise"
            )
            ```
        rZ   r,  r'  r(  updatesvaluescommandas_noderj  rk  rl  rg  /threadsr   Nr[   r   r   
r   r'  rZ   r(  rg  r,  rI   r1  sus
             r?   r2  zThreadsClient.create  s     J #%#,GK x#>r#-5J)2#GJ #,GK  $%   "#9  	 '(k'(uuY'7'(| 	%GL! YY^^JWg^NNN % Os3   /B B"B B&(B BB BB c               d   K   | j                   j                  d| d|i|       d{   S 7 w)a=  Update a thread.

        Args:
            thread_id: ID of thread to update.
            metadata: Metadata to merge with existing thread metadata.
            headers: Optional custom headers to include with the request.

        Returns:
            Thread: The created thread.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            thread = await client.threads.update(
                thread_id="my-thread-id",
                metadata={"number":1},
            )
            ```
        rd  r'  r   Nr5  r   rZ   r'  rI   s       r?   r   zThreadsClient.updateO  s?     6 YY__	{#:x*@' % 
 
 	
 
   '0.0c               `   K   | j                   j                  d| |       d{    y7 w)a  Delete a thread.

        Args:
            thread_id: The ID of the thread to delete.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost2024)
            await client.threads.delete(
                thread_id="my_thread_id"
            )
            ```

        rd  r  Nr9  re  s      r?   r   zThreadsClient.deleten  s,     , ii9+6HHHr:  r;  r   )r'  rj  statusr<  r=  r>  r?  rI   c                  K   ||d}	|r||	d<   |r||	d<   |r||	d<   |r||	d<   |r||	d<   | j                   j                  d|	|       d	{   S 7 w)
a  Search for threads.

        Args:
            metadata: Thread metadata to filter on.
            values: State values to filter on.
            status: Thread status to filter on.
                Must be one of 'idle', 'busy', 'interrupted' or 'error'.
            limit: Limit on number of threads to return.
            offset: Offset in threads table to start search from.
            sort_by: Sort by field.
            sort_order: Sort order.
            headers: Optional custom headers to include with the request.

        Returns:
            list[Thread]: List of the threads matching the search parameters.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            threads = await client.threads.search(
                metadata={"number":1},
                status="interrupted",
                limit=15,
                offset=5
            )
            ```

        rA  r'  rj  rw  r>  r?  /threads/searchr   Nr/  )
r   r'  rj  rw  r<  r=  r>  r?  rI   r1  s
             r?   r]   zThreadsClient.search  s     T #
 "*GJ &GH &GH!(GI$.GL!YY^^ $ 
 
 	
 
r7  c               b   K   | j                   j                  d| dd|       d{   S 7 w)a  Copy a thread.

        Args:
            thread_id: The ID of the thread to copy.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024)
            await client.threads.copy(
                thread_id="my_thread_id"
            )
            ```

        rd  /copyNr   r/  re  s      r?   copyzThreadsClient.copy  s<     , YY^^	{%(tW $ 
 
 	
 
s   &/-/F	subgraphsrI   c               ,  K   |r-| j                   j                  d| d||d|       d{   S |r.| j                   j                  d| d| d|i|       d{   S | j                   j                  d| d	d|i|       d{   S 7 `7 27 w)
a  Get the state of a thread.

        Args:
            thread_id: The ID of the thread to get the state of.
            checkpoint: The checkpoint to get the state of.
            checkpoint_id: (deprecated) The checkpoint ID to get the state of.
            subgraphs: Include subgraphs states.
            headers: Optional custom headers to include with the request.

        Returns:
            ThreadState: the thread of the state.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024)
            thread_state = await client.threads.get_state(
                thread_id="my_thread_id",
                checkpoint_id="my_checkpoint_id"
            )
            print(thread_state)
            ```

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

            {
                'values': {
                    '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
                        }
                    ]
                },
                'next': [],
                'checkpoint':
                    {
                        'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
                        'checkpoint_ns': '',
                        'checkpoint_id': '1ef4a9b8-e6fb-67b1-8001-abd5184439d1'
                    }
                'metadata':
                    {
                        'step': 1,
                        'run_id': '1ef4a9b8-d7da-679a-a45a-872054341df2',
                        'source': 'loop',
                        'writes':
                            {
                                'agent':
                                    {
                                        'messages': [
                                            {
                                                'id': 'run-159b782c-b679-4830-83c6-cef87798fe8b',
                                                'name': None,
                                                'type': 'ai',
                                                'content': "I'm doing well, thanks for asking! I'm an AI assistant created by Anthropic to be helpful, honest, and harmless.",
                                                'example': False,
                                                'tool_calls': [],
                                                'usage_metadata': None,
                                                'additional_kwargs': {},
                                                'response_metadata': {},
                                                'invalid_tool_calls': []
                                            }
                                        ]
                                    }
                            },
                'user_id': None,
                'graph_id': 'agent',
                'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
                'created_by': 'system',
                'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'},
                'created_at': '2024-07-25T15:35:44.184703+00:00',
                'parent_config':
                    {
                        'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
                        'checkpoint_ns': '',
                        'checkpoint_id': '1ef4a9b8-d80d-6fa7-8000-9300467fad0f'
                    }
            }
            ```
        rd  /state/checkpoint
checkpointr~  r   N/state/r~  r   /stater   r   r[   r   rZ   r  checkpoint_idr~  rI   s         r?   	get_statezThreadsClient.get_state  s     X I;&78$.YG (   
 I;gm_=#Y/ '    I;f-#Y/ '   s3   +BB/BB+B	B
BBBrl  r  r  rI   c                  K   d|i}|r||d<   |r||d<   |r||d<   | j                   j                  d| d||       d{   S 7 w)	a  Update the state of a thread.

        Args:
            thread_id: The ID of the thread to update.
            values: The values to update the state with.
            as_node: Update the state as if this node had just executed.
            checkpoint: The checkpoint to update the state of.
            checkpoint_id: (deprecated) The checkpoint ID to update the state of.
            headers: Optional custom headers to include with the request.

        Returns:
            ThreadUpdateStateResponse: Response after updating a thread's state.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024)
            response = await client.threads.update_state(
                thread_id="my_thread_id",
                values={"messages":[{"role": "user", "content": "hello!"}]},
                as_node="my_node",
            )
            print(response)
            ```
            ```shell

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

            {
                'checkpoint': {
                    'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
                    'checkpoint_ns': '',
                    'checkpoint_id': '1ef4a9b8-e6fb-67b1-8001-abd5184439d1',
                    'checkpoint_map': {}
                }
            }
            ```
        rj  r  r  rl  rd  r  r   Nr/  r   rZ   rj  rl  r  r  rI   r1  s           r?   update_statezThreadsClient.update_state\  sr     b f#
 '4GO$$.GL!!(GIYY^^	{&) $ 
 
 	
 
   ?AAAr<  beforer'  r  rI   c                  K   d|i}|r||d<   |r||d<   |r||d<   | j                   j                  d| d||       d{   S 7 w)	aB  Get the state history of a thread.

        Args:
            thread_id: The ID of the thread to get the state history for.
            checkpoint: Return states for this subgraph. If empty defaults to root.
            limit: The maximum number of states to return.
            before: Return states before this checkpoint.
            metadata: Filter states by metadata key-value pairs.
            headers: Optional custom headers to include with the request.

        Returns:
            list[ThreadState]: the state history of the thread.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024)
            thread_state = await client.threads.get_history(
                thread_id="my_thread_id",
                limit=5,
            )
            ```

        r<  r  r'  r  rd  /historyr   Nr/  r   rZ   r<  r  r'  r  rI   r1  s           r?   get_historyzThreadsClient.get_history  sr     F U#
  &GH"*GJ$.GL!YY^^	{(+'7 $ 
 
 	
 
r  rM  rZ   r   rI   r   r   r)   r'  r   rZ   rS  r(  rW  rg  z7Optional[Sequence[dict[str, Sequence[dict[str, Any]]]]]r,  rS  rI   r   r   r)   rZ   r   r'  dict[str, Any]rI   r   r   r)   rZ   r   rI   r   r   r   )r'  r   rj  r   rw  Optional[ThreadStatus]r<  rZ  r=  rZ  r>  zOptional[ThreadSortBy]r?  r[  rI   r   r   list[Thread]NNrZ   r   r  Optional[Checkpoint]r  rS  r~  rT  rI   r   r   r+   rZ   r   rj  z%Optional[Union[dict, Sequence[dict]]]rl  rS  r  r  r  rS  rI   r   r   r-   rZ   r   r<  rZ  r  zOptional[str | Checkpoint]r'  r   r  r  rI   r   r   zlist[ThreadState]r   r   r   r   r   r[   r2  r   r   r]   r|  r  r  r  r   rA   r?   r   r     s    FJ#M#M*B#M	#MP #'26NR"&,0>O >O !	>O
 0>O L>O  >O *>O 
>OJ -1

 !	

 *
 

@ FJII*BI	I6 )-*.*.,0;
 ;
 	;

 ';
 ;
 ;
 (;
 (;
 *;
 
;
| FJ

*B
	
: ,0'+	}  ,0}} )} %	} } *} 
}H "&+/'+,0;
;
 6;

 ;
 );
 %;
 *;
 
#;
B -1#'+/,0-
-
 	-

 +-
 !-
 )-
 *-
 
-
rA   r   c                     e Zd ZdZd'd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       Zeddddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d)d	       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Zeddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+d       Zeddddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d,d       Zdddddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d-dZd.dZedddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d/d       Z	edddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d0d       Z	ddddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d1dZ	ddddd	 	 	 	 	 	 	 	 	 	 	 d2dZ
dd	 	 	 	 	 	 	 d3dZdd dd!	 	 	 	 	 	 	 	 	 	 	 d4d"Zdd	 	 	 	 	 	 	 d5d#Zddddd$	 	 	 	 	 	 	 	 	 	 	 	 	 d6d%Zdd	 	 	 	 	 	 	 d7d&Zy)8r   a  Client for managing runs in LangGraph.

    A run is a single assistant invocation with optional input, config, 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"})
        ```
    c                    || _         y r   r  r  s     r?   r   zRunsClient.__init__  r  rA   Nrj  F)inputrk  stream_modestream_subgraphsstream_resumabler'  r-  r  r  checkpoint_duringinterrupt_beforeinterrupt_afterfeedback_keyson_disconnectwebhookmultitask_strategyif_not_existsafter_secondsrI   on_run_createdc                    y r   r   )r   rZ   r  r  rk  r  r  r  r'  r-  r  r  r  r  r  r  r  r  r  r  r  rI   r  s                          r?   r   zRunsClient.stream  s    4 %(rA   r  rk  r  r  r  r'  r-  r  r  r  r  r  on_completionr  r  r  rI   r  c                    y r   r   r   rZ   r  r  rk  r  r  r  r'  r-  r  r  r  r  r  r  r  r  r  rI   r  s                        r?   r   zRunsClient.stream  s    0 %(rA   r  rk  r  r  r  r'  r-  r  r  r  r  r  r  r  r  r  r  r  r  rI   r  c          
        i d|d|r'|j                         D ci c]  \  }}|	|| c}}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                  j                  |d|j                         D ci c]  \  }}|	|| c}}|r|      S d      S c c}}w c c}}w )a2  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.
            checkpoint: The checkpoint to resume from.
            checkpoint_during: 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.
            on_run_created: Callback when a run is created.

        Returns:
            AsyncIterator[StreamPart]: 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"},
                config={"configurable": {"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)
            ```

        r  rk  Nr-  r'  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rd  /runs/streamc                8    rt        |       x}r	 |       yyyz)Callback function to handle the response.Nrb   r   r'  r  s     r?   r   z&RunsClient.stream.<locals>.on_response  &    /Ns/S#S8#Sx( $T~rA   POSTr   r   httpx.Responseitemsr   r   r   rZ   r  r  rk  r  r  r  r'  r-  r  r  r  r  r  r  r  r  r  r  r  r  rI   r  kvr1  endpointr   s                          `     r?   r   zRunsClient.stream  s   |
U
GN'--/C$!QQ]ACTX

 f
 
 ;
  0
  0
 L
  0
 
 ]
 w
 *
  ]!
"  !2#
$ !"4%
& ]'
( +**-
4 $ 	{,/ 		)
 yy#*==?D41aam!Q$D'5   
 	

 <@   
 	
A DF E   
C
C
 
C
+C
)r  rk  r  r  r  r'  r  r-  r  r  r  r  r  r  rI   r  c                  K   y wr   r   )r   rZ   r  r  rk  r  r  r  r'  r  r-  r  r  r  r  r  r  rI   r  s                      r?   r2  zRunsClient.create  s     ,    r  rk  r  r  r  r'  r-  r  r  r  r  r  r  r  r  r  rI   r  c                  K   y wr   r   r   rZ   r  r  rk  r  r  r  r'  r-  r  r  r  r  r  r  r  r  r  rI   r  s                        r?   r2  zRunsClient.create  s     0 r  )r  rk  r  r  r  r'  r-  r  r  r  r  r  r  r  r  r  r  rI   r  c                 K   i d|d|r'|j                         D ci c]  \  }}|	|| c}}ndd|d|d|d|	d|d	|d
|d|d|d|
d|d|d|d|d|d|i}|j                         D ci c]  \  }}|	|| }}}dfd}| j                  j                  |rd| dnd||r|nd       d{   S c c}}w c c}}w 7 w)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.
            checkpoint: The checkpoint to resume from.
            checkpoint_during: 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.

        Returns:
            Run: 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"},
                config={"configurable": {"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,
                                        'model_name': "openai",
                                        'assistant_id': 'my_assistant_id'
                                    }
                            },
                        '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'
            }
            ```
        r  rk  Nr  r  r  r-  r'  r  r  r  r  r  r  r  r  r  r  r  c                8    rt        |       x}r	 |       yyyr  r  r  s     r?   r   z&RunsClient.create.<locals>.on_responseb  r  rA   rd  /runsr   r  r  r   r   )r   rZ   r  r  rk  r  r  r  r'  r-  r  r  r  r  r  r  r  r  r  r  rI   r  r  r  r1  r   s                        `    r?   r2  zRunsClient.create  s    ~
U
GN'--/C$!QQ]ACTX

 ;
  0
  0
 f
 
 L
  0
 
 w
 *
 ]
   !2!
" !"4#
$ ]%
& ]'
( ])
, %,MMOEDAqq}1a4EE	)
 YY^^,5i	{%(7'54	 $ 
 
 	
5 D& F
s3   C
C
C
AC9
CC	7C CCc                   K   dd}|D cg c]
  } ||       }}| j                   j                  d|       d{   S c c}w 7 	w),Create a batch of stateless background runs.c                \    | j                         D ci c]  \  }}|	|| c}}S c c}}w r   r  r1  r  r  s      r?   filter_payloadz/RunsClient.create_batch.<locals>.filter_payloadq  (    %,]]_FTQAqDFFF   
((/runs/batch)r   Nr1  r!   r/  )r   payloadsr  r1  s       r?   create_batchzRunsClient.create_batchn  sJ     	G <DDN7+DDYY^^M^AAA EAs   	AA"AA
AT)r  rk  r'  r-  r  r  r  r  r  r  r  r  r  r  raise_errorrI   r  c                  K   y wr   r   )r   rZ   r  r  rk  r'  r-  r  r  r  r  r  r  r  r  r  r  r  rI   r  s                       r?   waitzRunsClient.waitw  s     . -0r  )r  rk  r'  r-  r  r  r  r  r  r  r  r  r  rI   r  c                  K   y wr   r   )r   rZ   r  r  rk  r'  r-  r  r  r  r  r  r  r  r  r  rI   r  s                     r?   r  zRunsClient.wait  s     * -0r  )r  rk  r'  r-  r  r  r  r  r  r  r  r  r  r  r  r  rI   r  c          	     \  K   i d|d|r'|j                         D ci c]  \  }}|	|| c}}ndd|d|d|d|
d|d	|d
|d|d|d|	d|d|d|d|}|d| dnd}dfd}| j                  j                  ||j                         D ci c]  \  }}|	|| c}}|r|nd       d{   }|r[t        |t              rKd|v rGt        |d   t              r4t        |d   j                  d       d|d   j                  d             |S c c}}w c c}}w 7 ow)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.
            checkpoint: The checkpoint to resume from.
            checkpoint_during: 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.

        Returns:
            Union[list[dict], dict[str, Any]]: 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"},
                config={"configurable": {"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
                    }
                ]
            }
            ```

        r  rk  Nr-  r'  r  r  r  r  r  r  r  r  r  r  r  r  rd  
/runs/waitc                8    rt        |       x}r	 |       yyyr  r  r  s     r?   r   z$RunsClient.wait.<locals>.on_response(  r  rA   r   	__error__r   z: messager  )r  r   r   rP   rM   r}   r[   )r   rZ   r  r  rk  r'  r-  r  r  r  r  r  r  r  r  r  r  r  r  rI   r  r  r  r1  r  r   r_   s                       `      r?   r  zRunsClient.wait  s    R
U
GN'--/C$!QQ]ACTX

 f
 
 L
  0
 
 w
 *
 ]
 !"4
  !2
 ]
  ]!
" ]#
$ ]%
* 2;1Fi	{*-L 		)
 #*==?D41aam!Q$D'54	 ( 
 
 8T*x'8K0$7K(,,W56b+9N9R9RS\9]8^_  S D8 E
s4   D,
D
D
A*D,
D$#D$(D,:D*;A0D,r;  r   )r<  r=  rw  rI   c               z   K   ||d}|||d<   | j                   j                  d| d||       d{   S 7 w)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.

        Returns:
            list[Run]: 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,
            )
            ```

        rA  Nrw  rd  r  r   r  )r   rZ   r<  r=  rw  rI   r   s          r?   rS   zRunsClient.list>  s\     D 
 %F8YY]]	{%( # 
 
 	
 
rG  r  c               d   K   | j                   j                  d| d| |       d{   S 7 w)a  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.

        Returns:
            Run: 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",
            )
            ```

        rd  /runs/r  Nr  r   rZ   rY   rI   s       r?   r[   zRunsClient.geti  s>     2 YY]]	{&17 # 
 
 	
 
ru  	interruptr  actionrI   c          
     z   K   | j                   j                  d| d| d|rdnd d| d|       d{   S 7 w)	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.

        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"
            )
            ```

        rd  r  /cancel?wait=   r   &action=Nr   r/  r   rZ   rY   r  r  rI   s         r?   cancelzRunsClient.cancel  sV     F YY^^	{&4aQ=OxX^W_` $ 
 
 	
 
rG  c               f   K   | j                   j                  d| d| d|       d{   S 7 w)a8  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.

        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"
            )
            ```

        rd  r  /joinr  Nr  r  s       r?   joinzRunsClient.join  s@     0 YY]]	{&6 # 
 
 	
 
r  )cancel_on_disconnectr  rI   last_event_idc               x    | j                   j                  d| d| dd||di |rd|ini |xs i xs 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.

        Returns:
            None

        ???+ 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)
            ```

        rd  r  /streamGET)r  r  Last-Event-IDNr   r   r   )r   rZ   rY   r  r  rI   r  s          r?   join_streamzRunsClient.join_stream  sm    N yy	{&8(<*7DO]3"=b     
 	
rA   c               f   K   | j                   j                  d| d| |       d{    y7 w)a  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.

        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"
            )
            ```

        rd  r  r  Nr9  r  s       r?   r   zRunsClient.delete 	  s2     0 ii9+VF8DgVVVs   '1/1rM  ).rZ   r   r  r   r  r   rk  Optional[Command]r  'Union[StreamMode, Sequence[StreamMode]]r  rT  r  rT  r'  r   r-  rV  r  r  r  rS  r  Optional[bool]r  #Optional[Union[All, Sequence[str]]]r  r  r  Optional[Sequence[str]]r  Optional[DisconnectMode]r  rS  r  Optional[MultitaskStrategy]r  Optional[IfNotExists]r  Optional[int]rI   r   r  -Optional[Callable[[RunCreateMetadata], None]]r   r   )*rZ   r   r  r   r  r   rk  r   r  r  r  rT  r  rT  r'  r   r-  rV  r  r  r  r  r  r  r  r  r  r  r  Optional[OnCompletionBehavior]r  r  r  rS  r  r  rI   r   r  r	  r   r   )0rZ   rS  r  r   r  r   rk  r   r  r  r  rT  r  rT  r'  r   r-  rV  r  r  r  rS  r  r  r  r  r  r  r  r  r  r  r  r
  r  rS  r  r  r  r  r  r  rI   r   r  r	  r   r   )&rZ   r   r  r   r  r   rk  r   r  r  r  rT  r  rT  r'  r   r  r  r-  rV  r  r  r  r  r  rS  r  r
  r  r  r  r  rI   r   r  r	  r   r    *rZ   r   r  r   r  r   rk  r   r  r  r  rT  r  rT  r'  r   r-  rV  r  r  r  rS  r  r  r  r  r  r  r  rS  r  r  r  r  r  r  rI   r   r  r	  r   r    ),rZ   rS  r  r   r  r   rk  r   r  r  r  rT  r  rT  r'  r   r-  rV  r  r  r  rS  r  r  r  r  r  r  r  rS  r  r  r  r  r  r
  r  r  rI   r   r  r	  r   r    )r  list[RunCreate]r   	list[Run])(rZ   r   r  r   r  r   rk  r   r'  r   r-  rV  r  r  r  rS  r  r  r  r  r  r  r  rS  r  r  r  r  r  r  r  r  r  rT  rI   r   r  r	  r   !Union[list[dict], dict[str, Any]])$rZ   r   r  r   r  r   rk  r   r'  r   r-  rV  r  r  r  r  r  r  r  rS  r  r  r  r
  r  r  r  r  r  rT  rI   r   r  r	  r   r  )*rZ   rS  r  r   r  r   rk  r   r'  r   r-  rV  r  r  r  rS  r  r  r  r  r  r  r  rS  r  r  r  r
  r  r  r  r  r  r  r  rT  rI   r   r  r	  r   r  )rZ   r   r<  rZ  r=  rZ  rw  zOptional[RunStatus]rI   r   r   r  rZ   r   rY   r   rI   r   r   r    rZ   r   rY   r   r  rT  r  r   rI   r   r   r   rZ   r   rY   r   rI   r   r   rM   )rZ   r   rY   r   r  rT  r  1Optional[Union[StreamMode, Sequence[StreamMode]]]rI   r   r  rS  r   r   rZ   r   rY   r   rI   r   r   r   r   r   r   r   r   r   r   r2  r  r  rS   r[   r  r  r  r   r   rA   r?   r   r     s     !%%)?G!&!&#'#'+/'+,0@D?C1526!%:>/3'+,0HL1(( (
 ( #( =( ( ( !( !( )( %( *( >(  =!(" /#($ 0%(& '(( 8)(* -+(, %-(. */(0 F1(2 
#3( (6  !%%)?G!&!&#'#',0@D?C15268</3!%'+,0HL-(( (
 ( #( =( ( ( !( !( *( >( =( /(  0!(" 6#($ -%(& '(( %)(* *+(, F-(. 
#/( (< !%%)?G!&!&#'#'+/'+,0@D?C15268<!%:>/3'+,0HL3G
 G
 G

 G
 #G
 =G
 G
 G
 !G
 !G
 )G
 %G
 *G
 >G
  =!G
" /#G
$ 0%G
& 6'G
( )G
* 8+G
, --G
. %/G
0 *1G
2 F3G
4 
#5G
R  !%%)?G!&!&#',0#'@D?C!%8</3'+,0HL) 
  # =   ! * ! > =   6!" -#$ %%& *'( F)* 
+ .  !%%)?G!&!&#'#'+/'+,0@D?C!%:>/3'+,0HL- 
  # =   ! ! ) % * >  =!" #$ 8%& -'( %)* *+, F-. 
/ < !%%)?G!&!&#'#'+/'+,0@D?C!%:>/38<'+,0HL/a
 a
 a

 a
 #a
 =a
 a
 a
 !a
 !a
 )a
 %a
 *a
 >a
  =!a
" #a
$ 8%a
& -'a
( 6)a
* %+a
, *-a
. F/a
0 
1a
FB  !%%)#'#'+/'+,0@D?C!%26:>/3'+ ,0HL+00 0
 0 #0 !0 !0 )0 %0 *0 >0 =0 0 00  8!0" -#0$ %%0& '0( *)0* F+0, 
+-0 00  !%%)#'#',0@D?C!%268</3'+ ,0HL'00 0
 0 #0 !0 !0 *0 >0 =0 0 00 60 -0  %!0" #0$ *%0& F'0( 
+)0 06 !%%)#'#'+/'+,0@D?C!%268<:>/3'+ ,0HL-U U U
 U #U !U !U )U %U *U >U =U U 0U  6!U" 8#U$ -%U& %'U( )U* *+U, F-U. 
+/Uv &*,0)
)
 	)

 )
 $)
 *)
 
)
X SW

&)
7O
	
D *,0'
'
 '

 '
 '
 *'
 
'
T SW

&)
7O
	
B &+IM,0'+3
3
 3

 #3
 G3
 *3
 %3
 
#3
l SWWW&)W7OW	WrA   r   c            
          e Zd ZdZddZdddddddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdddddddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 ddZdddd	dd
	 	 	 	 	 	 	 	 	 	 	 ddZy)r   a  Client for managing recurrent runs (cron jobs) in LangGraph.

    A run is a single invocation of an assistant with optional input and config.
    This client allows scheduling recurring runs to occur automatically.

    ???+ example "Example Usage"

        ```python
        client = get_client(url="http://localhost:2024"))
        cron_job = await client.crons.create_for_thread(
            thread_id="thread_123",
            assistant_id="asst_456",
            schedule="0 9 * * *",
            input={"message": "Daily update"}
        )
        ```

    !!! note "Feature Availability"
        The crons client functionality is not supported on all licenses.
        Please check the relevant license documentation for the most up-to-date
        details on feature availability.
    c                    || _         y r   r  r   http_clients     r?   r   zCronClient.__init__3	  	    	rA   N	r  r'  r-  r  r  r  r  r  rI   c       
   
        K   ||||||||	|
d	}|r||d<   |j                         D ci c]  \  }}|	|| }}}| j                  j                  d| d||       d{   S c c}}w 7 
w)a  Create a cron job for a thread.

        Args:
            thread_id: the thread ID to run the cron job on.
            assistant_id: The assistant ID or graph name to use for the cron job.
                If using graph name, will default to first assistant created from that graph.
            schedule: The cron schedule to execute this job on.
            input: The input to the graph.
            metadata: Metadata to assign to the cron job runs.
            config: The configuration for the assistant.
            checkpoint_during: 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'.
            headers: Optional custom headers to include with the request.

        Returns:
            Run: The cron run.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            cron_run = await client.crons.create_for_thread(
                thread_id="my-thread-id",
                assistant_id="agent",
                schedule="27 15 * * *",
                input={"messages": [{"role": "user", "content": "hello!"}]},
                metadata={"name":"my_run"},
                config={"configurable": {"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"
            )
            ```
        	scheduler  r-  r'  r  r  r  r  r  r  Nrd  /runs/cronsr   r  )r   rZ   r  r  r  r'  r-  r  r  r  r  r  rI   r1  r  r  s                   r?   create_for_threadzCronClient.create_for_thread6	  s     t ! (!2 0.

 ,>G()$+MMOEDAqq}1a4EEYY^^	{+.Wg $ 
 
 	
 F
s    'A.
A&A&(A.!A,"A.c       
   
        K   |||||||||	d	}|
r|
|d<   |j                         D ci c]  \  }}|	|| }}}| j                  j                  d||       d{   S c c}}w 7 
w)a   Create a cron run.

        Args:
            assistant_id: The assistant ID or graph name to use for the cron job.
                If using graph name, will default to first assistant created from that graph.
            schedule: The cron schedule to execute this job on.
            input: The input to the graph.
            metadata: Metadata to assign to the cron job runs.
            config: The configuration for the assistant.
            checkpoint_during: 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'.
            headers: Optional custom headers to include with the request.

        Returns:
            Run: The cron run.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            cron_run = client.crons.create(
                assistant_id="agent",
                schedule="27 15 * * *",
                input={"messages": [{"role": "user", "content": "hello!"}]},
                metadata={"name":"my_run"},
                config={"configurable": {"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"
            )
            ```

        r  r  Nr  r   r  r   r  r  r  r'  r-  r  r  r  r  r  rI   r1  r  r  s                  r?   r2  zCronClient.create	  s     l ! (!2 0.

 ,>G()$+MMOEDAqq}1a4EEYY^^M^QQQ FQs    'A*
A"A"$A*A(A*c                `   K   | j                   j                  d| |       d{    y7 w)a  Delete a cron.

        Args:
            cron_id: The cron ID to delete.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            await client.crons.delete(
                cron_id="cron_to_delete"
            )
            ```

        /runs/crons/r  Nr9  r   cron_idrI   s      r?   r   zCronClient.delete	  s,     0 iigY7IIIr:  r;  r   r  rZ   r<  r=  rI   c                  K   ||||d}|j                         D ci c]  \  }}|	|| }}}| j                  j                  d||       d{   S c c}}w 7 
w)a  Get a list of cron jobs.

        Args:
            assistant_id: The assistant ID or graph name to search for.
            thread_id: the thread ID to search for.
            limit: The maximum number of results to return.
            offset: The number of results to skip.
            headers: Optional custom headers to include with the request.

        Returns:
            list[Cron]: The list of cron jobs returned by the search,

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            cron_jobs = await client.crons.search(
                assistant_id="my_assistant_id",
                thread_id="my_thread_id",
                limit=5,
                offset=5,
            )
            print(cron_jobs)
            ```
            ```shell

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

            [
                {
                    'cron_id': '1ef3cefa-4c09-6926-96d0-3dc97fd5e39b',
                    'assistant_id': 'my_assistant_id',
                    'thread_id': 'my_thread_id',
                    'user_id': None,
                    'payload':
                        {
                            'input': {'start_time': ''},
                            'schedule': '4 * * * *',
                            'assistant_id': 'my_assistant_id'
                        },
                    'schedule': '4 * * * *',
                    'next_run_date': '2024-07-25T17:04:00+00:00',
                    'end_time': None,
                    'created_at': '2024-07-08T06:02:23.073257+00:00',
                    'updated_at': '2024-07-08T06:02:23.073257+00:00'
                }
            ]
            ```

        r  rZ   r<  r=  N/runs/crons/searchr   r  	r   r  rZ   r<  r=  rI   r1  r  r  s	            r?   r]   zCronClient.search	  sj     x )"	
 %,MMOEDAqq}1a4EEYY^^$8wPW^XXX FXs    A
AA$AAA)r  r   r   r   )rZ   r   r  r   r  r   r  r   r'  r   r-  rV  r  r  r  Optional[Union[All, list[str]]]r  r+  r  rS  r  rS  rI   r   r   r    r  r   r  r   r  r   r'  r   r-  rV  r  r  r  r+  r  r+  r  rS  r  rS  rI   r   r   r    r   r%  r   rI   r   r   r   r  rS  rZ   rS  r<  rZ  r=  rZ  rI   r   r   z
list[Cron]	r   r   r   r   r   r  r2  r   r]   r   rA   r?   r   r   	  s   .  !%#'#',0<@;?!%,0,0I
I
 I

 I
 I
 !I
 !I
 *I
 :I
 9I
 I
 *I
 *I
 
I
` !%#'#',0<@;?!%,0,0CRCR 	CR
 CR !CR !CR *CR :CR 9CR CR *CR *CR 
CRP -1JJ *J 
	J: '+#',0BY $BY !	BY
 BY BY *BY 
BYrA   r   c                      e Zd ZdZd
dZ	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddd	 	 	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Z	y)r   a  Client for interacting with the graph's shared storage.

    The Store provides a key-value storage system for persisting data across graph executions,
    allowing for stateful operations and data sharing across threads.

    ???+ example "Example"

        ```python
        client = get_client(url="http://localhost:2024")
        await client.store.put_item(["users", "user123"], "mem-123451342", {"name": "Alice", "score": 100})
        ```
    c                    || _         y r   r  r  s     r?   r   zStoreClient.__init__3
  r  rA   Nc                  K   |D ]  }d|v st        d| d       |||||d}| j                  j                  dt        |      |       d{    y7 w)a  Store or update an item.

        Args:
            namespace: A list of strings representing the namespace path.
            key: The unique identifier for the item within the namespace.
            value: A dictionary containing the item's data.
            index: Controls search indexing - None (use defaults), False (disable), or list of field paths to index.
            ttl: Optional time-to-live in minutes for the item, or None for no expiration.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            await client.store.put_item(
                ["documents", "user123"],
                key="item456",
                value={"title": "My Document", "content": "Hello World"}
            )
            ```
        .Invalid namespace label '1'. Namespace labels cannot contain periods ('.').r$  keyvalueindexttl/store/itemsr   NrD   r   r   _provided_vals	r   r$  r7  r8  r9  r:  rI   labelr1  s	            r?   put_itemzStoreClient.put_item6
  s~     D  	Ee| /w6gh 	 #
 iimm!8'  
 	
 	
s   
AAAAArefresh_ttlrI   c                 K   |D ]  }d|v st        d| d       dj                  |      |d}|||d<   | j                  j                  d||       d{   S 7 w)	ay  Retrieve a single item.

        Args:
            key: The unique identifier for the item.
            namespace: Optional list of strings representing the namespace path.
            refresh_ttl: Whether to refresh the TTL on this read operation. If None, uses the store's default behavior.

        Returns:
            Item: The retrieved item.
            headers: Optional custom headers to include with the request.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            item = await client.store.get_item(
                ["documents", "user123"],
                key="item456",
            )
            print(item)
            ```
            ```shell

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

            {
                'namespace': ['documents', 'user123'],
                'key': 'item456',
                'value': {'title': 'My Document', 'content': 'Hello World'},
                'created_at': '2024-07-30T12:00:00Z',
                'updated_at': '2024-07-30T12:00:00Z'
            }
            ```
        r3  r4  r5  r$  r7  NrB  r;  r   rD   r  r   r[   r   r$  r7  rB  rI   r?  r   s          r?   get_itemzStoreClient.get_itemh
  s}     V  	Ee| /w6gh 	
  #xx	23?"$/F=!YY]]>&']RRRRs   
A AA AA c               b   K   | j                   j                  d||d|       d{    y7 w)a'  Delete an item.

        Args:
            key: The unique identifier for the item.
            namespace: Optional list of strings representing the namespace path.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            await client.store.delete_item(
                ["documents", "user123"],
                key="item456",
            )
            ```
        r;  rD  r   Nr9  r   r$  r7  rI   s       r?   delete_itemzStoreClient.delete_item
  s7     6 ii(5  
 	
 	
s   %/-/c               ~   K   ||||||d}| j                   j                  dt        |      |       d{   S 7 w)a  Search for items within a namespace prefix.

        Args:
            namespace_prefix: List of strings representing the namespace prefix.
            filter: Optional dictionary of key-value pairs to filter results.
            limit: Maximum number of items to return (default is 10).
            offset: Number of items to skip before returning results (default is 0).
            query: Optional query for natural language search.
            refresh_ttl: Whether to refresh the TTL on items returned by this search. If None, uses the store's default behavior.
            headers: Optional custom headers to include with the request.

        Returns:
            list[Item]: A list of items matching the search criteria.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            items = await client.store.search_items(
                ["documents"],
                filter={"author": "John Doe"},
                limit=5,
                offset=0
            )
            print(items)
            ```
            ```shell

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

            {
                "items": [
                    {
                        "namespace": ["documents", "user123"],
                        "key": "item789",
                        "value": {
                            "title": "Another Document",
                            "author": "John Doe"
                        },
                        "created_at": "2024-07-30T12:00:00Z",
                        "updated_at": "2024-07-30T12:00:00Z"
                    },
                    # ... additional items ...
                ]
            }
            ```
        namespace_prefixfilterr<  r=  queryrB  /store/items/searchr   Nr   r   r=  	r   rM  rN  r<  r=  rO  rB  rI   r1  s	            r?   search_itemszStoreClient.search_items
  sV     v !1&
 YY^^!( $ 
 
 	
 
s   4=;=c                |   K   |||||d}| j                   j                  dt        |      |       d{   S 7 w)a  List namespaces with optional match conditions.

        Args:
            prefix: Optional list of strings representing the prefix to filter namespaces.
            suffix: Optional list of strings representing the suffix to filter namespaces.
            max_depth: Optional integer specifying the maximum depth of namespaces to return.
            limit: Maximum number of namespaces to return (default is 100).
            offset: Number of namespaces to skip before returning results (default is 0).
            headers: Optional custom headers to include with the request.

        Returns:
            list[list[str]]: A list of namespaces matching the criteria.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            namespaces = await client.store.list_namespaces(
                prefix=["documents"],
                max_depth=3,
                limit=10,
                offset=0
            )
            print(namespaces)

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

            [
                ["documents", "user123", "reports"],
                ["documents", "user456", "invoices"],
                ...
            ]
            ```
        r=   suffix	max_depthr<  r=  /store/namespacesr   NrQ  r   r=   rV  rW  r<  r=  rI   r1  s           r?   list_namespaceszStoreClient.list_namespaces  sS     X "
 YY^^( $ 
 
 	
 
s   3<:<rM  NNNr7  r   r8  r  r9  z*Optional[Union[Literal[False], list[str]]]r:  r  rI   r   r$  Sequence[str]r   r   
r7  r   r$  r]  rB  r  rI   r   r   r   r   r7  r   rI   r   r$  r]  r   r   Nr;  r   NNNrN  zOptional[dict[str, Any]]r<  rZ  r=  rZ  rO  rS  rB  r  rI   r   rM  r]  r   r$   NNNd   r   Nr=   Optional[list[str]]rV  re  rW  r  r<  rZ  r=  rZ  rI   r   r   r   
r   r   r   r   r   r@  rG  rJ  rS  rZ  r   rA   r?   r   r   %
  s    =A!,00
 	0

 0
 :0
 0
 *0
 0
 
0
p '+,03S 	3S 3S $3S *3S 
3St -1
 	

 *
 
 

J ,0#&*,0G
 )	G

 G
 G
 G
 $G
 *G
'G
 
G
V '+&*#',06
#6
 $6
 !	6

 6
 6
 *6
 
6
rA   r   SyncLangGraphClientc           
         | d} t        j                  d      }t        j                  | ||t        j                  |      nt        j                  dddd      t	        ||            }t        |      S )a  Get a synchronous LangGraphClient instance.

    Args:
        url: The URL of the LangGraph API.
        api_key: The API key. If not provided, it will be read from the environment.
            Precedence:
                1. explicit argument
                2. LANGGRAPH_API_KEY
                3. LANGSMITH_API_KEY
                4. LANGCHAIN_API_KEY
        headers: Optional custom headers
        timeout: Optional timeout configuration for the HTTP client.
            Accepts an httpx.Timeout instance, a float (seconds), or a tuple of timeouts.
            Tuple format is (connect, read, write, pool)
            If not provided, defaults to connect=5s, read=300s, write=300s, and pool=5s.
    Returns:
        SyncLangGraphClient: The top-level synchronous client for accessing AssistantsClient,
        ThreadsClient, RunsClient, and CronClient.

    ???+ example "Example"

        ```python
        from langgraph_sdk import get_sync_client

        # get top-level synchronous LangGraphClient
        client = get_sync_client(url="http://localhost:8123")

        # example usage: client.<model>.<method_name>()
        assistant = client.assistants.get(assistant_id="some_uuid")
        ```
    rk   rl   rm   ro   rp   ru   )r~   HTTPTransportClientr   rJ   rg  )rc   r<   rI   rd   rw   r   s         r?   get_sync_clientrk  @  sr    N {%##A.I\\ " MM'"qs#AFWg.	F v&&rA   c                      e Zd ZdZddZy)rg  a~  Synchronous client for interacting with the LangGraph API.

    This class provides synchronous access to LangGraph API endpoints for managing
    assistants, threads, runs, cron jobs, and data storage.

    ???+ example "Example"

        ```python
        client = get_sync_client(url="http://localhost:2024")
        assistant = client.assistants.get("asst_123")
        ```
    c                (   t        |      | _        t        | j                        | _        t	        | j                        | _        t        | j                        | _        t        | j                        | _	        t        | j                        | _        y r   )SyncHttpClientr   SyncAssistantsClientr   SyncThreadsClientr   SyncRunsClientr   SyncCronClientr   SyncStoreClientr   r   s     r?   r   zSyncLangGraphClient.__init__  s^    "6*	.tyy9(3"499-	#DII.
$TYY/
rA   Nr   zhttpx.Clientr   r   r   r   rA   r?   rg  rg  x  s    0rA   c                      e Zd ZdZddZdddd	 	 	 	 	 	 	 	 	 ddZddd	 	 	 	 	 	 	 	 	 ddZddd	 	 	 	 	 	 	 	 	 ddZddd	 	 	 	 	 	 	 	 	 dd	Zdddd
	 	 	 	 	 	 	 	 	 ddZ	ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
y)rn  a8  Handle synchronous requests to the LangGraph API.

    Provides error messaging and content handling enhancements above the
    underlying httpx client, mirroring the interface of [HttpClient](#HttpClient)
    but for sync usage.

    Attributes:
        client (httpx.Client): Underlying HTTPX sync client.
    c                    || _         y r   r   r   s     r?   r   zSyncHttpClient.__init__  r   rA   Nr   c                  | j                   j                  |||      }|r ||       	 |j                          t        |      S # t        j                  $ re}|j                         j                         }t        j                  dk\  r|j                  |       |t        j                  d| |       |d}~ww xY w)r   r   r   r   r   N)r   r[   r   r~   r   rr   r   r   r   r   r   r   _decode_jsonr   s           r?   r[   zSyncHttpClient.get  s     KKOODOAN	  A $$ 	668??$D7*

4  G 9$@1MG	s   A B=A B88B=r   c                  |t        |      \  }}ni d}}|r|j                  |       | j                  j                  |||      }|r ||       	 |j	                          t        |      S # t
        j                  $ re}|j                         j                         }	t        j                  dk\  r|j                  |	       |t        j                  d|	 |       |d}~ww xY wr   )_encode_jsonr   r   r   r   r~   r   rr   r   r   r   r   r   r   rx  r   s
             r?   r   zSyncHttpClient.post  s     '3D'9$OW')3WO""7+KKT?GLN	  A $$ 	668??$D7*

4  G 9$@1MG	s   A- -C% A C  C%c                  t        |      \  }}|r|j                  |       | j                  j                  |||      }|r ||       	 |j	                          t        |      S # t
        j                  $ re}|j                         j                         }	t        j                  dk\  r|j                  |	       |t        j                  d|	 |       |d}~ww xY w)r   r   r   r   r   N)rz  r   r   r   r   r~   r   rr   r   r   r   r   r   r   rx  r   s
             r?   r   zSyncHttpClient.put  s     $0#5 ""7+KKOOD/7OKN	  A $$ 	668??$D7*

4  G 9$@1MG	   A& &C9A CCc                  t        |      \  }}|r|j                  |       | j                  j                  |||      }|r ||       	 |j	                          t        |      S # t
        j                  $ re}|j                         j                         }	t        j                  dk\  r|j                  |	       |t        j                  d|	 |       |d}~ww xY w)r   r   r   r   r   N)rz  r   r   r   r   r~   r   rr   r   r   r   r   r   r   rx  r   s
             r?   r   zSyncHttpClient.patch  s     $0#5 ""7+KKdOWMN	  A $$ 	668??$D7*

4  G 9$@1MG	r|  r   c               n   | j                   j                  d|||      }|r ||       	 |j                          y# t        j                  $ re}|j                         j                         }t        j                  dk\  r|j                  |       |t        j                  d| |       |d}~ww xY w)r   r   r   r   r   r   N)r   r   r   r~   r   rr   r   r   r   r   r   r   r   s           r?   r   zSyncHttpClient.delete  s     KK$T7KN	 $$ 	668??$D7*

4  G 9$@1MG	s   < B4A B//B4r   c             #    K   t        |      \  }}d|d<   d|d<   |r|j                  |       | j                  j                  |||||      5 }	|r ||	       	 |	j	                          |	j                  j                  d
d      j!                  d      d   }d|vrt        j"                  d|      t%               }t'        |	      D ])  }|j                  |j)                  d            }|&| + 	 d	d	d	       y	# t
        j                  $ re}
|	j                         j                         }t        j                  dk\  r|
j                  |       |
t        j                  d| |
       |
d	}
~
ww xY w# 1 sw Y   y	xY ww)z*Stream the results of a request using SSE.r   r   r   r   r   r   r   r   Nr   r   r   r   r   r   )rz  r   r   r   r   r~   r   rr   r   r   r   r   r   r   rI   r[   r   r   r.   r0   r   r   s                   r?   r   zSyncHttpClient.stream  s     $0#5 $7!+5(""7+[[D/76   
 	C $$& ;;??>2>HHMaPL",6**'*, 
 !lG&s+ nnT[[%78?I1	 	 (( 
**,##w.JJt$  LL#=dV!DqLQ	 	sJ   AFE:C?*BE:/E:6	F?E7A E22E77E::F?Frt  r   r   r   r   )r   r   r   r   r   r   r   r   rI   r   r   r   r   Iterator[StreamPart]r   r   rA   r?   rn  rn    s    -1,0BF *	
 * @ 
8 -1BF 	
 * @ 
D -1BF 	
 * @ 
@ -1BF 	
 * @ 
< #,0BF 	
 * @ 
6  $,0,0BF++ +
 + *+ *+ @+ 
+rA   rn  c                    t        j                  | t        t         j                  t         j                  z        }t        t        |            }d}||d}||fS r   )r   r   rW   r  r  r   r  r  s        r?   rz  rz  J  sR    <<""V%<%<<D
 T^N%L!/NGD=rA   c                T    | j                         }|rt        j                  |      S d S r   )rr   r   r  r  s     r?   rx  rx  V  s#    668D!%6<</4/rA   c                     e Zd ZdZddZdd	 	 	 	 	 ddZddd	 	 	 	 	 	 	 ddZdd	 	 	 	 	 dd	Z	 	 ddd	 	 	 	 	 	 	 	 	 dd
Z	 dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	ddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
dd	 	 	 	 	 ddZdddddd	 	 	 	 	 	 	 	 	 	 	 d dZ	 	 	 d!dd	 	 	 	 	 	 	 	 	 	 	 d"dZdd	 	 	 	 	 	 	 d#dZy)$ro  ag  Client for managing assistants in LangGraph synchronously.

    This class provides methods to interact with assistants, which are versioned configurations of your graph.

    ???+ example "Examples"

        ```python
        client = get_sync_client(url="http://localhost:2024")
        assistant = client.assistants.get("assistant_id_123")
        ```
    c                    || _         y r   r  r  s     r?   r   zSyncAssistantsClient.__init__h  r  rA   Nr  c               B    | j                   j                  d| |      S )a  Get an assistant by ID.

        Args:
            assistant_id: The ID of the assistant to get OR the name of the graph (to use the default assistant).
            headers: Optional custom headers to include with the request.

        Returns:
            Assistant: Assistant Object.

        ???+ example "Example Usage"

            ```python
            assistant = client.assistants.get(
                assistant_id="my_assistant_id"
            )
            print(assistant)
            ```

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

            {
                'assistant_id': 'my_assistant_id',
                'graph_id': 'agent',
                'created_at': '2024-06-25T17:10:33.109781+00:00',
                'updated_at': '2024-06-25T17:10:33.109781+00:00',
                'config': {},
                'metadata': {'created_by': 'system'}
            }
            ```

        r  r  r  r  s      r?   r[   zSyncAssistantsClient.getk  s#    L yy}}|L>:G}LLrA   Fr  c               J    | j                   j                  d| dd|i|      S )a  Get the graph of an assistant by ID.

        Args:
            assistant_id: The ID of the assistant to get the graph of.
            xray: Include graph representation of subgraphs. If an integer value is provided, only subgraphs with a depth less than or equal to the value will be included.
            headers: Optional custom headers to include with the request.

        Returns:
            Graph: The graph information for the assistant in JSON format.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            graph_info = client.assistants.get_graph(
                assistant_id="my_assistant_id"
            )
            print(graph_info)

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

            {
                'nodes':
                    [
                        {'id': '__start__', 'type': 'schema', 'data': '__start__'},
                        {'id': '__end__', 'type': 'schema', 'data': '__end__'},
                        {'id': 'agent','type': 'runnable','data': {'id': ['langgraph', 'utils', 'RunnableCallable'],'name': 'agent'}},
                    ],
                'edges':
                    [
                        {'source': '__start__', 'target': 'agent'},
                        {'source': 'agent','target': '__end__'}
                    ]
            }
            ```

        r  r  r  r   r  r  s       r?   r  zSyncAssistantsClient.get_graph  s4    X yy}}<./PW  
 	
rA   c               D    | j                   j                  d| d|      S )ab  Get the schemas of an assistant by ID.

        Args:
            assistant_id: The ID of the assistant to get the schema of.
            headers: Optional custom headers to include with the request.

        Returns:
            GraphSchema: The graph schema for the assistant.

        ???+ example "  Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            schema = client.assistants.get_schemas(
                assistant_id="my_assistant_id"
            )
            print(schema)
            ```
            ```shell
            ----------------------------------------------------------------------------------------------------------------------------

            {
                'graph_id': 'agent',
                'state_schema':
                    {
                        'title': 'LangGraphInput',
                        '$ref': '#/definitions/AgentState',
                        'definitions':
                            {
                                'BaseMessage':
                                    {
                                        'title': 'BaseMessage',
                                        'description': 'Base abstract Message class. Messages are the inputs and outputs of ChatModels.',
                                        'type': 'object',
                                        'properties':
                                            {
                                             'content':
                                                {
                                                    'title': 'Content',
                                                    'anyOf': [
                                                        {'type': 'string'},
                                                        {'type': 'array','items': {'anyOf': [{'type': 'string'}, {'type': 'object'}]}}
                                                    ]
                                                },
                                            'additional_kwargs':
                                                {
                                                    'title': 'Additional Kwargs',
                                                    'type': 'object'
                                                },
                                            'response_metadata':
                                                {
                                                    'title': 'Response Metadata',
                                                    'type': 'object'
                                                },
                                            'type':
                                                {
                                                    'title': 'Type',
                                                    'type': 'string'
                                                },
                                            'name':
                                                {
                                                    'title': 'Name',
                                                    'type': 'string'
                                                },
                                            'id':
                                                {
                                                    'title': 'Id',
                                                    'type': 'string'
                                                }
                                            },
                                        'required': ['content', 'type']
                                    },
                                'AgentState':
                                    {
                                        'title': 'AgentState',
                                        'type': 'object',
                                        'properties':
                                            {
                                                'messages':
                                                    {
                                                        'title': 'Messages',
                                                        'type': 'array',
                                                        'items': {'$ref': '#/definitions/BaseMessage'}
                                                    }
                                            },
                                        'required': ['messages']
                                    }
                            }
                    },
                'config_schema':
                    {
                        'title': 'Configurable',
                        'type': 'object',
                        'properties':
                            {
                                'model_name':
                                    {
                                        'title': 'Model Name',
                                        'enum': ['anthropic', 'openai'],
                                        'type': 'string'
                                    }
                            }
                    }
            }
            ```

        r  r  r  r  r  s      r?   r  z SyncAssistantsClient.get_schemas  s%    b yy}}|L>BG}TTrA   c                   |&| j                   j                  d| d| d|i|      S | j                   j                  d| dd|i|      S )a  Get the schemas of an assistant by ID.

        Args:
            assistant_id: The ID of the assistant to get the schema of.
            headers: Optional custom headers to include with the request.

        Returns:
            Subgraphs: The graph schema for the assistant.

        r  r   r!  r   r"  r  r#  s        r?   r%  z"SyncAssistantsClient.get_subgraphs6  sr    $  99==|nK	{C!7+ !   99==|nJ7!7+ !  rA   r&  c                   d|i}	|r||	d<   |r||	d<   |r||	d<   |r||	d<   |r||	d<   |r||	d<   | j                   j                  d|	|	      S )
a  Create a new assistant.

        Useful when graph is configurable and you want to create different assistants based on different configurations.

        Args:
            graph_id: The ID of the graph the assistant should use. The graph ID is normally set in your langgraph.json configuration.
            config: Configuration to use for the graph.
            metadata: Metadata to add to assistant.
            assistant_id: Assistant ID to use, will default to a random UUID if not provided.
            if_exists: How to handle duplicate creation. Defaults to 'raise' under the hood.
                Must be either 'raise' (raise error if duplicate), or 'do_nothing' (return existing assistant).
            name: The name of the assistant. Defaults to 'Untitled' under the hood.
            headers: Optional custom headers to include with the request.
            description: Optional description of the assistant.
                The description field is available for langgraph-api server version>=0.0.45

        Returns:
            Assistant: The created assistant.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            assistant = client.assistants.create(
                graph_id="agent",
                config={"configurable": {"model_name": "openai"}},
                metadata={"number":1},
                assistant_id="my-assistant-id",
                if_exists="do_nothing",
                name="my_name"
            )
            ```
        r,  r-  r'  r  r(  r)  r*  r.  r   r/  r0  s
             r?   r2  zSyncAssistantsClient.createU  sy    \ #
  &GH"*GJ&2GN##,GK "GFO%0GM"yy~~m'7~KKrA   r3  c                   i }|r||d<   |r||d<   |r||d<   |r||d<   |r||d<   | j                   j                  d| ||      S )a  Update an assistant.

        Use this to point to a different graph, update the configuration, or change the metadata of an assistant.

        Args:
            assistant_id: Assistant to update.
            graph_id: The ID of the graph the assistant should use.
                The graph ID is normally set in your langgraph.json configuration. If None, assistant will keep pointing to same graph.
            config: Configuration to use for the graph.
            metadata: Metadata to merge with existing assistant metadata.
            name: The new name for the assistant.
            headers: Optional custom headers to include with the request.
            description: Optional description of the assistant.
                The description field is available for langgraph-api server version>=0.0.45

        Returns:
            Assistant: The updated assistant.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            assistant = client.assistants.update(
                assistant_id='e280dad7-8618-443f-87f1-8e41841c180f',
                graph_id="other-graph",
                config={"configurable": {"model_name": "anthropic"}},
                metadata={"number":2}
            )
            ```
        r,  r-  r'  r)  r*  r  r   r5  r6  s	            r?   r   zSyncAssistantsClient.update  st    R #%"*GJ &GH"*GJ"GFO%0GM"yy<.)  
 	
rA   c               D    | j                   j                  d| |       y)a  Delete an assistant.

        Args:
            assistant_id: The assistant ID to delete.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            client.assistants.delete(
                assistant_id="my_assistant_id"
            )
            ```

        r  r  Nr9  r  s      r?   r   zSyncAssistantsClient.delete  s"    2 			<~6HrA   r;  r   )r'  r,  r<  r=  rI   c               d    ||d}|r||d<   |r||d<   | j                   j                  d||      S )ab  Search for assistants.

        Args:
            metadata: Metadata to filter by. Exact match filter for each KV pair.
            graph_id: The ID of the graph to filter by.
                The graph ID is normally set in your langgraph.json configuration.
            limit: The maximum number of results to return.
            offset: The number of results to skip.
            headers: Optional custom headers to include with the request.

        Returns:
            list[Assistant]: A list of assistants.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            assistants = client.assistants.search(
                metadata = {"name":"my_name"},
                graph_id="my_graph_id",
                limit=5,
                offset=5
            )
            ```
        rA  r'  r,  rB  r   r/  )r   r'  r,  r<  r=  rI   r1  s          r?   r]   zSyncAssistantsClient.search  sQ    F #
 "*GJ"*GJyy~~   
 	
rA   c               ^    ||d}|r||d<   | j                   j                  d| d||      S )a  List all versions of an assistant.

        Args:
            assistant_id: The assistant ID to get versions for.
            metadata: Metadata to filter versions by. Exact match filter for each KV pair.
            limit: The maximum number of versions to return.
            offset: The number of versions to skip.
            headers: Optional custom headers to include with the request.

        Returns:
            list[Assistant]: A list of assistants.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            assistant_versions = client.assistants.get_versions(
                assistant_id="my_assistant_id"
            )
            ```

        rA  r'  r  rD  r   r/  rE  s          r?   rF  z!SyncAssistantsClient.get_versions  sK    B #
 "*GJyy~~<.	2'  
 	
rA   c               N    d|i}| j                   j                  d| d||      S )aO  Change the version of an assistant.

        Args:
            assistant_id: The assistant ID to delete.
            version: The version to change to.
            headers: Optional custom headers to include with the request.

        Returns:
            Assistant: Assistant Object.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            new_version_assistant = client.assistants.set_latest(
                assistant_id="my_assistant_id",
                version=3
            )
            ```

        rI  r  rJ  r   r/  rK  s        r?   rL  zSyncAssistantsClient.set_latestB  s8    : $-g"6yy~~<.0w  
 	
rA   r   rn  r   r   rN  rO  rP  rQ  rR  r   rU  rX  rY  )r'  r   r,  rS  r<  rZ  r=  rZ  rI   r   r   r\  r]  r^  r_  r`  r   rA   r?   ro  ro  [  s   
 -1	&M&M *	&M
 
&MX "',0.
.
 	.

 *.
 
).
h -1	qUqU *	qU
 
qUl $(	 -1 ! 	 * 
D $(<L
 &*26",0%)<L<L !<L
 <L $<L 0<L <L *<L #<L 
<LD #'#'",0%)8
8
  	8

 !8
 8
 8
 *8
 #8
 
8
| -1	II *	I
 
I< "&,0.
 .
  	.

 .
 .
 *.
 
.
f (
 -1(
(
 (
 	(

 (
 *(
 
 (
^ -1!
!
 !

 *!
 
!
rA   ro  c                  j   e Zd ZdZddZdd	 	 	 	 	 ddZddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdd	 	 	 	 	 	 	 ddZdd	 	 	 	 	 dd	Zdddd
ddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	dd	 	 	 	 	 ddZ
	 	 dddd	 	 	 	 	 	 	 	 	 	 	 ddZddddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd
ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy) rp  a}  Synchronous client for managing threads in LangGraph.

    This class provides methods to create, retrieve, and manage threads,
    which represent conversations or stateful interactions.

    ???+ example "Example"

        ```python
        client = get_sync_client(url="http://localhost:2024")
        thread = client.threads.create(metadata={"user_id": "123"})
        ```
    c                    || _         y r   r  r  s     r?   r   zSyncThreadsClient.__init__t  r  rA   Nr  c               B    | j                   j                  d| |      S )aO  Get a thread by ID.

        Args:
            thread_id: The ID of the thread to get.
            headers: Optional custom headers to include with the request.

        Returns:
            Thread: Thread object.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            thread = client.threads.get(
                thread_id="my_thread_id"
            )
            print(thread)
            ```
            ```shell
            -----------------------------------------------------

            {
                'thread_id': 'my_thread_id',
                'created_at': '2024-07-18T18:35:15.540834+00:00',
                'updated_at': '2024-07-18T18:35:15.540834+00:00',
                'metadata': {'graph_id': 'agent'}
            }
            ```

        rd  r  r  re  s      r?   r[   zSyncThreadsClient.getw  s#    J yy}}y4g}FFrA   rf  c               (   i }|r||d<   |s|ri |xs i |rd|ini |d<   |r||d<   |rA|D 	cg c]0  }d|d   D 	cg c]  }	|	d   |	j                  d      |	d   d	 c}	i2 c}	}|d
<   | j                  j                  d||      S c c}	w c c}	}w )a  Create a new thread.

        Args:
            metadata: Metadata to add to thread.
            thread_id: ID of thread.
                If None, ID will be a randomly generated UUID.
            if_exists: How to handle duplicate creation. Defaults to 'raise' under the hood.
                Must be either 'raise' (raise error if duplicate), or 'do_nothing' (return existing thread).
            supersteps: Apply a list of supersteps when creating a thread, each containing a sequence of updates.
                Each update has `values` or `command` and `as_node`. Used for copying a thread between deployments.
            graph_id: Optional graph ID to associate with the thread.
            headers: Optional custom headers to include with the request.

        Returns:
            Thread: The created thread.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            thread = client.threads.create(
                metadata={"number":1},
                thread_id="my-thread-id",
                if_exists="raise"
            )
            ```
            )
        rZ   r,  r'  r(  ri  rj  rk  rl  rm  rg  rn  r   ro  rp  s
             r?   r2  zSyncThreadsClient.create  s    L #%#,GK x#>r#-5J)2#GJ #,GK  $%   "#9  	 '(k'(uuY'7'(| 	%GL! yy~~jw~HH %s   B"B	B	Bc               H    | j                   j                  d| d|i|      S )a<  Update a thread.

        Args:
            thread_id: ID of thread to update.
            metadata: Metadata to merge with existing thread metadata.
            headers: Optional custom headers to include with the request.

        Returns:
            Thread: The created thread.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            thread = client.threads.update(
                thread_id="my-thread-id",
                metadata={"number":1},
            )
            ```
        rd  r'  r   r5  rt  s       r?   r   zSyncThreadsClient.update  s1    6 yy	{#:x*@'  
 	
rA   c               D    | j                   j                  d| |       y)at  Delete a thread.

        Args:
            thread_id: The ID of the thread to delete.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client.threads.delete(
                thread_id="my_thread_id"
            )
            ```

        rd  r  Nr9  re  s      r?   r   zSyncThreadsClient.delete  s"    0 			9YK0'BrA   r;  r   )r'  rj  rw  r<  r=  rI   c               r    ||d}|r||d<   |r||d<   |r||d<   | j                   j                  d||      S )av  Search for threads.

        Args:
            metadata: Thread metadata to filter on.
            values: State values to filter on.
            status: Thread status to filter on.
                Must be one of 'idle', 'busy', 'interrupted' or 'error'.
            limit: Limit on number of threads to return.
            offset: Offset in threads table to start search from.
            headers: Optional custom headers to include with the request.

        Returns:
            list[Thread]: List of the threads matching the search parameters.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            threads = client.threads.search(
                metadata={"number":1},
                status="interrupted",
                limit=15,
                offset=5
            )
            ```
        rA  r'  rj  rw  ry  r   r/  )r   r'  rj  rw  r<  r=  rI   r1  s           r?   r]   zSyncThreadsClient.search  sU    J #
 "*GJ &GH &GHyy~~/gw~OOrA   c               F    | j                   j                  d| dd|      S )a  Copy a thread.

        Args:
            thread_id: The ID of the thread to copy.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            client.threads.copy(
                thread_id="my_thread_id"
            )
            ```

        rd  r{  Nr   r/  re  s      r?   r|  zSyncThreadsClient.copyH  s&    2 yy~~	)E:w~WWrA   Fr}  c                   |r%| j                   j                  d| d||d|      S |r&| j                   j                  d| d| d|i|      S | j                   j                  d| dd|i|      S )	ao  Get the state of a thread.

        Args:
            thread_id: The ID of the thread to get the state of.
            checkpoint: The checkpoint to get the state of.
            subgraphs: Include subgraphs states.
            headers: Optional custom headers to include with the request.

        Returns:
            ThreadState: the thread of the state.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            thread_state = client.threads.get_state(
                thread_id="my_thread_id",
                checkpoint_id="my_checkpoint_id"
            )
            print(thread_state)
            ```

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

            {
                'values': {
                    '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
                        }
                    ]
                },
                'next': [],
                'checkpoint':
                    {
                        'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
                        'checkpoint_ns': '',
                        'checkpoint_id': '1ef4a9b8-e6fb-67b1-8001-abd5184439d1'
                    }
                'metadata':
                    {
                        'step': 1,
                        'run_id': '1ef4a9b8-d7da-679a-a45a-872054341df2',
                        'source': 'loop',
                        'writes':
                            {
                                'agent':
                                    {
                                        'messages': [
                                            {
                                                'id': 'run-159b782c-b679-4830-83c6-cef87798fe8b',
                                                'name': None,
                                                'type': 'ai',
                                                'content': "I'm doing well, thanks for asking! I'm an AI assistant created by Anthropic to be helpful, honest, and harmless.",
                                                'example': False,
                                                'tool_calls': [],
                                                'usage_metadata': None,
                                                'additional_kwargs': {},
                                                'response_metadata': {},
                                                'invalid_tool_calls': []
                                            }
                                        ]
                                    }
                            },
                'user_id': None,
                'graph_id': 'agent',
                'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
                'created_by': 'system',
                'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'},
                'created_at': '2024-07-25T15:35:44.184703+00:00',
                'parent_config':
                    {
                        'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
                        'checkpoint_ns': '',
                        'checkpoint_id': '1ef4a9b8-d80d-6fa7-8000-9300467fad0f'
                    }
            }
            ```

        rd  r  r  r   r  r~  r   r  r  r  s         r?   r  zSyncThreadsClient.get_statec  s    X 99>>I;&78$.YG "  
 99==I;gm_=#Y/ !   99==I;f-#Y/ !  rA   r  c               x    d|i}|r||d<   |r||d<   |r||d<   | j                   j                  d| d||      S )a  Update the state of a thread.

        Args:
            thread_id: The ID of the thread to update.
            values: The values to update the state with.
            as_node: Update the state as if this node had just executed.
            checkpoint: The checkpoint to update the state of.
            headers: Optional custom headers to include with the request.

        Returns:
            ThreadUpdateStateResponse: Response after updating a thread's state.

        ???+ example "Example Usage"

            ```python

            response = await client.threads.update_state(
                thread_id="my_thread_id",
                values={"messages":[{"role": "user", "content": "hello!"}]},
                as_node="my_node",
            )
            print(response)

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

            {
                'checkpoint': {
                    'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
                    'checkpoint_ns': '',
                    'checkpoint_id': '1ef4a9b8-e6fb-67b1-8001-abd5184439d1',
                    'checkpoint_map': {}
                }
            }
            ```

        rj  r  r  rl  rd  r  r   r/  r  s           r?   r  zSyncThreadsClient.update_state  sd    ^ f#
 '4GO$$.GL!!(GIyy~~	{&)  
 	
rA   r  c               x    d|i}|r||d<   |r||d<   |r||d<   | j                   j                  d| d||      S )aT  Get the state history of a thread.

        Args:
            thread_id: The ID of the thread to get the state history for.
            checkpoint: Return states for this subgraph. If empty defaults to root.
            limit: The maximum number of states to return.
            before: Return states before this checkpoint.
            metadata: Filter states by metadata key-value pairs.
            headers: Optional custom headers to include with the request.

        Returns:
            list[ThreadState]: the state history of the thread.

        ???+ example "Example Usage"

            ```python

            thread_state = client.threads.get_history(
                thread_id="my_thread_id",
                limit=5,
                before="my_timestamp",
                metadata={"name":"my_name"}
            )
            ```

        r<  r  r'  r  rd  r  r   r/  r  s           r?   r  zSyncThreadsClient.get_history  sd    J U#
  &GH"*GJ$.GL!yy~~	{(+'7  
 	
rA   r  r  r  r  r  )r'  r   rj  r   rw  r  r<  rZ  r=  rZ  rI   r   r   r  r  r  r  r  r  r   rA   r?   rp  rp  f  s    -1	%G%G *	%G
 
%GT #'26NR"&,0?I ?I !	?I
 0?I L?I  ?I *?I 
?IL -1

 !	

 *
 

F -1	CC *	C
 
C: )-,0.P .P 	.P
 '.P .P .P *.P 
.Ph -1	XX *	X
 
X< ,0'+	}  ,0}} )} %	} } *} 
}H "&+/'+,09
9
 69

 9
 )9
 %9
 *9
 
#9
~ -1#'+/,0/
/
 	/

 +/
 !/
 )/
 */
 
/
rA   rp  c                     e Zd ZdZd&dZedddddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d'd       Zeddddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(d	       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Zeddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*d       Zeddddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+d       Zdddddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d,dZdd	 	 	 	 	 d-dZeddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d.d       Z	eddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d/d       Z	dddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d0dZ	dddd	 	 	 	 	 	 	 	 	 d1dZ
dd	 	 	 	 	 	 	 d2dZdddd 	 	 	 	 	 	 	 	 	 	 	 d3d!Zdd	 	 	 	 	 	 	 d4d"Zddddd#	 	 	 	 	 	 	 	 	 	 	 	 	 d5d$Zdd	 	 	 	 	 	 	 d6d%Zy)7rq  a~  Synchronous client for managing runs in LangGraph.

    This class provides methods to create, retrieve, and manage runs, which represent
    individual executions of graphs.

    ???+ example "Example"

        ```python
        client = get_sync_client(url="http://localhost:2024")
        run = client.runs.create(thread_id="thread_123", assistant_id="asst_456")
        ```
    c                    || _         y r   r  r  s     r?   r   zSyncRunsClient.__init__]  r  rA   Nrj  F)r  rk  r  r  r'  r-  r  r  r  r  r  r  r  r  r  r  r  rI   r  c                    y r   r   )r   rZ   r  r  rk  r  r  r'  r-  r  r  r  r  r  r  r  r  r  r  r  rI   r  s                         r?   r   zSyncRunsClient.stream`  s    2  #rA   r  c                    y r   r   r  s                        r?   r   zSyncRunsClient.stream{  s    0  #rA   r  c          
        i d|d|r'|j                         D ci c]  \  }}|	|| c}}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                  j                  |d|j                         D ci c]  \  }}|	|| c}}|r|      S d      S c c}}w c c}}w )aa  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: The command to execute.
            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.
            checkpoint: The checkpoint to resume from.
            checkpoint_during: 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.
            on_run_created: Optional callback to call when a run is created.

        Returns:
            Iterator[StreamPart]: Iterator of stream results.

        ???+ example "Example Usage"

            ```python
            client = get_sync_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"},
                config={"configurable": {"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)
            ```
        r  rk  Nr-  r'  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rd  r  c                8    rt        |       x}r	 |       yyyr  r  r  s     r?   r   z*SyncRunsClient.stream.<locals>.on_response  r  rA   r  r   r  r  r  s                          `     r?   r   zSyncRunsClient.stream  s   x
U
GN'--/C$!QQ]ACTX

 f
 
 ;
  0
  0
 L
  0
 
 ]
 w
 *
  ]!
"  !2#
$ !"4%
& ]'
( +**-
4 $ 	{,/ 		)
 yy#*==?D41aam!Q$D'5   
 	

 <@   
 	
A DF Er  )r  rk  r  r  r  r'  r-  r  r  r  r  r  r  r  rI   r  c                    y r   r   )r   rZ   r  r  rk  r  r  r  r'  r-  r  r  r  r  r  r  r  rI   r  s                      r?   r2  zSyncRunsClient.create  s    , rA   r  c                    y r   r   r  s                        r?   r2  zSyncRunsClient.create4  s    0 rA   )r  rk  r  r  r  r'  r-  r  r  r  r  r  r  r  r  r  r  rI   r  c                  i d|d|r'|j                         D ci c]  \  }}|	|| c}}ndd|d|d|d|	d|d	|d
|d|d|d|
d|d|d|d|d|d|i}|j                         D ci c]  \  }}|	|| }}}dfd}| j                  j                  |rd| dnd||r|      S d      S c c}}w c c}}w )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: The command to execute.
            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.
            checkpoint: The checkpoint to resume from.
            checkpoint_during: 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.

        Returns:
            Run: The created background run.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            background_run = client.runs.create(
                thread_id="my_thread_id",
                assistant_id="my_assistant_id",
                input={"messages": [{"role": "user", "content": "hello!"}]},
                metadata={"name":"my_run"},
                config={"configurable": {"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,
                                        'model_name': "openai",
                                        'assistant_id': 'my_assistant_id'
                                    }
                            },
                        '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'
            }
            ```
        r  rk  Nr  r  r  r-  r'  r  r  r  r  r  r  r  r  r  r  r  c                8    rt        |       x}r	 |       yyyr  r  r  s     r?   r   z*SyncRunsClient.create.<locals>.on_response  r  rA   rd  r  r   r  r  )r   rZ   r  r  rk  r  r  r  r'  r-  r  r  r  r  r  r  r  r  r  r  rI   r  r  r  r1  r   s                        `    r?   r2  zSyncRunsClient.createN  s   ~
U
GN'--/C$!QQ]ACTX

 ;
  0
  0
 f
 
 L
  0
 
 w
 *
 ]
   !2!
" !"4#
$ ]%
& ]'
( ])
, %,MMOEDAqq}1a4EE	)
 yy~~,5i	{%(7'5	  
 	
 <@	  
 	
5 D& Fs   
C 
C 
7
CCr  c               z    dd}|D cg c]
  } ||       }}| j                   j                  d||      S c c}w )r  c                \    | j                         D ci c]  \  }}|	|| c}}S c c}}w r   r  r  s      r?   r  z3SyncRunsClient.create_batch.<locals>.filter_payload  r  r  r  r   r  r/  )r   r  rI   r  r1  s        r?   r  zSyncRunsClient.create_batch  sB    
	G <DDN7+DDyy~~m(G~LL Es   8)r  rk  r'  r-  r  r  r  r  r  r  r  r  r  r  rI   r  c                    y r   r   )r   rZ   r  r  rk  r'  r-  r  r  r  r  r  r  r  r  r  r  rI   r  s                      r?   r  zSyncRunsClient.wait  s    , -0rA   )r  rk  r'  r-  r  r  r  r  r  r  r  r  rI   r  c                    y r   r   )r   rZ   r  r  rk  r'  r-  r  r  r  r  r  r  r  r  rI   r  s                    r?   r  zSyncRunsClient.wait  s    ( -0rA   )r  rk  r'  r-  r  r  r  r  r  r  r  r  r  r  r  rI   r  c          	        i d|d|r'|j                         D ci c]  \  }}|	|| c}}ndd|d|d|d|
d|d	|d
|d|	d|d|d|d|d|d|}dfd}|d| dnd}| j                  j                  ||j                         D ci c]  \  }}|	|| c}}|r|      S d      S c c}}w c c}}w )a8  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: The command to execute.
            metadata: Metadata to assign to the run.
            config: The configuration for the assistant.
            checkpoint: The checkpoint to resume from.
            checkpoint_during: 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.

        Returns:
            Union[list[dict], dict[str, Any]]: The output of the run.

        ???+ example "Example Usage"

            ```python

            final_state_of_run = client.runs.wait(
                thread_id=None,
                assistant_id="agent",
                input={"messages": [{"role": "user", "content": "how are you?"}]},
                metadata={"name":"my_run"},
                config={"configurable": {"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
                    }
                ]
            }
            ```

        r  rk  Nr-  r'  r  r  r  r  r  r  r  r  r  r  r  r  c                8    rt        |       x}r	 |       yyyr  r  r  s     r?   r   z(SyncRunsClient.wait.<locals>.on_response  r  rA   rd  r  r   r  r  )r   rZ   r  r  rk  r'  r-  r  r  r  r  r  r  r  r  r  r  r  rI   r  r  r  r1  r   r  s                      `     r?   r  zSyncRunsClient.wait*  st   R
U
GN'--/C$!QQ]ACTX

 f
 
 L
  0
 
 w
 *
 ]
 !"4
 ]
 ]
   !2!
" ]#
$ ]%
*	) 2;1Fi	{*-L 	 yy~~#*==?D41aam!Q$D'5	  
 	
 <@	  
 	
5 D8 Es   
B:
B:

C !C r;  r   )r<  r=  rI   c               N    | j                   j                  d| d| d| |      S )aj  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.
            headers: Optional custom headers to include with the request.

        Returns:
            list[Run]: The runs for the thread.

        ???+ example "Example Usage"

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

        rd  z/runs?limit=z&offset=r  r  )r   rZ   r<  r=  rI   s        r?   rS   zSyncRunsClient.list  s7    > yy}}	{,ugXfXFPW  
 	
rA   c               H    | j                   j                  d| d| |      S )a  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.

        Returns:
            Run: Run object.

        ???+ example "Example Usage"

            ```python

            run = client.runs.get(
                thread_id="thread_id_to_delete",
                run_id="run_id_to_delete",
            )
            ```
        rd  r  r  r  r  s       r?   r[   zSyncRunsClient.get  s(    8 yy}}y6&BG}TTrA   r  r  c          
     ^    | j                   j                  d| d| d|rdnd d| d|      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.

        Returns:
            None

        ???+ example "Example Usage"

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

        rd  r  r  r  r   r  Nr   r/  r  s         r?   r  zSyncRunsClient.cancel  sH    F yy~~	{&4aQ=OxX^W_`  
 	
rA   c               J    | j                   j                  d| d| d|      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.

        Returns:
            None

        ???+ example "Example Usage"

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

        rd  r  r  r  r  r  s       r?   r  zSyncRunsClient.join!  s2    8 yy}}	{&6  
 	
rA   )r  r  rI   r  c               x    | j                   j                  d| d| dd||di |rd|ini |xs i xs 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.
            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.
            cancel_on_disconnect: Whether to cancel the run when the stream is disconnected.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            client.runs.join_stream(
                thread_id="thread_id_to_join",
                run_id="run_id_to_join",
                stream_mode=["values", "debug"]
            )
            ```

        rd  r  r  r  )r  r  r  Nr   r  )r   rZ   rY   r  r  rI   r  s          r?   r  zSyncRunsClient.join_streamA  sm    L yy	{&8*(<7DO]3"=b     
 	
rA   c               J    | j                   j                  d| d| |       y)a  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.

        Returns:
            None

        ???+ example "Example Usage"

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

        rd  r  r  Nr9  r  s       r?   r   zSyncRunsClient.deleteu  s(    8 			9YKvfX>PrA   r  ),rZ   r   r  r   r  r   rk  r   r  r  r  rT  r'  r   r-  rV  r  r  r  rS  r  r  r  r  r  r  r  r  r  r  r  rS  r  r  r  r  r  r  rI   r   r  r	  r   r  )*rZ   r   r  r   r  r   rk  r   r  r  r  rT  r  rT  r'  r   r-  rV  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  rS  r  r  rI   r   r  r	  r   r  )0rZ   rS  r  r   r  r   rk  r   r  r  r  rT  r  rT  r'  r   r-  rV  r  r  r  rS  r  r  r  r  r  r  r  r  r  r  r  r
  r  rS  r  r  r  r  r  r  rI   r   r  r	  r   r  )&rZ   r   r  r   r  r   rk  r   r  r  r  rT  r  rT  r'  r   r-  rV  r  r  r  r  r  r  r  rS  r  r
  r  r  r  r  rI   r   r  r	  r   r    r  ),rZ   rS  r  r   r  r   rk  r   r  r  r  rT  r  rT  r'  r   r-  rV  r  r  r  rS  r  r  r  r  r  r  r  rS  r  r  r  r
  r  r  r  r  rI   r   r  r	  r   r    )r  r  rI   r   r   r  )&rZ   r   r  r   r  r   rk  r   r'  r   r-  rV  r  r  r  rS  r  r  r  r  r  r  r  rS  r  r  r  r  r  r  r  r  rI   r   r  r	  r   r  )"rZ   r   r  r   r  r   rk  r   r'  r   r-  rV  r  r  r  r  r  r  r  rS  r  r  r  r
  r  r  r  r  rI   r   r  r	  r   r  )(rZ   rS  r  r   r  r   rk  r   r'  r   r-  rV  r  r  r  r  r  rS  r  r  r  r  r  rS  r  r  r  r
  r  r  r  r  r  r  rI   r   r  r	  r   r  )
rZ   r   r<  rZ  r=  rZ  rI   r   r   r  r  r  r  )rZ   r   rY   r   r  r  r  rT  rI   r   r  rS  r   r  r  r  r   rA   r?   rq  rq  O  s     !%%)?G!&#'#'+/'+,0@D?C1526!%:>/3'+,0HL/## #
 # ## =# # !# !# )# %# *# ># =#  /!#" 0##$ %#& 8'#( -)#* %+#, *-#. F/#0 
1# #4  !%%)?G!&!&#'#',0@D?C15268</3!%'+,0HL-## #
 # ## =# # # !# !# *# ># =# /#  0!#" 6##$ -%#& '#( %)#* *+#, F-#. 
/# #< !%%)?G!&!&#'#'+/'+,0@D?C15268<!%:>/3'+,0HL3E
 E
 E

 E
 #E
 =E
 E
 E
 !E
 !E
 )E
 %E
 *E
 >E
  =!E
" /#E
$ 0%E
& 6'E
( )E
* 8+E
, --E
. %/E
0 *1E
2 F3E
4 
5E
N  !%%)?G!&!&#'#',0@D?C!%8</3'+,0HL) 
  # =   ! ! * > =   6!" -#$ %%& *'( F)* 
+ .  !%%)?G!&!&#'#'+/'+,0@D?C!%:>/3'+,0HL- 
  # =   ! ! ) % * >  =!" #$ 8%& -'( %)* *+, F-. 
/ < !%%)?G!&!&#'#'+/'+,0@D?C!%:>8</3'+,0HL/a
 a
 a

 a
 #a
 =a
 a
 a
 !a
 !a
 )a
 %a
 *a
 >a
  =!a
" #a
$ 8%a
& 6'a
( -)a
* %+a
, *-a
. F/a
0 
1a
H QU	M'	M5M	M		M  !%%)#'#'+/'+,0@D?C!%26:>/3'+,0HL)00 0
 0 #0 !0 !0 )0 %0 *0 >0 =0 0 00  8!0" -#0$ %%0& *'0( F)0* 
++0 0.  !%%)#'#',0@D?C!%268</3'+,0HL%00 0
 0 #0 !0 !0 *0 >0 =0 0 00 60 -0  %!0" *#0$ F%0& 
+'0 04 !%%)#'#',0+/'+@D?C!%268<:>/3'+,0HL+K
 K
 K

 K
 #K
 !K
 !K
 *K
 )K
 %K
 >K
 =K
 K
 0K
  6!K
" 8#K
$ -%K
& %'K
( *)K
* F+K
, 
+-K
b ,0!
!
 	!

 !
 *!
 
!
P -1UU U
 *U 
UF *,0'
'
 '

 '
 '
 *'
 
'
\ -1

 

 *
 

J JN%*,0'+2
2
 2

 G2
 #2
 *2
 %2
 
2
r -1QQ Q
 *Q 
QrA   rq  c            
          e Zd ZdZddZdddddddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdddddddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdd	 	 	 	 	 dd	Zddd
ddd	 	 	 	 	 	 	 	 	 	 	 ddZy)rr  a  Synchronous client for managing cron jobs in LangGraph.

    This class provides methods to create and manage scheduled tasks (cron jobs) for automated graph executions.

    ???+ example "Example"

        ```python
        client = get_sync_client(url="http://localhost:8123")
        cron_job = client.crons.create_for_thread(thread_id="thread_123", assistant_id="asst_456", schedule="0 * * * *")
        ```

    !!! note "Feature Availability"
        The crons client functionality is not supported on all licenses.
        Please check the relevant license documentation for the most up-to-date
        details on feature availability.
    c                    || _         y r   r  r  s     r?   r   zSyncCronClient.__init__  r  rA   N)	r  r'  r  r-  r  r  r  r  rI   c       
            |||||||	||
|d
}|j                         D ci c]  \  }}|	|| }}}| j                  j                  d| d||      S c c}}w )a  Create a cron job for a thread.

        Args:
            thread_id: the thread ID to run the cron job on.
            assistant_id: The assistant ID or graph name to use for the cron job.
                If using graph name, will default to first assistant created from that graph.
            schedule: The cron schedule to execute this job on.
            input: The input to the graph.
            metadata: Metadata to assign to the cron job runs.
            config: The configuration for the assistant.
            checkpoint_during: 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'.
            headers: Optional custom headers to include with the request.

        Returns:
            Run: The cron run.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:8123")
            cron_run = client.crons.create_for_thread(
                thread_id="my-thread-id",
                assistant_id="agent",
                schedule="27 15 * * *",
                input={"messages": [{"role": "user", "content": "hello!"}]},
                metadata={"name":"my_run"},
                config={"configurable": {"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"
            )
            ```
        )
r  r  r-  r'  r  r  r  r  r  r  rd  r  r   r  )r   rZ   r  r  r  r'  r  r-  r  r  r  r  rI   r1  r  r  s                   r?   r  z SyncCronClient.create_for_thread  s    p ! ( 0.!2"4
 %,MMOEDAqq}1a4EEyy~~	{+.Wg  
 	
 Fs
   
AAr  c       
            ||||||||	||
d
}|j                         D ci c]  \  }}|	|| }}}| j                  j                  d||      S c c}}w )a-  Create a cron run.

        Args:
            assistant_id: The assistant ID or graph name to use for the cron job.
                If using graph name, will default to first assistant created from that graph.
            schedule: The cron schedule to execute this job on.
            input: The input to the graph.
            metadata: Metadata to assign to the cron job runs.
            config: The configuration for the assistant.
            checkpoint_during: 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'.
            headers: Optional custom headers to include with the request.

        Returns:
            Run: The cron run.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:8123")
            cron_run = client.crons.create(
                assistant_id="agent",
                schedule="27 15 * * *",
                input={"messages": [{"role": "user", "content": "hello!"}]},
                metadata={"name":"my_run"},
                config={"configurable": {"model_name": "openai"}},
                checkpoint_during=True,
                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"
            )
            ```

        )
r  r  r-  r'  r  r  r  r  r  r  r  r   r  r!  s                  r?   r2  zSyncCronClient.create  sp    n ! ( 0.!2"4
 %,MMOEDAqq}1a4EEyy~~m'7~KK Fs
   
AAr  c               D    | j                   j                  d| |       y)a  Delete a cron.

        Args:
            cron_id: The cron ID to delete.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:8123")
            client.crons.delete(
                cron_id="cron_to_delete"
            )
            ```

        r#  r  Nr9  r$  s      r?   r   zSyncCronClient.delete6  s"    2 			<y17CrA   r;  r   r&  c                   ||||d}|j                         D ci c]  \  }}|	|| }}}| j                  j                  d||      S c c}}w )a  Get a list of cron jobs.

        Args:
            assistant_id: The assistant ID or graph name to search for.
            thread_id: the thread ID to search for.
            limit: The maximum number of results to return.
            offset: The number of results to skip.
            headers: Optional custom headers to include with the request.

        Returns:
            list[Cron]: The list of cron jobs returned by the search,

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:8123")
            cron_jobs = client.crons.search(
                assistant_id="my_assistant_id",
                thread_id="my_thread_id",
                limit=5,
                offset=5,
            )
            print(cron_jobs)
            ```

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

            [
                {
                    'cron_id': '1ef3cefa-4c09-6926-96d0-3dc97fd5e39b',
                    'assistant_id': 'my_assistant_id',
                    'thread_id': 'my_thread_id',
                    'user_id': None,
                    'payload':
                        {
                            'input': {'start_time': ''},
                            'schedule': '4 * * * *',
                            'assistant_id': 'my_assistant_id'
                        },
                    'schedule': '4 * * * *',
                    'next_run_date': '2024-07-25T17:04:00+00:00',
                    'end_time': None,
                    'created_at': '2024-07-08T06:02:23.073257+00:00',
                    'updated_at': '2024-07-08T06:02:23.073257+00:00'
                }
            ]
            ```
        r(  r)  r   r  r*  s	            r?   r]   zSyncCronClient.searchQ  s_    v )"	
 %,MMOEDAqq}1a4EEyy~~2'~RR Fs
   
AA)r  rn  r   r   )rZ   r   r  r   r  r   r  r   r'  r   r  r  r-  rV  r  r+  r  r+  r  rS  r  rS  rI   r   r   r    r,  r-  r.  r/  r   rA   r?   rr  rr    s   "  !%#',0#'<@;?!%,0,0F
F
 F

 F
 F
 !F
 *F
 !F
 :F
 9F
 F
 *F
 *F
 
F
Z !%#'#',0<@;?!%,0,0CLCL 	CL
 CL !CL !CL *CL :CL 9CL CL *CL *CL 
CLR -1	DD *	D
 
D< '+#',0AS $AS !	AS
 AS AS *AS 
ASrA   rr  c                      e Zd ZdZd
dZ	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddd	 	 	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Z	y)rs  a  A client for synchronous operations on a key-value store.

    Provides methods to interact with a remote key-value store, allowing
    storage and retrieval of items within namespaced hierarchies.

    ???+ example "Example"

        ```python
        client = get_sync_client(url="http://localhost:2024"))
        client.store.put_item(["users", "profiles"], "user123", {"name": "Alice", "age": 30})
        ```
    c                    || _         y r   r  r  s     r?   r   zSyncStoreClient.__init__  r  rA   Nc                   |D ]  }d|v st        d| d       |||||d}| j                  j                  dt        |      |       y)a  Store or update an item.

        Args:
            namespace: A list of strings representing the namespace path.
            key: The unique identifier for the item within the namespace.
            value: A dictionary containing the item's data.
            index: Controls search indexing - None (use defaults), False (disable), or list of field paths to index.
            ttl: Optional time-to-live in minutes for the item, or None for no expiration.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:8123")
            client.store.put_item(
                ["documents", "user123"],
                key="item456",
                value={"title": "My Document", "content": "Hello World"}
            )
            ```
        r3  r4  r5  r6  r;  r   Nr<  r>  s	            r?   r@  zSyncStoreClient.put_item  sj    D  	Ee| /w6gh 	 #
 			n>'+BGTrA   rA  c                  |D ]  }d|v st        d| d       |dj                  |      d}|||d<   | j                  j                  d||      S )ax  Retrieve a single item.

        Args:
            key: The unique identifier for the item.
            namespace: Optional list of strings representing the namespace path.
            refresh_ttl: Whether to refresh the TTL on this read operation. If None, uses the store's default behavior.
            headers: Optional custom headers to include with the request.

        Returns:
            Item: The retrieved item.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:8123")
            item = client.store.get_item(
                ["documents", "user123"],
                key="item456",
            )
            print(item)
            ```

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

            {
                'namespace': ['documents', 'user123'],
                'key': 'item456',
                'value': {'title': 'My Document', 'content': 'Hello World'},
                'created_at': '2024-07-30T12:00:00Z',
                'updated_at': '2024-07-30T12:00:00Z'
            }
            ```
        r3  r4  r5  r7  r$  rB  r;  r   rE  rF  s          r?   rG  zSyncStoreClient.get_item  ss    V  	Ee| /w6gh 	 388I+>?"$/F=!yy}}^FG}LLrA   c               F    | j                   j                  d||d|       y)a&  Delete an item.

        Args:
            key: The unique identifier for the item.
            namespace: Optional list of strings representing the namespace path.
            headers: Optional custom headers to include with the request.

        Returns:
            None

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:8123")
            client.store.delete_item(
                ["documents", "user123"],
                key="item456",
            )
            ```
        r;  r  r   Nr9  rI  s       r?   rJ  zSyncStoreClient.delete_item  s'    6 			9!Ew 	 	
rA   c               b    ||||||d}| j                   j                  dt        |      |      S )a  Search for items within a namespace prefix.

        Args:
            namespace_prefix: List of strings representing the namespace prefix.
            filter: Optional dictionary of key-value pairs to filter results.
            limit: Maximum number of items to return (default is 10).
            offset: Number of items to skip before returning results (default is 0).
            query: Optional query for natural language search.
            refresh_ttl: Whether to refresh the TTL on items returned by this search. If None, uses the store's default behavior.
            headers: Optional custom headers to include with the request.

        Returns:
            list[Item]: A list of items matching the search criteria.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:8123")
            items = client.store.search_items(
                ["documents"],
                filter={"author": "John Doe"},
                limit=5,
                offset=0
            )
            print(items)
            ```
            ```shell
            ----------------------------------------------------------------

            {
                "items": [
                    {
                        "namespace": ["documents", "user123"],
                        "key": "item789",
                        "value": {
                            "title": "Another Document",
                            "author": "John Doe"
                        },
                        "created_at": "2024-07-30T12:00:00Z",
                        "updated_at": "2024-07-30T12:00:00Z"
                    },
                    # ... additional items ...
                ]
            }
            ```
        rL  rP  r   rQ  rR  s	            r?   rS  zSyncStoreClient.search_items+  sF    t !1&
 yy~~!w(?  
 	
rA   c                `    |||||d}| j                   j                  dt        |      |      S )a  List namespaces with optional match conditions.

        Args:
            prefix: Optional list of strings representing the prefix to filter namespaces.
            suffix: Optional list of strings representing the suffix to filter namespaces.
            max_depth: Optional integer specifying the maximum depth of namespaces to return.
            limit: Maximum number of namespaces to return (default is 100).
            offset: Number of namespaces to skip before returning results (default is 0).
            headers: Optional custom headers to include with the request.

        Returns:
            list[list[str]]: A list of namespaces matching the criteria.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:8123")
            namespaces = client.store.list_namespaces(
                prefix=["documents"],
                max_depth=3,
                limit=10,
                offset=0
            )
            print(namespaces)
            ```

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

            [
                ["documents", "user123", "reports"],
                ["documents", "user456", "invoices"],
                ...
            ]
            ```
        rU  rX  r   rQ  rY  s           r?   rZ  zSyncStoreClient.list_namespacesp  sC    \ "
 yy~~nW&=w  
 	
rA   r  r[  r\  r^  r   r_  r`  ra  rb  rd  rf  r   rA   r?   rs  rs    s    =A!,0.U 	.U
 .U :.U .U *.U .U 
.Ul '+,04M 	4M 4M $4M *4M 
4Mv -1
 	

 *
 
 

F ,0#&*,0C
 )	C

 C
 C
 C
 $C
 *C
'C
 
C
N '+&*#',06
#6
 $6
 !	6

 6
 6
 *6
 
6
rA   rs  c                \    | j                         D ci c]  \  }}|	|| c}}S c c}}w r   r  )dr  r  s      r?   r=  r=    s(    WWY8TQ!-AqD888r  zlist[httpx.ASGITransport]rz   c                (    t         D ]	  }| |_         y r   )rz   ri   )ri   rw   s     r?   configure_loopback_transportsr    s    + 		rA   r  )maxsizec                 f    	 ddl m}  | j                  S # t        $ r t        j                  cY S w xY w)Nr   asgi_transport)langgraph_apir  ASGITransportImportErrorr~   r  s    r?   ry   ry     s1    #0+++ #"""#s    00r   )r<   rS  r   rS  )r<   rS  rG   r   r   zdict[str, str])rV   r   r   r   )r_   r  r   zOptional[RunCreateMetadata])
rc   rS  r<   rS  rI   r   rd   Optional[TimeoutTypes]r   re   )r   r   r   ztuple[dict[str, str], bytes])r   r  r   r   )
rc   rS  r<   rS  rI   r   rd   r  r   rg  )r  rM   )ri   r   r   r   )r   ztype[httpx.ASGITransport])fr   
__future__r   r   	functoolsloggingr9   rer   collections.abcr   r   r   typingr   r   r	   r
   r   r   r~   r   httpx._typesr   rE   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%   r&   r'   r(   r)   r*   r+   r,   r-   langgraph_sdk.sser.   r/   r0   	getLoggerr   r   rC   r@   rJ   rW   compiler\   rb   r   re   r   r   r   r   r   r   r   r   rk  rg  rn  rz  rx  ro  rp  rq  rr  rs  r=  rz   __annotations__r  	lru_cachery   floattupler   TimeoutTypesr   rA   r?   <module>r     s   #    	 	 
 = =    ( ! ! ! ! ! ! ! ! !D J I			8	$ "  ,D(P #

< 
 " !(,&*D#	D# D# &	D#
 $D# D#N, ,(y yx V
 V
rn
 n
bOW OWdGY GYTX
 X
z !(,&*5'	5' 5' &	5'
 $5' 5'p0 0.x xv	0
H
 H
Vf
 f
RBQ BQJ~S ~SBQ
 Q
h9 57 1 6
 Q#  # 		(5/8E?
*+	(5/8E?HUOXe_
LM	MM	rA   