
    <i             
      @   % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
JrJrJrJr  SSKJr  SSKJrJrJrJrJrJr  SSKrSSKrSSKrSSKJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@r@JArAJBrBJCrCJDrD  SSKEJFrFJGrGJHrH  \R                  " \J5      rKS	rLS9S:S
 jjrM      S;S jrNS<S jrO\R                  " S5      rQ    S=S jrRSSSSS.         S>S jjrS " S S5      rT " S S5      rUS?S jrVS@S jrW " S S5      rX " S S5      rY " S S5      rZ " S S5      r[ " S S 5      r\SSSSS.         SAS" jjr] " S# S!5      r^ " S$ S%5      r_SBS& jr`S@S' jra " S( S)5      rb " S* S+5      rc " S, S-5      rd " S. S/5      re " S0 S15      rfSCS2 jrg/ rhS3\iS4'   SDS5 jrj\R                  " S6S79SES8 j5       rl\S\m\n\\m   \\m   4   \n\\m   \\m   \\m   \\m   4   \R                  4   rpg)Fa  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MappingSequence)TracebackType)AnyCallableLiteralOptionalUnionoverload))All	AssistantAssistantSelectFieldAssistantSortByAssistantVersionCancelAction
CheckpointCommandConfigContextCronCronSelectField
CronSortByDisconnectMode
DurabilityGraphSchemaIfNotExistsItemJsonListNamespaceResponseMultitaskStrategyOnCompletionBehaviorOnConflictBehaviorQueryParamTypesRun	RunCreateRunCreateMetadataRunSelectField	RunStatusSearchItemsResponse	SortOrder
StreamMode
StreamPart	SubgraphsThreadThreadSelectFieldThreadSortByThreadStateThreadStatusThreadStreamModeThreadUpdateStateResponse)
SSEDecoderaiter_lines_rawiter_lines_raw)	x-api-keyc                    U (       a  U $ S HS  n[         R                  " U S35      =n(       d  M%  UR                  5       R                  S5      R                  S5      s  $    g)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      d/home/dmtnaga/Documents/work/airagagent/rag_env/lib/python3.13/site-packages/langgraph_sdk/client.py_get_api_keyrJ   U   sX     9))vhh/003099;$$S)//44 :     c                    U=(       d    0 n[          H  nX!;   d  M
  [        SU S35      e   SS[        R                   30UEn[	        U 5      n U (       a  XS'   U$ )z1Combine api_key and custom user-provided headers.zCannot set reserved header 'rB   z
User-Agentzlanggraph-sdk-py/r;   )RESERVED_HEADERS
ValueErrorlanggraph_sdk__version__rJ   )rF   custom_headersheaderheaderss       rI   _get_headersrT   e   st     $)rN"#;F81EFF #
 	)-*C*C)DE
G 7#G&NrK   c                j   [        U S5      (       a*  [        U R                  5      (       a  U R                  5       $ [        U S5      (       a*  [        U R                  5      (       a  U R                  5       $ [	        U [
        [        45      (       a  [        U 5      $ [        S[        U 5       S35      e)N
model_dumpdictzObject of type z is not JSON serializable)
hasattrcallablerV   rW   
isinstanceset	frozensetlist	TypeErrortype)objs    rI   _orjson_defaultra   y   s    sL!!hs~~&>&>~~	f		(388"4"4xxz	C#y)	*	*Cy/$s)4MNOOrK   z5(\/threads\/(?P<thread_id>.+))?\/runs\/(?P<run_id>.+)c                    U R                   R                  S5      =n(       aM  [        R                  U5      =n(       a1  [	        UR                  S5      UR                  S5      =(       d    SS9$ g)z/Extract run metadata from the response headers.zContent-Locationrun_id	thread_idN)rc   rd   )rS   get_RUN_METADATA_PATTERNsearchr)   group)responsecontent_locationmatchs      rI   _get_run_metadata_from_responserl      sh     %,,001CDDD&--.>??? ;;x(kk+.6$
 	

 rK   )urlrF   rS   timeoutLangGraphClientc                   SnU cb  [         R                  R                  S5      S:X  a'  [        5       " SSS9n[        R                  U5        Sn O SSKJn  Sn [        5       " USS	9nUc  [        R                  " SS9n[        R                  " U UUb  [        R                  " U5      O[        R                  " SSSSS9[        X5      S9n[        U5      $ ! [         a    S
n  N~f = f)uw  Create and configure a LangGraphClient.

The client provides programmatic access to a LangGraph Platform deployment. It supports
both remote servers and local in-process connections (when running inside a LangGraph server).

Args:
    url:
        Base URL of the LangGraph API.
        – If `None`, the client first attempts an in-process connection via ASGI transport.
          If that fails, it falls back to `http://localhost:8123`.
    api_key:
        API key for authentication. If omitted, the client reads from environment
        variables in the following order:
          1. Function argument
          2. `LANGGRAPH_API_KEY`
          3. `LANGSMITH_API_KEY`
          4. `LANGCHAIN_API_KEY`
    headers:
        Additional HTTP headers to include in requests. Merged with authentication headers.
    timeout:
        HTTP timeout configuration. May be:
          – `httpx.Timeout` instance
          – float (total seconds)
          – tuple `(connect, read, write, pool)` in seconds
        Defaults: connect=5, read=300, write=300, pool=5.

Returns:
    LangGraphClient:
        A top-level client exposing sub-clients for assistants, threads,
        runs, and cron operations.

???+ example "Connect to a remote server:"

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

???+ example "Connect in-process to a running LangGraph server:"

    ```python
    from langgraph_sdk import get_client

    client = get_client(url=None)

    async def my_node(...):
        subagent_result = await client.runs.wait(
            thread_id=None,
            assistant_id="agent",
            input={"messages": [{"role": "user", "content": "Foo"}]},
        )
    ```
N$__LANGGRAPH_DEFER_LOOPBACK_TRANSPORTtruez/noauth)app	root_pathz
http://apir   )rs   )rt   http://localhost:8123   retries,  connectreadwritepoolbase_url	transportrn   rS   )rC   environre   get_asgi_transport_registered_transportsappendlanggraph_api.serverrs   	ExceptionhttpxAsyncHTTPTransportAsyncClientTimeoutrT   ro   )rm   rF   rS   rn   r   rs   clients          rI   
get_clientr      s    D 26I
{::>>@AVK*,KI")))4C.4".0	J	 ,,Q7	 " MM'"qs#AFW.	F 6""  .-.s   C C'&C'c                  P    \ rS rSrSrS	S jrS
S jr        SS jrSS jrSr	g)ro      ak  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                (   [        U5      U l        [        U R                  5      U l        [	        U R                  5      U l        [        U R                  5      U l        [        U R                  5      U l	        [        U R                  5      U l        g N)
HttpClienthttpAssistantsClient
assistantsThreadsClientthreads
RunsClientruns
CronClientcronsStoreClientstoreselfr   s     rI   __init__LangGraphClient.__init__  s^    v&	*4995$TYY/tyy)			*
 +
rK   c                   #    U $ 7f)z Enter the async context manager. r   s    rI   
__aenter__LangGraphClient.__aenter__  s
     s   c                @   #    U R                  5       I Sh  vN   g N7f)zExit the async context manager.N)acloser   exc_typeexc_valexc_tbs       rI   	__aexit__LangGraphClient.__aexit__  s      kkms   c                   #    [        U S5      (       a-  U R                  R                  R                  5       I Sh  vN   gg N7fz!Close the underlying HTTP client.r   N)rX   r   r   r   r   s    rI   r   LangGraphClient.aclose  s6     4  ))""))+++ !+s   9AAAr   r   r   r   r   r   Nr   zhttpx.AsyncClientreturnNone)r   ro   r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | Noner   r   r   r   )
__name__
__module____qualname____firstlineno____doc__r   r   r   r   __static_attributes__r   rK   rI   ro   ro      sA    ,, & %	
 
,rK   c                  f   \ rS rSrSrSS jrSSSS.         SS jjrSSSS.           SS jjrSSSS.           SS jjrSSSS.           SS	 jjr	SSSSS
.           SS jjr
SSSSSS.               SS jjrSSSSS
.             SS jjrSrg)r   i   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                    Xl         g r   r   r   s     rI   r   HttpClient.__init__*      rK   NparamsrS   on_responsec                 #    U R                   R                  XUS9I Sh  vN nU(       a  U" U5         UR                  5         [        U5      I Sh  vN $  N7! [        R                   al  nUR                  5       I Sh  vN  R                  5       n[        R                  S:  a  UR                  U5        Ue[        R                  SU 3US9  UeSnAff = f N7f)Send a GET request.r   rS   N      Error from langgraph-api: exc_info)r   re   raise_for_statusr   HTTPStatusErrorareaddecodesysversion_infoadd_noteloggererror_adecode_jsonr   pathr   rS   r   rebodys           rI   re   HttpClient.get-  s      ++//$w/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c               .  #    Ub  [        U5      I Sh  vN u  pgO0 SpvU(       a  UR                  U5        U R                  R                  XXsS9I Sh  vN nU(       a  U" U5         UR	                  5         [        U5      I Sh  vN $  Nw N9! [
        R                   al  n	UR                  5       I Sh  vN  R                  5       n
[        R                  S:  a  U	R                  U
5        U	e[        R                  SU
 3U	S9  U	eSn	A	ff = f N7fzSend a POST request.NrK   rS   contentr   r   r   r   )_aencode_jsonupdater   postr   r   r   r   r   r   r   r   r   r   r   r   r   jsonr   rS   r   request_headersr   r   r   r   s              rI   r   HttpClient.postD  s     -:4-@'@$OW')3W""7+++""7 # 
 
 N	  #1%%%) (A
 $$ 	'')OO++-D7*

4  G 9$@1MG	 &s^   DB?DBD)B 9DDDDD$D7B:8ADDDc                  #    [        U5      I Sh  vN u  pgU(       a  UR                  U5        U R                  R                  XXsS9I Sh  vN nU(       a  U" U5         UR	                  5         [        U5      I Sh  vN $  Ns N9! [
        R                   al  n	UR                  5       I Sh  vN  R                  5       n
[        R                  S:  a  U	R                  U
5        U	e[        R                  SU
 3U	S9  U	eSn	A	ff = f N7f)Send a PUT request.Nr   r   r   r   )r   r   r   putr   r   r   r   r   r   r   r   r   r   r   r   s              rI   r   HttpClient.pute  s      *7t)<#< ""7+++//7 " 
 
 N	  #1%%%# $=
 $$ 	'')OO++-D7*

4  G 9$@1MG	 &^   DB;DBD"B	 2D DDD	D	D0B31ADD		Dc                  #    [        U5      I Sh  vN u  pgU(       a  UR                  U5        U R                  R                  XXsS9I Sh  vN nU(       a  U" U5         UR	                  5         [        U5      I Sh  vN $  Ns N9! [
        R                   al  n	UR                  5       I Sh  vN  R                  5       n
[        R                  S:  a  U	R                  U
5        U	e[        R                  SU
 3U	S9  U	eSn	A	ff = f N7f)Send a PATCH request.Nr   r   r   r   )r   r   r   patchr   r   r   r   r   r   r   r   r   r   r   r   s              rI   r   HttpClient.patch  s      *7t)<#< ""7+++##7 $ 
 
 N	  #1%%%# $=
 $$ 	'')OO++-D7*

4  G 9$@1MG	 &r   r   r   rS   r   c                 #    U R                   R                  SXX4S9I Sh  vN nU(       a  U" U5         UR                  5         g N%! [        R                   al  nUR                  5       I Sh  vN  R                  5       n[        R                  S:  a  UR                  U5        Ue[        R                  SU 3US9  UeSnAff = f7f)Send a DELETE request.DELETEr   r   rS   Nr   r   r   )r   requestr   r   r   r   r   r   r   r   r   r   	r   r   r   r   rS   r   r   r   r   s	            rI   deleteHttpClient.delete  s      ++%%df & 
 
 N	 
 $$ 	'')OO++-D7*

4  G 9$@1MG	s?   CACA	 C	C	C0A31ACC		Crv   r   r   rS   r   reconnect_limitc          	       #    [        U5      I Sh  vN u  pU(       a  UR                  U5        U R                  R                  X!XUS9 ISh  vN n
U(       a  U" U
5         U
R	                  5         U
R                  R                  S5      nUS::  d  U(       d$  [!        U
5      I Sh  vN sSSS5      ISh  vN   $  [!        U
5      I Sh  vN sSSS5      ISh  vN   $  N N! [
        R                   al  nU
R                  5       I Sh  vN  R                  5       n[        R                  S:  a  UR                  U5        Ue[        R                  SU 3US9  UeSnAff = f N N N N! [
        R"                   ad    [$        R&                  " SU 3S	S
9  U
R)                  5       I Sh  vN    U R+                  USUUS-
  S9I Sh  vN  s sSSS5      ISh  vN    $ f = f! , ISh  vN  (       d  f       g= f7f)@Send a request that automatically reconnects to Location header.Nr   r   r   r   locationr   2Request failed, attempting reconnect to Location:    
stacklevelGET   rS   r   )r   r   r   streamr   r   r   r   r   r   r   r   r   r   rS   re   r   	HTTPErrorwarningswarnr   request_reconnectr   r   methodr   r   rS   r   r   r   r   r   r   r   locs                 rI   r  HttpClient.request_reconnect  s     *7t)<#< ""7+;;%%/6 & 
 
A""$ ))--
+C!#3*1--!
 
 
"*1--%
 
 
 $=
 (( ggi//1##w.JJt$  LL#=dV!DqLQ .!
$ .%
& ?? HN  hhj  !33+$3a$7 4    3
 
 
&'
 
 
s  H	C%=H	C'H	G/$C)46G/*E,+G/.H	:E.;H	E4E0E4H	E2 H	'H	)E)=E$DAE$$E))G/.H	0E42H	4?G,3F64G,GG,G/H	$G'%H	+G,,G//H5G86HH	c                #    [        U5      I Sh  vN u  pxSUS'   SUS'   U(       a  UR                  U5        UR                  5        V	V
s0 s H  u  pU	R                  5       S;  d  M  X_M     nn	n
SnSnSnSn [	        Uc  UOU5      nUb  UUS
'   Uc  UOSnUc  UOSnUc  UOSnSnU R
                  R                  UU=(       d    UUUUS9 ISh  vN nUc  U(       a  U" U5         UR                  5         UR"                  R%                  SS5      R'                  S5      S   nSU;  a  [        R(                  " SU< 35      eUR"                  R%                  S5      nU(       a  Un[+        5       n [-        U5        Sh  vN nUR                  UR/                  S5      S9nUc  M,  UR0                  b  UR0                  nUR2                  (       d  UR4                  c  Me  U7v   Ml   GNs  sn
n	f  GN%! [        R                   al  nUR                  5       I Sh  vN  R                  5       n[        R                  S:  a  UR                  U5        Ue[        R!                  SU 3US9  UeSnAff = f N
 UR                  S5      =n(       a<  UR0                  b  UR0                  nUR2                  (       d  UR4                  b  U7v   O ! [        R6                   a	    Uc  e S	n Of = fSSS5      ISh  vN    O! , ISh  vN  (       d  f       O= fU(       a#  US-  nX:  a  [        R(                  " S5      eGM  g7f)zStream results using SSE.Ntext/event-streamAcceptno-storeCache-Control   content-typecontent-lengthr   rv   TLast-Event-IDr  Fr   r   r   r   r   ;JExpected response header Content-Type to contain 'text/event-stream', got r      
)linerK   r  *Exceeded maximum SSE reconnection attempts)r   r   itemslowerrW   r   r  r   r   r   r   r   r   r   r   r   r   rS   re   	partitionTransportErrorr8   r9   rstriplast_event_ideventdatar	  r   r   r  r   r   rS   r   r   r   keyvaluereconnect_headersr%  reconnect_pathreconnect_attemptsmax_reconnect_attemptscurrent_headerscurrent_methodcurrent_contentcurrent_paramsretryresr   r   content_typereconnect_locationdecoderr  sses                                rI   r  HttpClient.stream  s\     *7t)<#< $7!+5(""7+ .335
5
yy{"DD CJ5 	 
 %)%)!""#1#9?PO (3@0'5'=V5N)7)?gTO'5'=V4NE{{))&$''% *   !)k$((*  #{{~rBLLSQRST&l:..+.0 
 &)[[__Z%@"%%7N %,&&5c&: *d%nn$++e2DnE?&44@070E0E"yyCHH,@&)	M $=
. ,, "%))+--557D''72

4( G 'A$%HSTUG,*&: &nnS11s1"00<,3,A,AM99(<
 #&I  ! &- E!S     r "a'"%>..D  s   MG2;MG5+G51A%MG;ML.G>>A<L;KJ
JJ K25K+K2M5M>I>I9%H(&AI99I>>LJKALK63L5K66L9MLML"LL"2Mr   r   
r   strr   QueryParamTypes | NonerS   Mapping[str, str] | Noner   'Callable[[httpx.Response], None] | Noner   r	   r   r;  r   zdict[str, Any] | list | Noner   r<  rS   r=  r   r>  r   r	   r   r;  r   rW   r   r<  rS   r=  r   r>  r   r	   r   r;  r   z
Any | Noner   r<  rS   r=  r   r>  r   r   r   r;  r  r;  r   dict[str, Any] | Noner   r<  rS   r=  r   r>  r   intr   r	   )r   r;  r  r;  r   rC  r   r<  rS   r=  r   r>  r   AsyncIterator[StreamPart]r   r   r   r   r   r   re   r   r   r   r   r  r  r   r   rK   rI   r   r      sD    *.,0?C&& '	&
 *& =& 
&8 *.,0?C&& +	&
 '& *& =& 
&L *.,0?C&& 	&
 '& *& =& 
&D *.,0?C&& 	&
 '& *& =& 
&B  )-,0?C 	
 ' * = 
< '+)-,0?C .. .
 $. '. *. =. . 
.j '+)-,0?Cii i
 $i 'i *i =i 
#i irK   r   c                  #    U c  0 S 4$ [         R                  " 5       R                  S [        R                  U [
        [        R                  [        R                  -  5      I S h  vN n[        [        U5      5      nSnX#S.nXA4$  N!7fNzapplication/json)zContent-LengthzContent-Type)
asyncioget_running_looprun_in_executororjsondumpsra   OPT_SERIALIZE_NUMPYOPT_NON_STR_KEYSr;  lenr   r   content_lengthr5  rS   s        rI   r   r   T  s~     |4x))+;;""V%<%<< D T^N%L!/NG=s   A$B
&B'"B
c                   #    U R                  5       I S h  vN nU(       a<  [        R                  " 5       R                  S [        R
                  U5      I S h  vN $ S $  NI N7fr   )r   rI  rJ  rK  rL  loadsr   r   s     rI   r   r   d  sR     ?D  &&(88v||TRR  Rs"   A$A AA$A"A$"A$c            
      H   \ rS rSrSrSS jrSSS.       SS jjrSSSS.         SS	 jjrSSS.       SS
 jjr  SSSS.           SS jjjr	 S SSSSSSSSS.                     S!S jjjr
SSSSSSSSS.                   S"S jjrSSS.       S#S jjrSSSSSSSSSS.	                   S$S jjrSSSSS.         S%S jjr   S&SSS.             S'S jjjrSSS.         S(S jjrSrg))r   im  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                    Xl         g r   r   r   r   s     rI   r   AssistantsClient.__init__{      	rK   NrS   r   c               X   #    U R                   R                  SU 3X#S9I Sh  vN $  N7f)a6  Get an assistant by ID.

Args:
    assistant_id: The ID of the assistant to get.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters 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   re   r   assistant_idrS   r   s       rI   re   AssistantsClient.get~  s8     R YY]]<.)7 # 
 
 	
 
   !*(*FxrayrS   r   c                  #    SU0nU(       a  UR                  U5        U R                  R                  SU S3XSS9I Sh  vN $  N7f)aI  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.
    params: Optional query parameters 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__'}
            ]
    }
    ```


re  r^  /graphr   Nr   r   re   r   ra  re  rS   r   query_paramss         rI   	get_graphAssistantsClient.get_graph  sT     d ~'YY]]<./ # 
 
 	
 
s   >A AAc               Z   #    U R                   R                  SU S3X#S9I Sh  vN $  N7f)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.
    params: Optional query parameters 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']
                            }
                    }
            },
        'context_schema':
            {
                'title': 'Context',
                'type': 'object',
                'properties':
                    {
                        'model_name':
                            {
                                'title': 'Model Name',
                                'enum': ['anthropic', 'openai'],
                                'type': 'string'
                            }
                    }
            }
    }
    ```

r^  /schemasr\  Nr_  r`  s       rI   get_schemasAssistantsClient.get_schemas  s:     j YY]]<.17 # 
 
 	
 
s   "+)+c                  #    SU0nU(       a  0 UEUEnUb)  U R                   R                  SU SU 3UUS9I Sh  vN $ U R                   R                  SU S3UUS9I Sh  vN $  N+ N7f)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.
    params: Optional query parameters to include with the request.

Returns:
    Subgraphs: The graph schema for the assistant.

recurseNr^  /subgraphs/r   
/subgraphsr_  r   ra  	namespacerr  rS   r   
get_paramss          rI   get_subgraphsAssistantsClient.get_subgraphs^  s     ,  )
1J1&1J |nK	{C! '    |nJ7! '   s!   9A+A'&A+"A)#A+)A+contextmetadatara  	if_existsnamerS   descriptionr   c                  #    SU0nU(       a  X+S'   U(       a  X;S'   U(       a  XKS'   U(       a  X[S'   U(       a  XkS'   U(       a  X{S'   U	(       a  XS'   U R                   R                  S	XU
S
9I Sh  vN $  N7f)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.
    context: Static context to add to the assistant.
        !!! version-added "Supported with langgraph>=0.6.0"
    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
    params: Optional query parameters to include with the request.

Returns:
    Assistant: The created assistant.

???+ example "Example Usage"

    ```python
    client = get_client(url="http://localhost:2024")
    assistant = await client.assistants.create(
        graph_id="agent",
        context={"model_name": "openai"},
        metadata={"number":1},
        assistant_id="my-assistant-id",
        if_exists="do_nothing",
        name="my_name"
    )
    ```
graph_idconfigr{  r|  ra  r}  r~  r  /assistantsr   rS   r   Nr   r   r   r  r  r{  r|  ra  r}  r~  rS   r  r   payloads               rI   createAssistantsClient.create  s     f #
  &H!(I"*J&2N##,K "FO%0M"YY^^ $ 
 
 	
 
s   A0A92A73A9r  r  r{  r|  r~  rS   r  r   c                  #    0 n
U(       a  X*S'   U(       a  X:S'   U(       a  XJS'   U(       a  XZS'   U(       a  XjS'   U(       a  XS'   U R                   R                  SU 3U
UU	S9I S	h  vN $  N7f)
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.
    context: Static context to add to the assistant.
        !!! version-added "Supported with langgraph>=0.6.0"
    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
    params: Optional query parameters to include with the request.

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",
        context={"model_name": "anthropic"},
        metadata={"number":2}
    )
    ```

r  r  r{  r|  r~  r  r^  r  Nr   r   r   ra  r  r  r{  r|  r~  rS   r  r   r  s              rI   r   AssistantsClient.update  s     ^ #%"*J &H!(I"*J"FO%0M"YY__<.)	 % 
 
 	
 
s   A'A0)A.*A0c               Z   #    U R                   R                  SU 3X#S9I Sh  vN   g N7f)a  Delete an assistant.

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

Returns:
    None

???+ example "Example Usage"

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

r^  r\  Nr   r   r`  s       rI   r   AssistantsClient.delete  s4     6 ii<.)7  
 	
 	
   !+)+
   r   	r|  r  limitoffsetsort_by
sort_orderselectrS   r   c       	           #    UUS.n
U(       a  XS'   U(       a  X*S'   U(       a  XZS'   U(       a  XjS'   U(       a  XzS'   U R                   R                  SU
UU	S9I S	h  vN $  N7f)
aO  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.
    params: Optional query parameters 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  r  /assistants/searchr  Nr  r   r|  r  r  r  r  r  r  rS   r   r  s              rI   rg   AssistantsClient.search-  s~     T #
 "*J"*J!(I$.L! &HYY^^ 	 $ 
 
 	
 
s   AA%A#A%r|  r  rS   r   c                  #    0 nU(       a  XS'   U(       a  X%S'   U R                   R                  SXSUS9I Sh  vN $  N7f)a  Count assistants matching filters.

Args:
    metadata: Metadata to filter by. Exact match for each key/value.
    graph_id: Optional graph id to filter by.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    int: Number of assistants matching the criteria.
r|  r  /assistants/countr  Nr  r   r|  r  rS   r   r  s         rI   countAssistantsClient.countk  sM     & #%"*J"*JYY^^gv $ 
 
 	
 
   7A >A c               ~   #    UUS.nU(       a  X'S'   U R                   R                  SU S3UUUS9I Sh  vN $  N7f)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.
    params: Optional query parameters 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"
    )
    ```
r  r|  r^  	/versionsr  Nr  r   ra  r|  r  r  rS   r   r  s           rI   get_versionsAssistantsClient.get_versions  s[     D #
 "*JYY^^<.	2	 $ 
 
 	
 
s   4=;=c               f   #    SU0nU R                   R                  SU S3UUUS9I Sh  vN $  N7f)a  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.
    params: Optional query parameters 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   ra  r  rS   r   r  s         rI   
set_latestAssistantsClient.set_latest  sJ     > $-g"6YY^^<.0	 $ 
 
 	
 
s   (1/1rX  r   r   r   r   ra  r;  rS   r=  r   r<  r   r   
ra  r;  re  z
int | boolrS   r=  r   r<  r   zdict[str, list[dict[str, Any]]]ra  r;  rS   r=  r   r<  r   r   NFra  r;  rv  
str | Nonerr  boolrS   r=  r   r<  r   r0   r   r  r  r  Config | Noner{  Context | Noner|  r!   ra  r  r}  OnConflictBehavior | Noner~  r  rS   r=  r  r  r   r<  r   r   ra  r;  r  r  r  r  r{  r  r|  r!   r~  r  rS   r=  r  r  r   r<  r   r   ra  r;  rS   r=  r   r<  r   r   r|  r!   r  r  r  rD  r  rD  r  zAssistantSortBy | Noner  SortOrder | Noner  z!list[AssistantSelectField] | NonerS   r=  r   r<  r   zlist[Assistant]
r|  r!   r  r  rS   r=  r   r<  r   rD  Nr  r   ra  r;  r|  r!   r  rD  r  rD  rS   r=  r   r<  r   zlist[AssistantVersion]
ra  r;  r  rD  rS   r=  r   r<  r   r   r   r   r   r   r   r   re   rk  ro  rx  r  r   r   rg   r  r  r  r   r   rK   rI   r   r   m  s    -1)-+
+
 *	+

 '+
 
+
b !,0)-8
8
 	8

 *8
 '8
 
)8
| -1)-w
w
 *	w

 'w
 
w
x !%	$ -1)-$$ $ 	$ *$ '$ 
$R !%E

 #'#'/3,0"&)-E
E
 E

  E
 E
 !E
 -E
 E
 *E
  E
 'E
 
E
V  $ $"&,0"&)-A
A
 	A

 A
  A
 A
 A
 *A
  A
 'A
 
A
N -1)-

 *	

 '
 

D #*.'+48,0)-<
 <
 	<

 <
 <
 (<
 %<
 2<
 *<
 '<
 
<
B #,0)-
 
 	

 *
 '
 

> ,
 -1)-,
,
 ,
 	,

 ,
 *,
 ',
 
 ,
f -1)-&
&
 &

 *&
 '&
 
&
 &
rK   r   c                  R   \ rS rSrSrSS jrSSS.       SS jjrSSSSSSSSS.                 S S jjrSSSS	.           S!S
 jjrSSS.       S"S jjr	SSSSSSSSSSSS.                       S#S jjr
SSSSSS.           S$S jjrSSS.       S"S jjr  S%SSSS.             S&S jjjrSSSSSS.               S'S jjrSSSSSSS.               S(S jjrSSSSS.           S)S jjrSrg)*r   i  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                    Xl         g r   rX  rY  s     rI   r   ThreadsClient.__init__  r[  rK   Nr\  c               X   #    U R                   R                  SU 3X#S9I Sh  vN $  N7f)a  Get a thread by ID.

Args:
    thread_id: The ID of the thread to get.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters 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   rd   rS   r   s       rI   re   ThreadsClient.get  s8     P YY]]	{#W # 
 
 	
 
rc  r|  rd   r}  
superstepsr  ttlrS   r   c                 #    0 n	U(       a  X)S'   U(       d  U(       a  0 U=(       d    0 EU(       a  SU0O0 EU	S'   U(       a  X9S'   U(       aG  U V
Vs/ s H4  n
SU
S    Vs/ s H  nUS   UR                  S5      US   S	.PM      sn0PM6     snn
U	S
'   Ub(  [        U[        [        45      (       a	  USS.U	S'   OXiS'   U R                  R                  SXUS9I Sh  vN $ s  snf s  snn
f  N7f)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.
    ttl: Optional time-to-live in minutes for the thread. You can pass an
        integer (minutes) or a mapping with keys `ttl` and optional
        `strategy` (defaults to "delete").
    headers: Optional custom headers to include with the request.
    params: Optional query parameters 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"
    )
    ```
rd   r  r|  r}  updatesvaluescommandas_noder  r  r  r  Nr   r  strategyr  /threadsr  re   rZ   rD  floatr   r   r   r|  rd   r}  r  r  r  rS   r   r  sus               rI   r  ThreadsClient.create  s&    V #%#,K x#>r#-5J)2#GJ #,K  $% $A  "#9  ".A	 '(k'(uuY'7'(|
 ". 	 $%GL! ?#U|,,),(!C!$YY^^Wf $ 
 
 	
# %&
s7   AC/C' %C"C'AC/C-C/"C''C/r  rS   r   c                  #    SU0nUb(  [        U[        [        45      (       a	  USS.US'   OX6S'   U R                  R	                  SU 3UUUS9I Sh  vN $  N7f)a  Update a thread.

Args:
    thread_id: ID of thread to update.
    metadata: Metadata to merge with existing thread metadata.
    ttl: Optional time-to-live in minutes for the thread. You can pass an
        integer (minutes) or a mapping with keys `ttl` and optional
        `strategy` (defaults to "delete").
    headers: Optional custom headers to include with the request.
    params: Optional query parameters 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},
        ttl=43_200,
    )
    ```
r|  Nr   r  r  r  r  rZ   rD  r  r   r   r   rd   r|  r  rS   r   r  s          rI   r   ThreadsClient.updatei  st     D $.x"8?#U|,,),(!C!$YY__	{#	 % 
 
 	
 
s   AAAAc               Z   #    U R                   R                  SU 3X#S9I Sh  vN   g N7f)a  Delete a thread.

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

Returns:
    None

???+ example "Example Usage"

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

r  r\  Nr  r  s       rI   r   ThreadsClient.delete  s+     6 ii9+6WWWr  r  r   r|  r  idsstatusr  r  r  r  r  rS   r   c                  #    UUS.nU(       a  XS'   U(       a  X,S'   U(       a  X<S'   U(       a  XLS'   U(       a  X|S'   U(       a  XS'   U	(       a  XS'   U R                   R                  S	UU
US
9I Sh  vN $  N7f)au  Search for threads.

Args:
    metadata: Thread metadata to filter on.
    values: State values to filter on.
    ids: List of thread IDs to filter by.
    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.
    params: Optional query parameters 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
    )
    ```

r  r|  r  r  r  r  r  r  /threads/searchr  Nr  r   r|  r  r  r  r  r  r  r  r  rS   r   r  s                rI   rg   ThreadsClient.search  s     ^ #
 "*J &H EN &H!(I$.L! &HYY^^	 $ 
 
 	
 
s   A2A;4A95A;r|  r  r  rS   r   c                  #    0 nU(       a  XS'   U(       a  X&S'   U(       a  X6S'   U R                   R                  SXdUS9I Sh  vN $  N7f)c  Count threads matching filters.

Args:
    metadata: Thread metadata to filter on.
    values: State values to filter on.
    status: Thread status to filter on.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    int: Number of threads matching the criteria.
r|  r  r  /threads/countr  Nr  r   r|  r  r  rS   r   r  s          rI   r  ThreadsClient.count  sX     * #%"*J &H &HYY^^7F $ 
 
 	
 
s   AAA	Ac               \   #    U R                   R                  SU S3SX#S9I Sh  vN $  N7f)a  Copy a thread.

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

Returns:
    None

???+ example "Example Usage"

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

r  /copyNr  r  r  s       rI   copyThreadsClient.copy  s;     6 YY^^	{%(tW $ 
 
 	
 
s   #,*,F	subgraphsrS   r   c               j  #    U(       a*  U R                   R                  SU S3X$S.UUS9I Sh  vN $ U(       a:  SU0nU(       a  0 UEUEnU R                   R                  SU SU 3UUS9I Sh  vN $ SU0nU(       a  0 UEUEnU R                   R                  SU S	3UUS9I Sh  vN $  N} N> N7f)
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.
    params: Optional query parameters 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'
            }
    }
    ```
r  /state/checkpoint
checkpointr  r  Nr  /state/r   /stater   r   re   r   rd   r  checkpoint_idr  rS   r   rw  s           rI   	get_stateThreadsClient.get_state;  s     \ I;&78$.G	 (    %y1J5
5f5
I;gm_=! '    &y1J5
5f5
I;f-! '   's4   -B3B-A B30B/17B3(B1)B3/B31B3r  r  r  rS   r   c                  #    SU0nU(       a  XXS'   U(       a  XHS'   U(       a  X8S'   U R                   R                  SU S3XUS9I Sh  vN $  N7f)	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.
    params: Optional query parameters 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': {}
        }
    }
    ```
r  r  r  r  r  r  r  Nr  	r   rd   r  r  r  r  rS   r   r  s	            rI   update_stateThreadsClient.update_state  sl     f f#
 '4O$$.L!!(IYY^^	{&)QW $ 
 
 	
 
s   AA
AAr  beforer|  r  rS   r   c                  #    SU0nU(       a  X8S'   U(       a  XHS'   U(       a  XXS'   U R                   R                  SU S3UUUS9I Sh  vN $  N7f)	a  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.
    params: Optional query parameters 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  r  /historyr  Nr  	r   rd   r  r  r|  r  rS   r   r  s	            rI   get_historyThreadsClient.get_history  sp     J U#
  &H"*J$.L!YY^^	{(+	 $ 
 
 	
 
s   A	AAA	run_modes)r%  stream_moderS   r   c                  #    SU0nU(       a  UR                  U5        U R                  R                  SU S3S0 U(       a  SU0O0 EU=(       d    0 EUS9$ 7f)a(  Get a stream of events for a thread.

Args:
    thread_id: The ID of the thread to get the stream for.
    last_event_id: The ID of the last event to get.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    Iterator[StreamPart]: An iterator of stream parts.

???+ example "Example Usage"

    ```python

    for chunk in client.threads.join_stream(
        thread_id="my_thread_id",
        last_event_id="my_event_id",
    ):
        print(chunk)
    ```

r  r  /streamr  r  r\  r   r   r  )r   rd   r%  r  rS   r   rj  s          rI   join_streamThreadsClient.join_stream6  sy     B ;
 'yy	{'*7DO]3"=b     
 	
s   AArX  r  rd   r;  rS   r=  r   r<  r   r1   r|  r!   rd   r  r}  r  r  z4Sequence[dict[str, Sequence[dict[str, Any]]]] | Noner  r  r  int | Mapping[str, Any] | NonerS   r=  r   r<  r   r1   rd   r;  r|  Mapping[str, Any]r  r  rS   r=  r   r<  r   r1   rd   r;  rS   r=  r   r<  r   r   r|  r!   r  r!   r  Sequence[str] | Noner  ThreadStatus | Noner  rD  r  rD  r  zThreadSortBy | Noner  r  r  zlist[ThreadSelectField] | NonerS   r=  r   r<  r   zlist[Thread]r|  r!   r  r!   r  r   rS   r=  r   r<  r   rD  NNrd   r;  r  Checkpoint | Noner  r  r  r  rS   r=  r   r<  r   r4   rd   r;  r  z&dict[str, Any] | Sequence[dict] | Noner  r  r  r$  r  r  rS   r=  r   r<  r   r7   rd   r;  r  rD  r  zstr | Checkpoint | Noner|  Mapping[str, Any] | Noner  r$  rS   r=  r   r<  r   zlist[ThreadState])rd   r;  r%  r  r  -ThreadStreamMode | Sequence[ThreadStreamMode]rS   r=  r   r<  r   rE  r   r   r   r   r   r   re   r  r   r   rg   r  r  r  r  r  r  r   r   rK   rI   r   r     s	    -1)-*
*
 *	*

 '*
 
*
^  $/3KO#.2,0)-K
 K
 	K

 -K
 IK
 K
 ,K
 *K
 'K
 
K
d /3,0)--
-
 $	-

 ,-
 *-
 '-
 
-
f -1)-XX *	X
 'X 
X@ $(&*'+'+15,0)-E
 E
 	E

 "E
 $E
 E
 E
 %E
 %E
 /E
 *E
 'E
 
E
T &*,0)-
 
 	

 $
 *
 '
 

H -1)-

 *	

 '
 

D )-$(	F  ,0)-FF &F "	F F *F 'F 
FZ #(,$(,0)-=
=
 7=

 =
 &=
 "=
 *=
 '=
 
#=
F *.-1(,,0)-2
2
 	2

 (2
 +2
 &2
 *2
 '2
 
2
p %)EP,0)--
-
 "	-

 C-
 *-
 '-
 
#-
 -
rK   r   c                     \ rS rSrSrS)S jr\SSSSSSSSSSSSSSSSSSSSSSS.                                                 S*S jj5       r\SSSSSSSSSSSSSSSSSSSS	.                                           S+S
 jj5       rSSSSSSSSSSSSSSSSSSSSSSSSS.                                                     S,S jjr\SSSSSSSSSSSSSSSSSSS.                                         S-S jj5       r\SSSSSSSSSSSSSSSSSSSSS.                                             S.S jj5       rSSSSSSSSSSSSSSSSSSSSSSS.                                                 S/S jjrSSS.       S0S jjr	\SSSSSSSSSSSSSSSSSSSS.                                           S1S jj5       r
\SSSSSSSSSSSSSSSSSS.                                       S2S jj5       r
SSSSSSSSSSSSSSSSSSSSSS.                                               S3S jjr
SSSSSSS.               S4S jjrSSS.         S5S  jjrSS!SSS".             S6S# jjrSSS.         S7S$ jjrSSSSSS%.               S8S& jjrSSS.         S9S' jjrS(rg):r   if  a  Client for managing runs in LangGraph.

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

???+ example "Example"

    ```python
    client = get_client(url="http://localhost:2024")
    run = await client.runs.create(assistant_id="asst_123", thread_id="thread_456", input={"query": "Hello"})
    ```
c                    Xl         g r   rX  rY  s     rI   r   RunsClient.__init__t  r[  rK   Nr  F)inputr  r  stream_subgraphsstream_resumabler|  r  r{  r  r  checkpoint_duringinterrupt_beforeinterrupt_afterfeedback_keyson_disconnectwebhookmultitask_strategyif_not_existsafter_secondsrS   r   on_run_createdc                   g r   r   )r   rd   ra  r-  r  r  r.  r/  r|  r  r{  r  r  r0  r1  r2  r3  r4  r5  r6  r7  r8  rS   r   r9  s                            rI   r  RunsClient.streamw  s    8 %(rK   )r-  r  r  r.  r/  r|  r  r0  r1  r2  r3  r4  on_completionr7  r5  r8  rS   r   r9  c                   g r   r   )r   rd   ra  r-  r  r  r.  r/  r|  r  r0  r1  r2  r3  r4  r<  r7  r5  r8  rS   r   r9  s                         rI   r  r;    s    2 %(rK   r-  r  r  r.  r/  r|  r  r{  r  r  r0  r1  r2  r3  r4  r<  r5  r6  r7  r8  rS   r   r9  
durabilityc          
       ^ Ub  [         R                  " S[        SS9  0 SU_SU(       a,  UR                  5        VVs0 s H  u  nnUc  M  UU_M     snnOS_SU	_SU
_S	U_S
U_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_UUUUUS.EnUb  SU S3OSnSU4S jjnU R                  R                  USUR                  5        VVs0 s H  u  nnUc  M  UU_M     snnUUT(       a  US9$ SS9$ s  snnf s  snnf )a  Create a run and stream the results.

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

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"},
        context={"model_name": "anthropic"},
        interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
        interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
        feedback_keys=["my_feedback_key_1","my_feedback_key_2"],
        webhook="https://my.fake.webhook.com",
        multitask_strategy="interrupt"
    ):
        print(chunk)
    ```

    ```shell

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

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

Nd`checkpoint_during` is deprecated and will be removed in a future version. Use `durability` instead.r  r  r-  r  r  r{  r|  r  r.  r/  ra  r1  r2  r3  r5  r  r  r0  r6  r7  r4  r<  r8  r?  r  /runs/streamc                L   > T(       a  [        U 5      =n(       a	  T" U5        gggz)Callback function to handle the response.Nrl   r4  r|  r9  s     rI   r   &RunsClient.stream.<locals>.on_response@  &    /Ns/S#S8#Sx( $T~rK   POSTr   r4  httpx.Responser
  r  DeprecationWarningr   r   r   r   rd   ra  r-  r  r  r.  r/  r|  r  r{  r  r  r0  r1  r2  r3  r4  r<  r5  r6  r7  r8  rS   r   r9  r?  kvr  endpointr   s                             `      rI   r  r;    s   R (MMv"
U
GN'--/C/$!QQA/CTX

 f
 w
 
 ;
  0
  0
 L
  0
 
 ]
 w
  *!
" ]#
$  !2%
& !"4'
( +***$1
8 $ 	{,/ 		)
 yy#*==?D?41aa$!Q$?D'5   
 	
 <@   
 	
E DJ E   
C5
C5

C;C;)r-  r  r  r.  r/  r|  r0  r  r{  r1  r2  r5  r<  r7  r8  rS   r   r9  c                  #    g 7fr   r   )r   rd   ra  r-  r  r  r.  r/  r|  r0  r  r{  r1  r2  r5  r<  r7  r8  rS   r   r9  s                        rI   r  RunsClient.createN  s
     0    r-  r  r  r.  r/  r|  r  r{  r  r  r0  r1  r2  r5  r6  r7  r8  rS   r   r9  c                  #    g 7fr   r   r   rd   ra  r-  r  r  r.  r/  r|  r  r{  r  r  r0  r1  r2  r5  r6  r7  r8  rS   r   r9  s                          rI   r  rU  h  s
     4 rV  r-  r  r  r.  r/  r|  r  r{  r  r  r0  r1  r2  r5  r6  r7  r<  r8  rS   r   r9  r?  c                 ^#    Ub  [         R                  " S[        SS9  0 SU_SU(       a,  UR                  5        VVs0 s H  u  nnUc  M  UU_M     snnOS_SU_SU_S	U_S
U	_SU
_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_UUUS.EnUR                  5        VVs0 s H  u  nnUc  M  UU_M     nnnSU4S jjnU R                  R                  U(       a  SU S3OSUUUT(       a  UOSS9I Sh  vN $ s  snnf s  snnf  N7f)a  Create a background run.

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

Returns:
    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"},
        context={"model_name": "openai"},
        interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
        interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
        webhook="https://my.fake.webhook.com",
        multitask_strategy="interrupt"
    )
    print(background_run)
    ```

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

    {
        'run_id': 'my_run_id',
        'thread_id': 'my_thread_id',
        'assistant_id': 'my_assistant_id',
        'created_at': '2024-07-25T15:35:42.598503+00:00',
        'updated_at': '2024-07-25T15:35:42.598503+00:00',
        'metadata': {},
        'status': 'pending',
        'kwargs':
            {
                'input':
                    {
                        'messages': [
                            {
                                'role': 'user',
                                'content': 'how are you?'
                            }
                        ]
                    },
                'config':
                    {
                        'metadata':
                            {
                                'created_by': 'system'
                            },
                        'configurable':
                            {
                                'run_id': 'my_run_id',
                                'user_id': None,
                                'graph_id': 'agent',
                                'thread_id': 'my_thread_id',
                                'checkpoint_id': None,
                                'assistant_id': 'my_assistant_id'
                            },
                    },
                'context':
                    {
                        'model_name': 'openai'
                    }
                'webhook': "https://my.fake.webhook.com",
                'temporary': False,
                'stream_mode': ['values'],
                'feedback_keys': None,
                'interrupt_after': ["node_to_stop_after_1","node_to_stop_after_2"],
                'interrupt_before': ["node_to_stop_before_1","node_to_stop_before_2"]
            },
        'multitask_strategy': 'interrupt'
    }
    ```
NrA  r  r  r-  r  r  r.  r/  r  r{  r|  ra  r1  r2  r5  r  r  r0  r6  r7  r<  r8  r?  c                L   > T(       a  [        U 5      =n(       a	  T" U5        gggrE  rF  rG  s     rI   r   &RunsClient.create.<locals>.on_response/	  rI  rK   r  /runsr   rK  r
  r  rN  r   r   r   r   rd   ra  r-  r  r  r.  r/  r|  r  r{  r  r  r0  r1  r2  r5  r6  r7  r<  r8  rS   r   r9  r?  rP  rQ  r  r   s                          `     rI   r  rU    s    V (MMv"

U
GN'--/C/$!QQA/CTX

 ;
  0
  0
 f
 w
 
 L
  0
 
 w
 *
  ]!
"  !2#
$ !"4%
& ]'
( +*$-
0 %,MMOEODAqq41a4OE	)
 YY^^,5i	{%(7'54 $ 
 
 	
9 D* F
s7   =D 
C=
C=
AD"
D0D7AD8D	9Dr\  c                  #    SS jnU Vs/ s H
  oT" U5      PM     nnU R                   R                  SXbUS9I Sh  vN $ s  snf  N	7f),Create a batch of stateless background runs.c                b    U R                  5        VVs0 s H  u  pUc  M
  X_M     snn$ s  snnf r   r   r  rP  rQ  s      rI   filter_payload/RunsClient.create_batch.<locals>.filter_payloadE	  (    %,]]_F_TQDAD_FFF   	++/runs/batchr  Nr  r(   r  r   payloadsrS   r   rg  r  filtereds          rI   create_batchRunsClient.create_batch<	  sX     	G <DD8N7+8DYY^^& $ 
 
 	
 E
s   
A	A A	A
A	Tr-  r  r|  r  r{  r  r  r0  r1  r2  r5  r4  r6  r7  r8  raise_errorrS   r   r9  c                  #    g 7fr   r   r   rd   ra  r-  r  r|  r  r{  r  r  r0  r1  r2  r5  r4  r6  r7  r8  rs  rS   r   r9  s                         rI   waitRunsClient.waitM	  s
     2 '*rV  r-  r  r|  r  r{  r0  r1  r2  r5  r4  r<  r7  r8  rs  rS   r   r9  c                  #    g 7fr   r   r   rd   ra  r-  r  r|  r  r{  r0  r1  r2  r5  r4  r<  r7  r8  rs  rS   r   r9  s                       rI   rv  rw  h	  s
     . '*rV  )r-  r  r|  r  r{  r  r  r0  r1  r2  r5  r4  r<  r6  r7  r8  rs  rS   r   r9  r?  c          
       ^#    U
b  [         R                  " S[        SS9  0 SU_SU(       a,  UR                  5        VVs0 s H  u  nnUc  M  UU_M     snnOS_SU_SU_S	U_S
U_SU_SU_SU_SU_SU	_SU_SU
_SU_SU_SU_SU_SU0EnUb  SU S3OSnS U4S jjnU R                  R                  USUR                  5        VVs0 s H  u  nnUc  M  UU_M     snnUUT(       a  UOSS9I Sh  vN nU(       ag  [        U[        5      (       aR  SU;   aL  [        US   [        5      (       a4  [        US   R                  S5       SUS   R                  S5       35      eU$ s  snnf s  snnf  N7f)!ad  Create a run, wait until it finishes and return the final state.

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

Returns:
    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"},
        context={"model_name": "anthropic"},
        interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
        interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
        webhook="https://my.fake.webhook.com",
        multitask_strategy="interrupt"
    )
    print(final_state_of_run)
    ```

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

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

NrA  r  r  r-  r  r  r{  r|  ra  r1  r2  r5  r  r  r6  r0  r7  r4  r<  r8  r?  r  
/runs/waitc                L   > T(       a  [        U 5      =n(       a	  T" U5        gggrE  rF  rG  s     rI   r   $RunsClient.wait.<locals>.on_response
  rI  rK   rJ  r   	__error__r   z: messagerK  )
r
  r  rN  r   r   r  rZ   rW   r   re   )r   rd   ra  r-  r  r|  r  r{  r  r  r0  r1  r2  r5  r4  r<  r6  r7  r8  rs  rS   r   r9  r?  rP  rQ  r  rR  r   ri   s                         `       rI   rv  rw  	  s"    d (MMv"

U
GN'--/C/$!QQA/CTX

 f
 w
 
 L
  0
 
 w
 *
 ]
 !"4
  !2
  ]!
" ]#
$ ]%
& ]'
( *)
. 2;1Fi	{*-L 		)
 44#*==?D?41aa$!Q$?D'54 5 
 
 8T**x'8K0$77K(,,W56b+9N9R9RS\9]8^_  [ D> E
s7   =E7 
E)
E)
A5E7

E/E/E74E55BE7r  r   r  r  r  r  rS   r   c                  #    UUS.nUb  XHS'   U(       a  XXS'   U(       a  UR                  U5        U R                  R                  SU S3XS9I Sh  vN $  N7f)aV  List runs.

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

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

r  Nr  r  r  r_  r   rh  	r   rd   r  r  r  r  rS   r   rj  s	            rI   r]   RunsClient.list+
  ss     J (
 %+"%+"'YY]]	{%( # 
 
 	
 
s   AAAAc               ^   #    U R                   R                  SU SU 3X4S9I Sh  vN $  N7f)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.
    params: Optional query parameters 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",
    )
    ```

r  /runs/r\  Nr_  r   rd   rc   rS   r   s        rI   re   RunsClient.get]
  s=     > YY]]	{&17 # 
 
 	
 
s   $-+-	interruptrv  actionrS   r   c                 #    U(       a  SOSUS.nU(       a  UR                  U5        U(       a+  U R                  R                  SU SU S3SUUS9I S	h  vN $ U R                  R                  SU SU S3S	UUS
9I S	h  vN $  N/ N7f)a  Get a run.

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

Returns:
    None

???+ example "Example Usage"

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

r  r   rv  r  r  r  /cancelrJ  r   Nr   r   r   r  r   r   rd   rc   rv  r  rS   r   rj  s           rI   cancelRunsClient.cancel
  s     L A1
 '44I;fVHG<#	 5    I;fVHG<#	 (   s$   AB
B*B
BB
B
c               d   #    U R                   R                  SU SU S3SUUS9I Sh  vN $  N7f)a  Block until a run is done. Returns the final state of the thread.

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

Returns:
    None

???+ example "Example Usage"

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

r  r  /joinr  r\  Nr   r  r  s        rI   joinRunsClient.join
  sH     < YY00	{&6	 1 
 
 	
 
s   '0.0cancel_on_disconnectr  rS   r   r%  c                   UUS.nU(       a  UR                  U5        U R                  R                  SU SU S3SU0 U(       a  SU0O0 EU=(       d    0 E=(       d    SS9$ )	a  Stream output from a run in real-time, until the run is done.
Output is not buffered, so any output produced before this call will
not be received here.

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

Returns:
    AsyncIterator[StreamPart]: The stream of parts.

???+ example "Example Usage"

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

)r  r  r  r  r  r  r  Nr   r  	r   rd   rc   r  r  rS   r   r%  rj  s	            rI   r  RunsClient.join_stream
  s    V %9&
 'yy	{&87DO]3"=b     	
 		
rK   c               `   #    U R                   R                  SU SU 3X4S9I Sh  vN   g N7f)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.
    params: Optional query parameters to include with the request.

Returns:
    None

???+ example "Example Usage"

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

r  r  r\  Nr  r  s        rI   r   RunsClient.delete  s:     < ii	{&17  
 	
 	
s   $.,.rX  r  )2rd   r;  ra  r;  r-  r'  r  Command | Noner  !StreamMode | Sequence[StreamMode]r.  r  r/  r  r|  r'  r  r  r{  r  r  r$  r  r  r0  bool | Noner1  All | Sequence[str] | Noner2  r  r3  r  r4  DisconnectMode | Noner5  r  r6  MultitaskStrategy | Noner7  IfNotExists | Noner8  
int | NonerS   r=  r   r<  r9  *Callable[[RunCreateMetadata], None] | Noner   rE  ),rd   r   ra  r;  r-  r'  r  r  r  r  r.  r  r/  r  r|  r'  r  r  r0  r  r1  r  r2  r  r3  r  r4  r  r<  OnCompletionBehavior | Noner7  r  r5  r  r8  r  rS   r=  r   r<  r9  r  r   rE  )6rd   r  ra  r;  r-  r'  r  r  r  r  r.  r  r/  r  r|  r'  r  r  r{  r  r  r$  r  r  r0  r  r1  r  r2  r  r3  r  r4  r  r<  r  r5  r  r6  r  r7  r  r8  r  rS   r=  r   r<  r9  r  r?  Durability | Noner   rE  )*rd   r   ra  r;  r-  r'  r  r  r  r  r.  r  r/  r  r|  r'  r0  r  r  r  r{  r  r1  r  r2  r  r5  r  r<  r  r7  r  r8  r  rS   r=  r   r<  r9  r  r   r'   .rd   r;  ra  r;  r-  r'  r  r  r  r  r.  r  r/  r  r|  r'  r  r  r{  r  r  r$  r  r  r0  r  r1  r  r2  r  r5  r  r6  r  r7  r  r8  r  rS   r=  r   r<  r9  r  r   r'   2rd   r  ra  r;  r-  r'  r  r  r  r  r.  r  r/  r  r|  r'  r  r  r{  r  r  r$  r  r  r0  r  r1  r  r2  r  r5  r  r6  r  r7  r  r<  r  r8  r  rS   r=  r   r<  r9  r  r?  r  r   r'   rn  zlist[RunCreate]rS   r=  r   r<  r   	list[Run],rd   r;  ra  r;  r-  r'  r  r  r|  r'  r  r  r{  r  r  r$  r  r  r0  r  r1  r  r2  r  r5  r  r4  r  r6  r  r7  r  r8  r  rs  r  rS   r=  r   r<  r9  r  r   list[dict] | dict[str, Any](rd   r   ra  r;  r-  r'  r  r  r|  r'  r  r  r{  r  r0  r  r1  r  r2  r  r5  r  r4  r  r<  r  r7  r  r8  r  rs  r  rS   r=  r   r<  r9  r  r   r  )0rd   r  ra  r;  r-  r'  r  r  r|  r'  r  r  r{  r  r  r$  r  r  r0  r  r1  r  r2  r  r5  r  r4  r  r<  r  r6  r  r7  r  r8  r  rs  r  rS   r=  r   r<  r9  r  r?  r  r   r  rd   r;  r  rD  r  rD  r  zRunStatus | Noner  zlist[RunSelectField] | NonerS   r=  r   r<  r   r  
rd   r;  rc   r;  rS   r=  r   r<  r   r'   rd   r;  rc   r;  rv  r  r  r   rS   r=  r   r<  r   r   
rd   r;  rc   r;  rS   r=  r   r<  r   rW   )rd   r;  rc   r;  r  r  r  (StreamMode | Sequence[StreamMode] | NonerS   r=  r   r<  r%  r  r   rE  
rd   r;  rc   r;  rS   r=  r   r<  r   r   r   r   r   r   r   r   r   r  r  rp  rv  r]   re   r  r  r  r   r   r   rK   rI   r   r   f  sQ     +/"&9A!&!&-1 $"&(,$()-7;6:.2/3"7;,0$(,0)-EI5(( (
 ((  ( 7( ( ( +( (  ( &( "( '(  5!(" 4#($ ,%(& -'(( )(* 5+(, *-(. "/(0 *1(2 '3(4 C5(6 
#7( (:  +/"&9A!&!&-1 $)-7;6:.2/359,0"$(,0)-EI/(( (
 ((  ( 7( ( ( +( ( '( 5( 4( ,(  -!(" 3#($ *%(& '(( ")(* *+(, '-(. C/(0 
#1( (> +/"&9A!&!&-1 $"&(,$()-7;6:.2/359"7;,0$(,0)-EI(,9\
\
 \

 (\
  \
 7\
 \
 \
 +\
 \
  \
 &\
 "\
 '\
  5!\
" 4#\
$ ,%\
& -'\
( 3)\
* +\
, 5-\
. */\
0 "1\
2 *3\
4 '5\
6 C7\
8 &9\
: 
#;\
|  +/"&9A!&!&-1)- $"&7;6:"59,0$(,0)-EI- 
 (   7   + '    5 4  !" 3#$ *%& "'( *)* '+, C-. 
/ 2  +/"&9A!&!&-1 $"&(,$()-7;6:"7;,0$(,0)-EI1 
 (   7   +    & " '  5!" 4#$ %& 5'( *)* "+, *-. '/0 C12 
3 @ +/"&9A!&!&-1 $"&(,$()-7;6:"7;,059$(,0)-EI(,5v
v
 v

 (v
  v
 7v
 v
 v
 +v
 v
  v
 &v
 "v
 'v
  5!v
" 4#v
$ %v
& 5'v
( *)v
* 3+v
, "-v
. */v
0 '1v
2 C3v
4 &5v
6 
7v
x -1)-
!
 *	

 '
 

"  +/"&-1 $"&(,$()-7;6:"/37;,0$( ,0)-EI/** *
 (*  * +* *  * &* "* '* 5* 4* *  -!*" 5#*$ *%*& "'*( )** *+*, '-*. C/*0 
%1* *4  +/"&-1 $"&)-7;6:"/359,0$( ,0)-EI+** *
 (*  * +* *  * '* 5* 4* * -* 3*  *!*" "#*$ %*& *'*( ')** C+*, 
%-* *: +/"&-1 $"&(,$()-7;6:"/3597;,0$( ,0)-EI(,3hh h
 (h  h +h h  h &h "h 'h 5h 4h h  -!h" 3#h$ 5%h& *'h( ")h* +h, *-h. '/h0 C1h2 &3h4 
%5h\ #'.2,0)-0
0
 	0

 0
 !0
 ,0
 *0
 '0
 
0
n -1)-!
!
 !

 *!
 '!
 
!
P *,0)-88 8
 8 8 *8 '8 
8~ -1)-#
#
 #

 *#
 '#
 
#
T &+@D,0)-$(9
9
 9

 #9
 >9
 *9
 '9
 "9
 
#9
@ -1)- 
 
  

 * 
 ' 
 
 
  
rK   r   c                  r   \ rS rSrSrSS jrSSSSSSSSSSSS.                             SS jjrSSSSSSSSSSSS.                           SS jjrSSS.       SS	 jjrSSS
SSSSSSS.	                   SS jjr	SSSSS.         SS jjr
Srg)r   i=  a  Client for managing recurrent runs (cron jobs) in LangGraph.

A run is a single invocation of an assistant with optional input, config, and context.
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                    Xl         g r   rX  r   http_clients     rI   r   CronClient.__init__U      	rK   Nr-  r|  r  r{  r0  r1  r2  r5  r6  rS   r   c                  #    UUUUUUUU	U
US.
nU(       a  XS'   UR                  5        VVs0 s H  u  nnUc  M  UU_M     nnnU R                  R                  SU S3UUUS9I Sh  vN $ s  snnf  N
7f)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.
    context: Static context to add to the assistant.
        !!! version-added "Supported with langgraph>=0.6.0"
    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.
    params: Optional query parameters 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"},
        context={"model_name": "openai"},
        interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
        interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
        webhook="https://my.fake.webhook.com",
        multitask_strategy="interrupt"
    )
    ```

scheduler-  r  r|  r{  ra  r0  r1  r2  r5  r6  Nr  /runs/cronsr  r   r   r   r   rd   ra  r  r-  r|  r  r{  r0  r1  r2  r5  r6  rS   r   r  rP  rQ  s                     rI   create_for_threadCronClient.create_for_threadX  s     ~ ! (!2 0.
 ,>()$+MMOEODAqq41a4OEYY^^	{+.	 $ 
 
 	
 F
s!   ,A6
A.A.&A6)A4*A6c                  #    UUUUUUUUU	U
S.
nU(       a  XS'   UR                  5        VVs0 s H  u  nnUc  M  UU_M     nnnU R                  R                  SXUS9I Sh  vN $ s  snnf  N
7f)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.
    context: Static context to add to the assistant.
        !!! version-added "Supported with langgraph>=0.6.0"
    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.
    params: Optional query parameters 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"},
        context={"model_name": "openai"},
        interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
        interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
        webhook="https://my.fake.webhook.com",
        multitask_strategy="interrupt"
    )
    ```

r  r6  Nr  r  r  r   ra  r  r-  r|  r  r{  r0  r1  r2  r5  r6  rS   r   r  rP  rQ  s                    rI   r  CronClient.create  s     v ! (!2 0.
 ,>()$+MMOEODAqq41a4OEYY^^ $ 
 
 	
 F
s!   ,A1
A)A)!A1$A/%A1r\  c               Z   #    U R                   R                  SU 3X#S9I Sh  vN   g N7f)a  Delete a cron.

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

Returns:
    None

???+ example "Example Usage"

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

/runs/crons/r\  Nr  r   cron_idrS   r   s       rI   r   CronClient.delete  s+     6 iigY7XXXr  r  r   	ra  rd   r  r  r  r  r  rS   r   c       	          #    UUUUS.n
U(       a  XZS'   U(       a  XjS'   U(       a  XzS'   U
R                  5        VVs0 s H  u  pUc  M
  X_M     n
nnU R                  R                  SXU	S9I Sh  vN $ s  snnf  N
7f)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.
    params: Optional query parameters 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'
        }
    ]
    ```

ra  rd   r  r  r  r  r  N/runs/crons/searchr  r  r   ra  rd   r  r  r  r  r  rS   r   r  rP  rQ  s                rI   rg   CronClient.search  s     B )"	
 !(I$.L! &H$+MMOEODAq414OEYY^^ w $ 
 
 	
 F
s"   <A?	A7A7!A?2A=3A?ra  rd   rS   r   c                  #    0 nU(       a  XS'   U(       a  X%S'   U R                   R                  SXSUS9I Sh  vN $  N7f)<  Count cron jobs matching filters.

Args:
    assistant_id: Assistant ID to filter by.
    thread_id: Thread ID to filter by.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    int: Number of crons matching the criteria.
ra  rd   /runs/crons/countr  Nr  r   ra  rd   rS   r   r  s         rI   r  CronClient.countg  sM     & #%&2N##,K YY^^gv $ 
 
 	
 
r  rX  )r  r   r   r   rd   r;  ra  r;  r  r;  r-  r'  r|  r'  r  r  r{  r  r0  r  r1  All | list[str] | Noner2  r  r5  r  r6  r  rS   r=  r   r<  r   r'   ra  r;  r  r;  r-  r'  r|  r'  r  r  r{  r  r0  r  r1  r  r2  r  r5  r  r6  r  rS   r=  r   r<  r   r'   r  r;  rS   r=  r   r<  r   r   ra  r  rd   r  r  rD  r  rD  r  zCronSortBy | Noner  r  r  zlist[CronSelectField] | NonerS   r=  r   r<  r   z
list[Cron]
ra  r  rd   r  rS   r=  r   r<  r   rD  r   r   r   r   r   r   r  r  r   rg   r  r   r   rK   rI   r   r   =  s   .  +/-1 $"&)-3726")-,0)-!R
R
 R

 R
 (R
 +R
 R
  R
 'R
 1R
 0R
 R
 'R
 *R
  '!R
" 
#R
r +/-1 $"&)-3726")-,0)-K
K
 	K

 (K
 +K
 K
  K
 'K
 1K
 0K
 K
 'K
 *K
 'K
  
!K
b -1)-YY *	Y
 'Y 
Y@ $( $%)'+/3,0)-O
 !O
 	O

 O
 O
 #O
 %O
 -O
 *O
 'O
 
O
h $( $,0)-
 !
 	

 *
 '
 

 
rK   r   c                     \ rS rSrSrSS jr    S               SS jjrSSSS.           SS jjr  S         SS jjr       S                 SS	 jjr	       S               SS
 jjr
Srg)r   i  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                    Xl         g r   rX  rY  s     rI   r   StoreClient.__init__  r[  rK   Nc                  #    U H  nSU;   d  M  [        SU S35      e   UUUUUS.n	U R                  R                  S[        U	5      XgS9I Sh  vN   g N7f)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.
    params: Optional query parameters 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 ('.').rv  r)  r*  indexr  /store/itemsr  NrN   r   r   _provided_vals
r   rv  r)  r*  r  r  rS   r   labelr  s
             rI   put_itemStoreClient.put_item  sx     H Ee| /w6gh   #
 iimm!8'  
 	
 	
s   
AA AAArefresh_ttlrS   r   c                 #    U H  nSU;   d  M  [        SU S35      e   SR                  U5      US.nUb  X7S'   U(       a  0 UEUEnU R                  R                  SXtS9I Sh  vN $  N7f)	a  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.
    params: Optional query parameters 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'
    }
    ```
r  r  r  rv  r)  Nr  r  r   )rN   r  r   re   )r   rv  r)  r  rS   r   r  rw  s           rI   get_itemStoreClient.get_item  s     Z Ee| /w6gh  
 $'88I#6sC
"(3}%1J1&1JYY]]>*]VVVVs   
A-AA-&A+'A-c               \   #    U R                   R                  SXS.UUS9I Sh  vN   g N7f)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.
    params: Optional query parameters 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  r  r  Nr  r   rv  r)  rS   r   s        rI   delete_itemStoreClient.delete_item  s7     : ii(5	  
 	
 	
s   ",*,c	               z   #    UUUUUUS.n	U R                   R                  S[        U	5      UUS9I Sh  vN $  N7f)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.
    params: Optional query parameters 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  queryr  /store/items/searchr  Nr   r   r  
r   r  r  r  r  r   r  rS   r   r  s
             rI   search_itemsStoreClient.search_items&  sX     z !1&
 YY^^!(	 $ 
 
 	
 
s   2;9;c                x   #    UUUUUS.nU R                   R                  S[        U5      UUS9I Sh  vN $  N7f)ad  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.
    params: Optional query parameters 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"],
        ...
    ]
    ```
rG   suffix	max_depthr  r  /store/namespacesr  Nr  	r   rG   r  r	  r  r  rS   r   r  s	            rI   list_namespacesStoreClient.list_namespacesr  sU     \ "
 YY^^(	 $ 
 
 	
 
s   1:8:rX  r  NNNNr)  r;  r*  r  r  z!Literal[False] | list[str] | Noner  r  rS   r=  r   r<  rv  Sequence[str]r   r   r)  r;  rv  r  r  r  rS   r=  r   r<  r   r    r"  
r)  r;  rS   r=  r   r<  rv  r  r   r   Nr  r   NNNNr  r'  r  rD  r  rD  r   r  r  r  rS   r=  r   r<  r  r  r   r,   )NNNd   r   NNrG   list[str] | Noner  r  r	  r  r  rD  r  rD  rS   r=  r   r<  r   r"   r   r   r   r   r   r   r  r  r  r  r  r   r   rK   rI   r   r     s    48,0)-2
 	2

 !2
 12
 2
 *2
 '2
 2
 
2
t $(,0)-7W 	7W 7W !7W *7W '7W 
7W| -1)-"
 	"

 *"
 '"
 "
 
"
P ,0 #',0)-J
 )	J

 J
 J
 J
 !J
 *J
 'J
'J
 
J
\ $(#' $,0)-9
 9
 !9
 	9

 9
 9
 *9
 '9
 
9
 9
rK   r   SyncLangGraphClientc                    U c  Sn [         R                  " SS9n[         R                  " U UUb  [         R                  " U5      O[         R                  " SSSSS9[	        X5      S9n[        U5      $ )aX  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")
    ```
ru   rv   rw   ry   rz   r   )r   HTTPTransportClientr   rT   r  )rm   rF   rS   rn   r   r   s         rI   get_sync_clientr    sp    N {%##A.I\\ " MM'"qs#AFW.	F v&&rK   c                  P    \ rS rSrSrS	S jrS
S jr        SS jrSS jrSr	g)r  i  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                (   [        U5      U l        [        U R                  5      U l        [	        U R                  5      U l        [        U R                  5      U l        [        U R                  5      U l	        [        U R                  5      U l        g r   )SyncHttpClientr   SyncAssistantsClientr   SyncThreadsClientr   SyncRunsClientr   SyncCronClientr   SyncStoreClientr   r   s     rI   r   SyncLangGraphClient.__init__  s^    "6*	.tyy9(3"499-	#DII.
$TYY/
rK   c                    U $ )zEnter the sync context manager.r   r   s    rI   	__enter__SyncLangGraphClient.__enter__  s    rK   c                $    U R                  5         g)zExit the sync context manager.N)closer   s       rI   __exit__SyncLangGraphClient.__exit__   s     	

rK   c                p    [        U S5      (       a%  U R                  R                  R                  5         ggr   )rX   r   r   r+  r   s    rI   r+  SyncLangGraphClient.close	  s*    4  II""$ !rK   r   Nr   zhttpx.Clientr   r   )r   r  r   r   )
r   r   r   r   r   r   r(  r,  r+  r   r   rK   rI   r  r    sA    0, & %	
 
%rK   c                  f   \ rS rSrSrSS jrSSSS.         SS jjrSSSS.           SS jjrSSSS.           SS jjrSSSS.           SS	 jjr	SSSSS
.           SS jjr
SSSSSS.               SS jjrSSSSS
.             SS jjrSrg)r   i  a   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                    Xl         g r   r   r   s     rI   r   SyncHttpClient.__init__  r   rK   Nr   c                  U R                   R                  XUS9nU(       a  U" U5         UR                  5         [        U5      $ ! [        R                   ac  nUR                  5       R                  5       n[        R                  S:  a  UR                  U5        Ue[        R                  SU 3US9  UeSnAff = f)r   r   r   r   r   N)r   re   r   r   r   r|   r   r   r   r   r   r   _decode_jsonr   s           rI   re   SyncHttpClient.get  s     KKOODOAN	  A $$ 	668??$D7*

4  G 9$@1MG	s   A B=AB88B=c                  Ub  [        U5      u  pgO0 SpvU(       a  UR                  U5        U R                  R                  XXsS9nU(       a  U" U5         UR	                  5         [        U5      $ ! [
        R                   ac  n	UR                  5       R                  5       n
[        R                  S:  a  U	R                  U
5        U	e[        R                  SU
 3U	S9  U	eSn	A	ff = fr   )_encode_jsonr   r   r   r   r   r   r|   r   r   r   r   r   r   r5  r   s              rI   r   SyncHttpClient.post4  s     '3D'9$OW')3W""7+KK7  
 N	  A $$ 	668??$D7*

4  G 9$@1MG	s   A2 2C)AC$$C)c                  [        U5      u  pgU(       a  UR                  U5        U R                  R                  XXsS9nU(       a  U" U5         UR	                  5         [        U5      $ ! [
        R                   ac  n	UR                  5       R                  5       n
[        R                  S:  a  U	R                  U
5        U	e[        R                  SU
 3U	S9  U	eSn	A	ff = f)r   r   r   r   r   N)r8  r   r   r   r   r   r   r|   r   r   r   r   r   r   r5  r   s              rI   r   SyncHttpClient.putT  s     $0#5 ""7+KKOO7  
 N	  A $$ 	668??$D7*

4  G 9$@1MG	   A+ +C"?ACC"c                  [        U5      u  pgU(       a  UR                  U5        U R                  R                  XXsS9nU(       a  U" U5         UR	                  5         [        U5      $ ! [
        R                   ac  n	UR                  5       R                  5       n
[        R                  S:  a  U	R                  U
5        U	e[        R                  SU
 3U	S9  U	eSn	A	ff = f)r   r   r   r   r   N)r8  r   r   r   r   r   r   r|   r   r   r   r   r   r   r5  r   s              rI   r   SyncHttpClient.patchr  s     $0#5 ""7+KK7  
 N	  A $$ 	668??$D7*

4  G 9$@1MG	r<  r   c               n   U R                   R                  SXX4S9nU(       a  U" U5         UR                  5         g! [        R                   ac  nUR                  5       R                  5       n[        R                  S:  a  UR                  U5        Ue[        R                  SU 3US9  UeSnAff = f)r   r   r   r   r   r   N)r   r   r   r   r   r|   r   r   r   r   r   r   r   s	            rI   r   SyncHttpClient.delete  s     KKdf   
 N	 $$ 	668??$D7*

4  G 9$@1MG	s   = B4AB//B4rv   r   c          	     <   [        U5      u  pU(       a  UR                  U5        U R                  R                  X!XUS9 n
U(       a  U" U
5         U
R	                  5         U
R                  R                  S5      nUS::  d  U(       d  [!        U
5      sSSS5        $  [!        U
5      sSSS5        $ ! [
        R                   ac  nU
R                  5       R                  5       n[        R                  S:  a  UR                  U5        Ue[        R                  SU 3US9  UeSnAff = f! [
        R"                   aI    [$        R&                  " SU 3S	S
9  U
R)                  5         U R+                  USUUS-
  S9s sSSS5        $ f = f! , (       d  f       g= f)r   r   r   r   r   Nr   r   r  r  r  r  r  r  )r8  r   r   r  r   r   r   r|   r   r   r   r   r   r   rS   re   r5  r	  r
  r  r+  r  r  s                 rI   r   SyncHttpClient.request_reconnect  s    $0#5 ""7+[[/6   
A""$ ))--
+C!#3#A!
 
"#A%
 
 (( vvx(##w.JJt$  LL#=dV!DqLQ ?? HN  	--+$3a$7 .  3
 
&'
 
sP   FB3"2F
D-3D*AD%%D**F-AF
>F	F

F
Fc             #  >  #    Ub  [        U5      u  pxO0 SpSUS'   SUS'   U(       a  UR                  U5        UR                  5        V	V
s0 s H  u  pU	R                  5       S;  d  M  X_M     nn	n
SnSnSnSn [	        Uc  UOU5      nUb  UUS
'   Uc  UOSnUc  UOSnUc  UOSnSnU R
                  R                  UU=(       d    UUUUS9 nUc  U(       a  U" U5         UR                  5         UR"                  R%                  SS5      R'                  S5      S   nSU;  a  [        R(                  " SU< 35      eUR"                  R%                  S5      nU(       a  Un[+        5       n [-        U5       He  nUR                  UR/                  S5      5      nUc  M(  UR0                  b  UR0                  nUR2                  (       d  UR4                  c  Ma  Uv   Mg     UR                  S5      =n(       a;  UR0                  b  UR0                  nUR2                  (       d  UR4                  b  Uv   SSS5        U(       a#  US-  nX:  a  [        R(                  " S5      eGM  gs  sn
n	f ! [        R                   ac  nUR                  5       R                  5       n[        R                  S:  a  UR                  U5        Ue[        R!                  SU 3US9  UeSnAff = f! [        R6                   a	    Uc  e S	n Nf = f! , (       d  f       N= f7f)z*Stream the results of a request using SSE.Nr  r  r  r  r  r   rv   Tr  r  Fr   r   r   r   r  r  r  r  r   r  rK   r  r  )r8  r   r   r!  rW   r   r  r   r   r   r|   r   r   r   r   r   r   rS   re   r"  r#  r8   r:   r$  r%  r&  r'  r	  r(  s                                rI   r  SyncHttpClient.stream  s8     '3D'9$OW')4W$7!+5(""7+ .335
5
yy{"DD CJ5 	 
 %)%)!""#1#9?PO (3@0'5'=V5N)7)?gTO'5'=V4NE##&$''% $  !)k$((*  #{{~rBLLSQRST&l:..+.0 
 &)[[__Z%@"%%7N$,& .s 3%nnT[[-?@?&44@070E0E"yyCHH,@&)	 !4 &nnS11s1"00<,3,A,AM99(< #&Ikl "a'"%>..D  i
F ,, HHJ..0D''72

4( G 'A$%HSTUG8  ! &- E!Q s   A
LI,*I,0A!LL%I25A<L2/K,%5K,K,&AL99L2K)AK$$K))L,L	LL		L
LLr   r0  r:  r?  r@  rA  rB  )r   r;  r  r;  r   rC  r   r<  rS   r=  r   r>  r   Iterator[StreamPart]rF  r   rK   rI   r   r     sD    *.,0?C '	
 * = 
8 *.,0?C +	
 ' * = 
J *.,0?C 	
 ' * = 
F *.,0?C 	
 ' * = 
B  )-,0?C 	
 ' * = 
< '+)-,0?C .. .
 $. '. *. =. . 
.j '+)-,0?Chh h
 $h 'h *h =h 
h hrK   r   c                    [         R                  " U [        [         R                  [         R                  -  5      n[        [        U5      5      nSnX#S.nXA4$ rH  )rL  rM  ra   rN  rO  r;  rP  rQ  s        rI   r8  r8  C  sN    <<""V%<%<<D
 T^N%L!/NG=rK   c                `    U R                  5       nU(       a  [        R                  " U5      $ S $ r   )r|   rL  rT  rU  s     rI   r5  r5  O  s#    668D!%6<</4/rK   c            
      H   \ rS rSrSrSS jrSSS.       SS jjrSSSS.         SS	 jjrSSS.       SS
 jjr  SSSS.           SS jjjr	 S SSSSSSSSS.                     S!S jjjr
SSSSSSSSS.                   S"S jjrSSS.       S#S jjrSSSSSSSSSS.	                   S$S jjrSSSSS.         S%S jjr   S&SSS.             S'S jjjrSSS.         S(S jjrSrg))r!  iT  aK  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                    Xl         g r   rX  rY  s     rI   r   SyncAssistantsClient.__init__a  r[  rK   Nr\  c               <    U R                   R                  SU 3X#S9$ )aJ  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.
    params: Optional query parameters 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': {},
        'context': {},
        'metadata': {'created_by': 'system'}
    }
    ```

r^  r\  r_  r`  s       rI   re   SyncAssistantsClient.getd  s+    R yy}}<.)7  
 	
rK   Frd  c               v    SU0nU(       a  UR                  U5        U R                  R                  SU S3XSS9$ )a1  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.
    params: Optional query parameters 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__'}
            ]
    }
    ```

re  r^  rg  r   rh  ri  s         rI   rk  SyncAssistantsClient.get_graph  sG    \ ~'yy}}<./  
 	
rK   c               >    U R                   R                  SU S3X#S9$ )aW  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.
    params: Optional query parameters 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'
                            }
                    }
            },
        'context_schema':
            {
                'title': 'Context',
                'type': 'object',
                'properties':
                    {
                        'model_name':
                            {
                                'title': 'Model Name',
                                'enum': ['anthropic', 'openai'],
                                'type': 'string'
                            }
                    }
            }
    }
    ```

r^  rn  r\  r_  r`  s       rI   ro   SyncAssistantsClient.get_schemas  s-    B yy}}<.17  
 	
rK   c                   SU0nU(       a  0 UEUEnUb!  U R                   R                  SU SU 3UUS9$ U R                   R                  SU S3UUS9$ )a1  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.
    params: Optional query parameters to include with the request.

Returns:
    Subgraphs: The graph schema for the assistant.

rr  r^  rs  r   rt  r_  ru  s          rI   rx  "SyncAssistantsClient.get_subgraphsK  s    (  )
1J1&1J 99==|nK	{C! !   99==|nJ7! !  rK   rz  c                   SU0nU(       a  X+S'   U(       a  X;S'   U(       a  XKS'   U(       a  X[S'   U(       a  XkS'   U(       a  X{S'   U	(       a  XS'   U R                   R                  S	XU
S
9$ )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.
    context: Static context to add to the assistant.
        !!! version-added "Supported with langgraph>=0.6.0"
    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
    params: Optional query parameters to include with the request.

Returns:
    Assistant: The created assistant.

???+ example "Example Usage"

    ```python
    client = get_sync_client(url="http://localhost:2024")
    assistant = client.assistants.create(
        graph_id="agent",
        context={"model_name": "openai"},
        metadata={"number":1},
        assistant_id="my-assistant-id",
        if_exists="do_nothing",
        name="my_name"
    )
    ```
r  r  r{  r|  ra  r}  r~  r  r  r  r  r  s               rI   r  SyncAssistantsClient.createo  s    f #
  &H!(I"*J&2N##,K "FO%0M"yy~~  
 	
rK   r  c                   0 n
U(       a  X*S'   U(       a  X:S'   U(       a  XJS'   U(       a  XZS'   U(       a  XjS'   U(       a  XS'   U R                   R                  SU 3U
UU	S9$ )	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.
    context: Static context to add to the assistant.
        !!! version-added "Supported with langgraph>=0.6.0"
    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",
        context={"model_name": "anthropic"},
        metadata={"number":2}
    )
    ```
r  r  r{  r|  r~  r  r^  r  r  r  s              rI   r   SyncAssistantsClient.update  sx    Z #%"*J &H!(I"*J"FO%0M"yy<.)	  
 	
rK   c               >    U R                   R                  SU 3X#S9  g)a  Delete an assistant.

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

Returns:
    None

???+ example "Example Usage"

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

r^  r\  Nr  r`  s       rI   r   SyncAssistantsClient.delete  s"    6 			<~6WrK   r  r   r  c       	            UUS.n
U(       a  XS'   U(       a  X*S'   U(       a  XZS'   U(       a  XjS'   U(       a  XzS'   U R                   R                  SU
UU	S9$ )	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.
    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
    )
    ```
r  r|  r  r  r  r  r  r  r  r  s              rI   rg   SyncAssistantsClient.search  sq    N #
 "*J"*J!(I$.L! &Hyy~~ 	  
 	
rK   r  c               h    0 nU(       a  XS'   U(       a  X%S'   U R                   R                  SXSUS9$ )r  r|  r  r  r  r  r  s         rI   r  SyncAssistantsClient.countO  s@    & #%"*J"*Jyy~~gv  
 	
rK   c               b    UUS.nU(       a  X'S'   U R                   R                  SU S3UUUS9$ )ac  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"
    )
    ```

r  r|  r^  r  r  r  r  s           rI   r  !SyncAssistantsClient.get_versionsk  sN    D #
 "*Jyy~~<.	2	  
 	
rK   c               J    SU0nU R                   R                  SU S3UUUS9$ )a  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
    )
    ```

r  r^  r  r  r  r  s         rI   r  SyncAssistantsClient.set_latest  s=    < $-g"6yy~~<.0	  
 	
rK   rX  r   r   r   r   r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r   rK   rI   r!  r!  T  s   
 -1)-+
+
 *	+

 '+
 
+
b !,0)-3
3
 	3

 *3
 '3
 
)3
r -1)-C
C
 *	C

 'C
 
C
P !%	" -1)-"" " 	" *" '" 
"N !%E

 #'#'/3,0"&)-E
E
 E

  E
 E
 !E
 -E
 E
 *E
  E
 'E
 
E
V  $ $"&,0"&)-?
?
 	?

 ?
  ?
 ?
 ?
 *?
  ?
 '?
 
?
J -1)-XX *	X
 'X 
X@ #*.'+48,0)-9
 9
 	9

 9
 9
 (9
 %9
 29
 *9
 '9
 
9
| #,0)-
 
 	

 *
 '
 

> ,
 -1)-,
,
 ,
 	,

 ,
 *,
 ',
 
 ,
f -1)-%
%
 %

 *%
 '%
 
%
 %
rK   r!  c                  R   \ rS rSrSrSS jrSSS.       SS jjrSSSSSSSSS.                 S S jjrSSSS	.           S!S
 jjrSSS.       S"S jjr	SSSSSSSSSSSS.                       S#S jjr
SSSSSS.           S$S jjrSSS.       S"S jjr  S%SSSS.             S&S jjjrSSSSSS.               S'S jjrSSSSSSS.               S(S jjrSSSSS.           S)S jjrSrg)*r"  i  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                    Xl         g r   rX  rY  s     rI   r   SyncThreadsClient.__init__  r[  rK   Nr\  c               <    U R                   R                  SU 3X#S9$ )a  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'}
    }
    ```

r  r\  r_  r  s       rI   re   SyncThreadsClient.get  s#    L yy}}y4g}UUrK   r  c                  0 n	U(       a  X)S'   U(       d  U(       a  0 U=(       d    0 EU(       a  SU0O0 EU	S'   U(       a  X9S'   U(       aG  U V
Vs/ s H4  n
SU
S    Vs/ s H  nUS   UR                  S5      US   S	.PM      sn0PM6     snn
U	S
'   Ub(  [        U[        [        45      (       a	  USS.U	S'   OXiS'   U R                  R                  SXUS9$ s  snf s  snn
f )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.
    ttl: Optional time-to-live in minutes for the thread. You can pass an
        integer (minutes) or a mapping with keys `ttl` and optional
        `strategy` (defaults to "delete").
    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"
    )
    ```
    )
rd   r  r|  r}  r  r  r  r  r  r  r   r  r  r  r  r  r  s               rI   r  SyncThreadsClient.create  s   V #%#,K x#>r#-5J)2#GJ #,K  $% $A  "#9  ".A	 '(k'(uuY'7'(|
 ". 	 $%GL! ?#U|,,),(!C!$yy~~jwPV~WW# %s   C%CCCr  c                   SU0nUb(  [        U[        [        45      (       a	  USS.US'   OX6S'   U R                  R	                  SU 3UUUS9$ )a  Update a thread.

Args:
    thread_id: ID of thread to update.
    metadata: Metadata to merge with existing thread metadata.
    ttl: Optional time-to-live in minutes for the thread. You can pass an
        integer (minutes) or a mapping with keys `ttl` and optional
        `strategy` (defaults to "delete").
    headers: Optional custom headers to include with the request.
    params: Optional query parameters 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},
        ttl=43_200,
    )
    ```
r|  r   r  r  r  r  r  r  s          rI   r   SyncThreadsClient.updateE  sg    D $.x"8?#U|,,),(!C!$yy	{#	  
 	
rK   c               >    U R                   R                  SU 3X#S9  g)aW  Delete a thread.

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

Returns:
    None

???+ example "Example Usage"

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

r  r\  Nr  r  s       rI   r   SyncThreadsClient.deletet  s"    4 			9YK0'QrK   r  r   r  c                   UUS.nU(       a  XS'   U(       a  X,S'   U(       a  X<S'   U(       a  XLS'   U(       a  X|S'   U(       a  XS'   U	(       a  XS'   U R                   R                  S	XUS
9$ )a  Search for threads.

Args:
    metadata: Thread metadata to filter on.
    values: State values to filter on.
    ids: List of thread IDs to filter by.
    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
    )
    ```
r  r|  r  r  r  r  r  r  r  r  r  r  s                rI   rg   SyncThreadsClient.search  s    V #
 "*J &H EN &H!(I$.L! &Hyy~~GV  
 	
rK   r  c               ~    0 nU(       a  XS'   U(       a  X&S'   U(       a  X6S'   U R                   R                  SXdUS9$ )r  r|  r  r  r  r  r  r  s          rI   r  SyncThreadsClient.count  sK    * #%"*J &H &Hyy~~7F  
 	
rK   c               @    U R                   R                  SU S3SX#S9$ )a  Copy a thread.

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

Returns:
    None

???+ example "Example Usage"

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

r  r  Nr  r  r  s       rI   r  SyncThreadsClient.copy  s.    6 yy~~	{%(tW  
 	
rK   Fr  c               &   U(       a"  U R                   R                  SU S3X$S.UUS9$ U(       a2  SU0nU(       a  0 UEUEnU R                   R                  SU SU 3UUS9$ SU0nU(       a  0 UEUEnU R                   R                  SU S3UUS9$ )	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.
    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'
            }
    }
    ```

r  r  r  r  r  r  r   r  r   r  s           rI   r  SyncThreadsClient.get_state  s    Z 99>>I;&78$.G	 "   %y1J5
5f5
99==I;gm_=! !   &y1J5
5f5
99==I;f-! !  rK   r  c                   SU0nU(       a  XXS'   U(       a  XHS'   U(       a  X8S'   U R                   R                  SU S3XUS9$ )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': {}
        }
    }
    ```

r  r  r  r  r  r  r  r  r  s	            rI   r  SyncThreadsClient.update_state  s_    ` f#
 '4O$$.L!!(Iyy~~	{&)QW  
 	
rK   r
  c                   SU0nU(       a  X8S'   U(       a  XHS'   U(       a  XXS'   U R                   R                  SU S3UUUS9$ )a  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  r  r  r  r  r  s	            rI   r  SyncThreadsClient.get_history  sc    L U#
  &H"*J$.L!yy~~	{(+	  
 	
rK   r  )r  r%  rS   r   c                   SU0nU(       a  UR                  U5        U R                  R                  SU S3S0 U(       a  SU0O0 EU=(       d    0 EUS9$ )aI  Get a stream of events for a thread.

Args:
    thread_id: The ID of the thread to get the stream for.
    last_event_id: The ID of the last event to get.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    Iterator[StreamPart]: An iterator of stream parts.

???+ example "Example Usage"

    ```python

    for chunk in client.threads.join_stream(
        thread_id="my_thread_id",
        last_event_id="my_event_id",
        stream_mode="run_modes",
    ):
        print(chunk)
    ```

r  r  r  r  r  r\  r  )r   rd   r  r%  rS   r   rj  s          rI   r  SyncThreadsClient.join_stream  sv    D ;
 'yy	{'*7DO]3"=b     
 	
rK   rX  ra  r  r  r  r  r  r!  r"  r#  r%  r&  )rd   r;  r  r(  r%  r  rS   r=  r   r<  r   rE  r)  r   rK   rI   r"  r"    s    -1)-&V&V *	&V
 '&V 
&VV  $/3KO#.2,0)-IX IX 	IX
 -IX IIX IX ,IX *IX 'IX 
IX` /3,0)--
-
 $	-

 ,-
 *-
 '-
 
-
f -1)-RR *	R
 'R 
R> $(&*'+'+15,0)->
 >
 	>

 ">
 $>
 >
 >
 %>
 %>
 />
 *>
 '>
 
>
F &*,0)-
 
 	

 $
 *
 '
 

H -1)-

 *	

 '
 

D )-$(	E  ,0)-EE &E "	E E *E 'E 
EX #(,$(,0)-:
:
 7:

 :
 &:
 ":
 *:
 ':
 
#:
@ *.-1(,,0)-3
3
 	3

 (3
 +3
 &3
 *3
 '3
 
3
r FQ$(,0)-.
.
 C	.

 ".
 *.
 '.
 
.
 .
rK   r"  c                     \ rS rSrSrS)S jr\SSSSSSSSSSSSSSSSSSSSSS.                                               S*S jj5       r\SSSSSSSSSSSSSSSSSSSSS	.                                             S+S
 jj5       rSSSSSSSSSSSSSSSSSSSSSSSSS.                                                     S,S jjr\SSSSSSSSSSSSSSSSSSS.                                         S-S jj5       r\SSSSSSSSSSSSSSSSSSSSS.                                             S.S jj5       rSSSSSSSSSSSSSSSSSSSSSSS.                                                 S/S jjrSSS.       S0S jjr	\SSSSSSSSSSSSSSSSSSSS.                                           S1S jj5       r
\SSSSSSSSSSSSSSSSSS.                                       S2S jj5       r
SSSSSSSSSSSSSSSSSSSSSS.                                               S3S jjr
SSSSSSS.               S4S jjrSSS.         S5S  jjrSS!SSS".             S6S# jjrSSS.         S7S$ jjrSSSSSS%.               S8S& jjrSSS.         S9S' jjrS(rg):r#  i8  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                    Xl         g r   rX  rY  s     rI   r   SyncRunsClient.__init__F  r[  rK   Nr  F)r-  r  r  r.  r|  r  r{  r  r  r0  r1  r2  r3  r4  r5  r6  r7  r8  rS   r   r9  c                   g r   r   )r   rd   ra  r-  r  r  r.  r|  r  r{  r  r  r0  r1  r2  r3  r4  r5  r6  r7  r8  rS   r   r9  s                           rI   r  SyncRunsClient.streamI  s    6  #rK   )r-  r  r  r.  r/  r|  r  r{  r0  r1  r2  r3  r4  r<  r7  r5  r8  rS   r   r9  c                   g r   r   )r   rd   ra  r-  r  r  r.  r/  r|  r  r{  r0  r1  r2  r3  r4  r<  r7  r5  r8  rS   r   r9  s                          rI   r  r  f  s    4  #rK   r>  c          
       ^ Ub  [         R                  " S[        SS9  0 SU_SU(       a,  UR                  5        VVs0 s H  u  nnUc  M  UU_M     snnOS_SU	_SU
_S	U_S
U_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_UUUUUS.EnUb  SU S3OSnSU4S jjnU R                  R                  USUR                  5        VVs0 s H  u  nnUc  M  UU_M     snnUUT(       a  US9$ SS9$ s  snnf s  snnf )a  Create a run and stream the results.

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


Returns:
    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"},
        context={"model_name": "anthropic"},
        interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
        interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
        feedback_keys=["my_feedback_key_1","my_feedback_key_2"],
        webhook="https://my.fake.webhook.com",
        multitask_strategy="interrupt"
    ):
        print(chunk)
    ```
    ```shell
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    StreamPart(event='metadata', data={'run_id': '1ef4a9b8-d7da-679a-a45a-872054341df2'})
    StreamPart(event='values', data={'messages': [{'content': 'how are you?', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'human', 'name': None, 'id': 'fe0a5778-cfe9-42ee-b807-0adaa1873c10', 'example': False}]})
    StreamPart(event='values', data={'messages': [{'content': 'how are you?', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'human', 'name': None, 'id': 'fe0a5778-cfe9-42ee-b807-0adaa1873c10', 'example': False}, {'content': "I'm doing well, thanks for asking! I'm an AI assistant created by Anthropic to be helpful, honest, and harmless.", 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'ai', 'name': None, 'id': 'run-159b782c-b679-4830-83c6-cef87798fe8b', 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None}]})
    StreamPart(event='end', data=None)
    ```
NrA  r  r  r-  r  r  r{  r|  r  r.  r/  ra  r1  r2  r3  r5  r  r  r0  r6  rB  r  rC  c                L   > T(       a  [        U 5      =n(       a	  T" U5        gggrE  rF  rG  s     rI   r   *SyncRunsClient.stream.<locals>.on_response  rI  rK   rJ  r   rK  rM  rO  s                             `      rI   r  r    s   L (MMv"

U
GN'--/C/$!QQA/CTX

 f
 w
 
 ;
  0
  0
 L
  0
 
 ]
 w
  *!
" ]#
$  !2%
& !"4'
( +***$1
8 $ 	{,/ 		)
 yy#*==?D?41aa$!Q$?D'5   
 	
 <@   
 	
E DJ ErS  )r-  r  r  r.  r/  r|  r  r{  r0  r1  r2  r5  r<  r7  r8  rS   r   r9  c                   g r   r   )r   rd   ra  r-  r  r  r.  r/  r|  r  r{  r0  r1  r2  r5  r<  r7  r8  rS   r   r9  s                        rI   r  SyncRunsClient.create  s    0 rK   rW  c                   g r   r   rY  s                          rI   r  r  6  s    4 rK   rZ  c                 ^ Ub  [         R                  " S[        SS9  0 SU_SU(       a,  UR                  5        VVs0 s H  u  nnUc  M  UU_M     snnOS_SU_SU_S	U_S
U	_SU
_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_UUUS.EnUR                  5        VVs0 s H  u  nnUc  M  UU_M     nnnSU4S jjnU R                  R                  U(       a  SU S3OSUUUT(       a  US9$ SS9$ s  snnf s  snnf )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.
    context: Static context to add to the assistant.
        !!! version-added "Supported with langgraph>=0.6.0"
    checkpoint: The checkpoint to resume from.
    checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
    interrupt_before: Nodes to interrupt immediately before they get executed.
    interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
    webhook: Webhook to call after LangGraph API call is done.
    multitask_strategy: Multitask strategy to use.
        Must be one of 'reject', 'interrupt', 'rollback', or 'enqueue'.
    on_completion: Whether to delete or keep the thread created for a stateless run.
        Must be one of 'delete' or 'keep'.
    if_not_exists: How to handle missing thread. Defaults to 'reject'.
        Must be either 'reject' (raise error if missing), or 'create' (create new thread).
    after_seconds: The number of seconds to wait before starting the run.
        Use to schedule future runs.
    headers: Optional custom headers to include with the request.
    on_run_created: Optional callback to call when a run is created.
    durability: The durability to use for the run. Values are "sync", "async", or "exit".
        "async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
        "sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
        "exit" means checkpoints are only persisted when the run exits, does not save intermediate steps

Returns:
    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"},
        context={"model_name": "openai"},
        interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
        interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
        webhook="https://my.fake.webhook.com",
        multitask_strategy="interrupt"
    )
    print(background_run)
    ```

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

    {
        'run_id': 'my_run_id',
        'thread_id': 'my_thread_id',
        'assistant_id': 'my_assistant_id',
        'created_at': '2024-07-25T15:35:42.598503+00:00',
        'updated_at': '2024-07-25T15:35:42.598503+00:00',
        'metadata': {},
        'status': 'pending',
        'kwargs':
            {
                'input':
                    {
                        'messages': [
                            {
                                'role': 'user',
                                'content': 'how are you?'
                            }
                        ]
                    },
                'config':
                    {
                        'metadata':
                            {
                                'created_by': 'system'
                            },
                        'configurable':
                            {
                                'run_id': 'my_run_id',
                                'user_id': None,
                                'graph_id': 'agent',
                                'thread_id': 'my_thread_id',
                                'checkpoint_id': None,
                                'assistant_id': 'my_assistant_id'
                            }
                    },
                'context':
                    {
                        'model_name': 'openai'
                    },
                'webhook': "https://my.fake.webhook.com",
                'temporary': False,
                'stream_mode': ['values'],
                'feedback_keys': None,
                'interrupt_after': ["node_to_stop_after_1","node_to_stop_after_2"],
                'interrupt_before': ["node_to_stop_before_1","node_to_stop_before_2"]
            },
        'multitask_strategy': 'interrupt'
    }
    ```
NrA  r  r  r-  r  r  r.  r/  r  r{  r|  ra  r1  r2  r5  r  r  r0  r6  r7  r\  c                L   > T(       a  [        U 5      =n(       a	  T" U5        gggrE  rF  rG  s     rI   r   *SyncRunsClient.create.<locals>.on_response  rI  rK   r  r_  r   rK  r`  ra  s                          `     rI   r  r  R  s   V (MMv"

U
GN'--/C/$!QQA/CTX

 ;
  0
  0
 f
 w
 
 L
  0
 
 w
 *
  ]!
"  !2#
$ !"4%
& ]'
( +*$-
0 %,MMOEODAqq41a4OE	)
 yy~~,5i	{%(7'5  
 	

 <@  
 	
9 D* Fs   
C5
C5
 
C;.C;r\  c               z    SS jnU Vs/ s H
  oT" U5      PM     nnU R                   R                  SXbUS9$ s  snf )rc  c                b    U R                  5        VVs0 s H  u  pUc  M
  X_M     snn$ s  snnf r   re  rf  s      rI   rg  3SyncRunsClient.create_batch.<locals>.filter_payload  ri  rj  rk  r  rl  r  rm  s          rI   rp  SyncRunsClient.create_batch
  sK    	G <DD8N7+8Dyy~~&  
 	
 Es   8Trr  c                   g r   r   ru  s                         rI   rv  SyncRunsClient.wait  s    2 '*rK   rx  c                   g r   r   rz  s                       rI   rv  r  6  s    . '*rK   )r-  r  r|  r  r{  r0  r  r  r1  r2  r5  r4  r<  r6  r7  r8  rs  rS   r   r9  r?  c          
       ^ Ub  [         R                  " S[        SS9  0 SU_SU(       a,  UR                  5        VVs0 s H  u  nnUc  M  UU_M     snnOS_SU_SU_S	U_S
U_SU_SU_SU_SU	_SU
_SU_SU_SU_SU_SU_SU_UUS.EnSU4S jjnUb  SU S3OSnU R                  R                  USUR                  5        VVs0 s H  u  nnUc  M  UU_M     snnUUT(       a  US9$ SS9$ s  snnf s  snnf )aK  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.
    context: Static context to add to the assistant.
        !!! version-added "Supported with langgraph>=0.6.0"
    checkpoint: The checkpoint to resume from.
    checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
    interrupt_before: Nodes to interrupt immediately before they get executed.
    interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
    webhook: Webhook to call after LangGraph API call is done.
    on_disconnect: The disconnect mode to use.
        Must be one of 'cancel' or 'continue'.
    on_completion: Whether to delete or keep the thread created for a stateless run.
        Must be one of 'delete' or 'keep'.
    multitask_strategy: Multitask strategy to use.
        Must be one of 'reject', 'interrupt', 'rollback', or 'enqueue'.
    if_not_exists: How to handle missing thread. Defaults to 'reject'.
        Must be either 'reject' (raise error if missing), or 'create' (create new thread).
    after_seconds: The number of seconds to wait before starting the run.
        Use to schedule future runs.
    raise_error: Whether to raise an error if the run fails.
    headers: Optional custom headers to include with the request.
    on_run_created: Optional callback to call when a run is created.
    durability: The durability to use for the run. Values are "sync", "async", or "exit".
        "async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
        "sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
        "exit" means checkpoints are only persisted when the run exits, does not save intermediate steps

Returns:
    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"},
        context={"model_name": "anthropic"},
        interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
        interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
        webhook="https://my.fake.webhook.com",
        multitask_strategy="interrupt"
    )
    print(final_state_of_run)
    ```

    ```shell

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

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

NrA  r  r  r-  r  r  r{  r|  ra  r1  r2  r5  r  r  r6  r7  r4  r0  r<  r8  )rs  r?  c                L   > T(       a  [        U 5      =n(       a	  T" U5        gggrE  rF  rG  s     rI   r   (SyncRunsClient.wait.<locals>.on_response  rI  rK   r  r|  rJ  r   rK  )r
  r  rN  r   r   r  )r   rd   ra  r-  r  r|  r  r{  r0  r  r  r1  r2  r5  r4  r<  r6  r7  r8  rs  rS   r   r9  r?  rP  rQ  r  r   rR  s                         `      rI   rv  r  O  s   h (MMv"

U
GN'--/C/$!QQA/CTX

 f
 w
 
 L
  0
 
 w
 *
 ]
 !"4
 ]
  ]!
"  !2#
$ ]%
& ]'
( '$+
0	) 2;1Fi	{*-L 	 yy**#*==?D?41aa$!Q$?D'5 + 
 	
 <@ + 
 	
; D@ Es   
C2
C2
	
C8C8r  r   r  c                   X#S.nUb  XHS'   U(       a  XXS'   U(       a  UR                  U5        U R                  R                  SU S3XS9$ )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.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters 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,
    )
    ```

r  r  r  r  r_  r   rh  r  s	            rI   r]   SyncRunsClient.list  s_    F 27'I%+"%+"'yy}}	{%(  
 	
rK   c               B    U R                   R                  SU SU 3X4S9$ )aZ  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",
    )
    ```
r  r  r\  r_  r  s        rI   re   SyncRunsClient.get   s0    : yy}}	{&17  
 	
rK   r  r  c                   U(       a  SOSUS.nU(       a  UR                  U5        U(       a$  U R                  R                  SU SU S3SSUUS	9$ U R                  R                  SU SU S3SUUS	9$ )
a  Get a run.

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

Returns:
    None

???+ example "Example Usage"

    ```python
    client = get_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"
    )
    ```

r  r   r  r  r  r  rJ  Nr   r  r  s           rI   r  SyncRunsClient.cancelA  s    L A1
 '99..I;fVHG<# /   yy~~	{&8	  
 	
rK   c               H    U R                   R                  SU SU S3SUUS9$ )a  Block until a run is done. Returns the final state of the thread.

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

Returns:
    None

???+ example "Example Usage"

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

r  r  r  r  r\  r  r  s        rI   r  SyncRunsClient.join{  s;    < yy**	{&6	 + 
 	
rK   r  c                   UUS.nU(       a  UR                  U5        U R                  R                  SU SU S3SU0 U(       a  SU0O0 EU=(       d    0 E=(       d    SS9$ )	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.
    params: Optional query parameters to include with the request.
    last_event_id: The last event ID to use for the stream.

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

)r  r  r  r  r  r  r  Nr   r  r  s	            rI   r  SyncRunsClient.join_stream  s    T '$8
 'yy	{&87DO]3"=b     	
 		
rK   c               D    U R                   R                  SU SU 3X4S9  g)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.
    params: Optional query parameters 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"
    )
    ```

r  r  r\  Nr  r  s        rI   r   SyncRunsClient.delete  s-    < 				{&17 	 	
rK   rX  ra  )0rd   r;  ra  r;  r-  r'  r  r  r  r  r.  r  r|  r'  r  r  r{  r  r  r$  r  r  r0  r  r1  r  r2  r  r3  r  r4  r  r5  r  r6  r  r7  r  r8  r  rS   r=  r   r<  r9  r  r   rE  ).rd   r   ra  r;  r-  r'  r  r  r  r  r.  r  r/  r  r|  r'  r  r  r{  r  r0  r  r1  r  r2  r  r3  r  r4  r  r<  r  r7  r  r5  r  r8  r  rS   r=  r   r<  r9  r  r   rE  )6rd   r  ra  r;  r-  r'  r  r  r  r  r.  r  r/  r  r|  r'  r  r  r{  r  r  r$  r  r  r0  r  r1  r  r2  r  r3  r  r4  r  r<  r  r5  r  r6  r  r7  r  r8  r  rS   r=  r   r<  r9  r  r?  r  r   rE  )*rd   r   ra  r;  r-  r'  r  r  r  r  r.  r  r/  r  r|  r'  r  r  r{  r  r0  r  r1  r  r2  r  r5  r  r<  r  r7  r  r8  r  rS   r=  r   r<  r9  r  r   r'   r  r  r  r  r  )0rd   r  ra  r;  r-  r'  r  r  r|  r'  r  r  r{  r  r0  r  r  r$  r  r  r1  r  r2  r  r5  r  r4  r  r<  r  r6  r  r7  r  r8  r  rs  r  rS   r=  r   r<  r9  r  r?  r  r   r  r  r  r  r  )rd   r;  rc   r;  r  r  r  r  rS   r=  r   r<  r%  r  r   rE  r  r  r   rK   rI   r#  r#  8  sR     +/"&9A!&-1 $"&(,$()-7;6:.2/3"7;,0$(,0)-EI3## #
 (#  # 7# # +# #  # &# "# '# 5#  4!#" ,##$ -%#& '#( 5)#* *+#, "-#. */#0 '1#2 C3#4 
5# #8  +/"&9A!&!&-1 $"&)-7;6:.2/359,0"$(,0)-EI1## #
 (#  # 7# # # +# #  # '# 5# 4#  ,!#" -##$ 3%#& *'#( )#* "+#, *-#. '/#0 C1#2 
3# #@ +/"&9A!&!&-1 $"&(,$()-7;6:.2/359"7;,0$(,0)-EI(,9X
X
 X

 (X
  X
 7X
 X
 X
 +X
 X
  X
 &X
 "X
 'X
  5!X
" 4#X
$ ,%X
& -'X
( 3)X
* +X
, 5-X
. */X
0 "1X
2 *3X
4 '5X
6 C7X
8 &9X
: 
;X
t  +/"&9A!&!&-1 $"&)-7;6:"59,0$(,0)-EI- 
 (   7   +    ' 5 4  !" 3#$ *%& "'( *)* '+, C-. 
/ 2  +/"&9A!&!&-1 $"&(,$()-7;6:"7;,0$(,0)-EI1 
 (   7   +    & " '  5!" 4#$ %& 5'( *)* "+, *-. '/0 C12 
3 @ +/"&9A!&!&-1 $"&(,$()-7;6:"7;,059$(,0)-EI(,5v
v
 v

 (v
  v
 7v
 v
 v
 +v
 v
  v
 &v
 "v
 'v
  5!v
" 4#v
$ %v
& 5'v
( *)v
* 3+v
, "-v
. */v
0 '1v
2 C3v
4 &5v
6 
7v
x -1)-
!
 *	

 '
 

"  +/"&-1 $"&(,$()-7;6:"/37;,0$( ,0)-EI/** *
 (*  * +* *  * &* "* '* 5* 4* *  -!*" 5#*$ *%*& "'*( )** *+*, '-*. C/*0 
%1* *4  +/"&-1 $"&)-7;6:"/359,0$( ,0)-EI+** *
 (*  * +* *  * '* 5* 4* * -* 3*  *!*" "#*$ %*& *'*( ')** C+*, 
%-* *: +/"&-1 $"&)-(,$(7;6:"/3597;,0$( ,0)-EI(,3a
a
 a

 (a
  a
 +a
 a
  a
 'a
 &a
 "a
 5a
 4a
 a
  -!a
" 3#a
$ 5%a
& *'a
( ")a
* +a
, *-a
. '/a
0 C1a
2 &3a
4 
%5a
N #'.2,0)-,
,
 	,

 ,
 !,
 ,,
 *,
 ',
 
,
f -1)-

 

 *
 '
 

L *,0)-8
8
 8

 8
 8
 *8
 '8
 
8
~ -1)-#
#
 #

 *#
 '#
 
#
T &+@D,0)-$(8
8
 8

 #8
 >8
 *8
 '8
 "8
 
8
~ -1)- 
 
  

 * 
 ' 
 
 
  
rK   r#  c                  r   \ rS rSrSrSS jrSSSSSSSSSSSS.                             SS jjrSSSSSSSSSSSS.                           SS jjrSSS.       SS	 jjrSSS
SSSSSSS.	                   SS jjr	SSSSS.         SS jjr
Srg)r$  i  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                    Xl         g r   rX  r  s     rI   r   SyncCronClient.__init__  r  rK   Nr  c                   UUUUUUU	U
UUUS.nUR                  5        VVs0 s H  u  nnUc  M  UU_M     nnnU R                  R                  SU S3UUUS9$ s  snnf )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.
    context: Static context to add to the assistant.
        !!! version-added "Supported with langgraph>=0.6.0"
    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"},
        context={"model_name": "openai"},
        interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
        interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
        webhook="https://my.fake.webhook.com",
        multitask_strategy="interrupt"
    )
    ```
)r  r-  r  r|  r{  ra  r1  r2  r0  r5  r6  r  r  r  r  r  s                     rI   r   SyncCronClient.create_for_thread  s    x ! ( 0.!2"4
 %,MMOEODAqq41a4OEyy~~	{+.	  
 	
 Fs
   
AAc                   UUUUUUUU	U
UUS.nUR                  5        VVs0 s H  u  nnUc  M  UU_M     nnnU R                  R                  SXUS9$ s  snnf )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.
    context: Static context to add to the assistant.
        !!! version-added "Supported with langgraph>=0.6.0"
    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"},
        context={"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{  ra  r1  r2  r5  r0  r6  r  r  r  r  s                    rI   r  SyncCronClient.createb  s|    v ! ( 0.!2"4
 %,MMOEODAqq41a4OEyy~~  
 	
 Fs
   
AAr\  c               >    U R                   R                  SU 3X#S9  g)a  Delete a cron.

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

Returns:
    None

???+ example "Example Usage"

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

r  r\  Nr  r  s       rI   r   SyncCronClient.delete  s"    6 			<y17RrK   r  r   r  c       	            UUUUS.n
U(       a  XZS'   U(       a  XjS'   U(       a  XzS'   U
R                  5        VVs0 s H  u  pUc  M
  X_M     n
nnU R                  R                  SXU	S9$ s  snnf )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  r  r  r  s                rI   rg   SyncCronClient.search  s    ~ )"	
 !(I$.L! &H$+MMOEODAq414OEyy~~ w  
 	
 Fs   	A-	A-r  c               h    0 nU(       a  XS'   U(       a  X%S'   U R                   R                  SXSUS9$ )r  ra  rd   r  r  r  r  s         rI   r  SyncCronClient.count  s@    & #%&2N##,K yy~~gv  
 	
rK   rX  )r  r   r   r   r  r  r  r  r  r  r   rK   rI   r$  r$    s   "  +/-1 $"&)-3726")-,0)-!N
N
 N

 N
 (N
 +N
 N
  N
 'N
 1N
 0N
 N
 'N
 *N
  '!N
" 
#N
j +/-1 $"&)-3726")-,0)-J
J
 	J

 (J
 +J
 J
  J
 'J
 1J
 0J
 J
 'J
 *J
 'J
  
!J
` -1)-SS *	S
 'S 
S@ $( $%)'+/3,0)-M
 !M
 	M

 M
 M
 #M
 %M
 -M
 *M
 'M
 
M
d $( $,0)-
 !
 	

 *
 '
 

 
rK   r$  c                  $   \ rS rSrSrSS jr    S               SS jjrSSSS.           SS jjr  S         SS jjr       S                 SS	 jjr	     SSSS
.               SS jjjr
Srg)r%  i7  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                    Xl         g r   rX  rY  s     rI   r   SyncStoreClient.__init__E  r[  rK   Nc                   U H  nSU;   d  M  [        SU S35      e   UUUUUS.n	U R                  R                  S[        U	5      XgS9  g)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.
    params: Optional query parameters 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"}
    )
    ```
r  r  r  r  r  r  Nr  r  s
             rI   r  SyncStoreClient.put_itemH  sk    H Ee| /w6gh   #
 			!8' 	 	
rK   r  c                  U H  nSU;   d  M  [        SU S35      e   USR                  U5      S.nUb  X7S'   U(       a  UR                  U5        U R                  R	                  SXtS9$ )a  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'
    }
    ```
r  r  r  r)  rv  r  r  r   )rN   r  r   r   re   )r   rv  r)  r  rS   r   r  rj  s           rI   r  SyncStoreClient.get_item|  s{    X Ee| /w6gh    #)1DE"*5''yy}}^L}RRrK   c               @    U R                   R                  SX!S.UUS9  g)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.
    params: Optional query parameters 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  Nr  r  s        rI   r  SyncStoreClient.delete_item  s*    : 			5	 	 	
rK   c	               ^    UUUUUUS.n	U R                   R                  S[        U	5      UUS9$ )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.
    params: Optional query parameters 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 ...
        ]
    }
    ```
r  r  r  r  r  s
             rI   r  SyncStoreClient.search_items  sK    x !1&
 yy~~!(	  
 	
rK   r\  c               \    UUUUUS.nU R                   R                  S[        U5      UUS9$ )a5  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"],
        ...
    ]
    ```
r  r
  r  r  r  s	            rI   r  SyncStoreClient.list_namespaces#  sH    ` "
 yy~~(	  
 	
rK   rX  ra  r  r  r  r"  r  r  r  )NNNr  r   r  r  r   rK   rI   r%  r%  7  s    48,0)-2
 	2

 !2
 12
 2
 *2
 '2
 2
 
2
t $(,0)-7S 	7S 7S !7S *7S '7S 
7S| -1)-"
 	"

 *"
 '"
 "
 
"
P ,0 #',0)-H
 )	H

 H
 H
 H
 !H
 *H
 'H
'H
 
H
X $(#' $;
 -1)-;
 ;
 !;
 	;

 ;
 ;
 *;
 ';
 
;
 ;
rK   r%  c                b    U R                  5        VVs0 s H  u  pUc  M
  X_M     snn$ s  snnf r   re  )drP  rQ  s      rI   r  r  a  s(    WWY8YTQ!DADY888rj  zlist[httpx.ASGITransport]r   c                *    [          H	  nXl        M     g r   )r   rs   )rs   r   s     rI   configure_loopback_transportsr  i  s    +	 ,rK   r  )maxsizec                 h     SSK Jn   U R                  $ ! [         a    [        R                  s $ f = f)Nr   asgi_transport)langgraph_apir  ASGITransportImportErrorr   r  s    rI   r   r   n  s1    #0+++ #"""#s    11r   )rF   r  r   r  )rF   r  rQ   r=  r   zdict[str, str])r`   r	   r   r	   )ri   rL  r   zRunCreateMetadata | None)
rm   r  rF   r  rS   r=  rn   TimeoutTypes | Noner   ro   )r   r	   r   z#tuple[dict[str, str], bytes | None])r   rL  r   r	   )
rm   r  rF   r  rS   r=  rn   r  r   r  )r   r	   r   ztuple[dict[str, str], bytes])r  r  r   zdict[str, Any])rs   r	   r   r   )r   ztype[httpx.ASGITransport])qr   
__future__r   rI  	functoolsloggingrC   rer   r
  collections.abcr   r   r   r   typesr   typingr	   r
   r   r   r   r   r   rL  rO   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.   r/   r0   r1   r2   r3   r4   r5   r6   r7   langgraph_sdk.sser8   r9   r:   	getLoggerr   r   rM   rJ   rT   ra   compilerf   rl   r   ro   r   r   r   r   r   r   r   r   r  r  r   r8  r5  r!  r"  r#  r$  r%  r  r   __annotations__r  	lru_cacher   r  tupler   TimeoutTypesr   rK   rI   <module>r     s   #    	 	 
  F F     * * * * * * * * * * *V J I			8	$ "  )A(P 

< 
" (,#'^#	^# ^# &	^#
 !^# ^#B#, #,Lq qh	 n	
 n	
bE

 E

PT
 T
nD
 D
N
g
 g
X	 (,#'5'	5' 5' &	5'
 !5' 5'p&% &%Rq qh		0
j	
 j	
Zt	
 t	
nB
 B
Jw
 w
t	g
 g
T	9 57 1 6
 Q#  # 		(5/8E?
*+	(5/8E?HUOXe_
LM	MM	rK   