
    =Kia                        S r SSKJr  SSKJrJrJr  SSKJr  SSK	J
r
  SSKJrJrJrJrJrJrJrJrJrJrJrJrJrJr   " S S5      rg	)
z/Async client for managing threads in LangGraph.    )annotations)AsyncIteratorMappingSequence)Any)
HttpClient)
CheckpointJsonOnConflictBehaviorPruneStrategyQueryParamTypes	SortOrder
StreamPartThreadThreadSelectFieldThreadSortByThreadStateThreadStatusThreadStreamModeThreadUpdateStateResponsec                     \ 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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 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)/ThreadsClient   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 )Nhttp)selfr   s     ^/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/langgraph_sdk/_async/threads.py__init__ThreadsClient.__init__*   s    	    N)includeheadersparamsc                  #    0 nU(       a  SR                  U5      US'   U(       a  UR                  U5        U R                  R                  SU 3UU=(       d    SS9I Sh  vN $  N7f)a2  Get a thread by ID.

Args:
    thread_id: The ID of the thread to get.
    include: Additional fields to include in the response.
        Supported values: `"ttl"`.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    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'}
    }
    ```

,r"   	/threads/Nr#   r$   )joinupdater   get)r   	thread_idr"   r#   r$   query_paramss         r   r+   ThreadsClient.get-   sm     T (*&)hhw&7L#'YY]]	{#'4 # 
 
 	
 
s   A A)"A'#A))metadatar,   	if_exists
superstepsgraph_idttlr#   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:
    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"
    )
    ```
r,   r2   r/   r0   updatesvaluescommandas_node)r6   r7   r8   r1   Ndeleter3   strategyr3   z/threadsjsonr#   r$   )r+   
isinstanceintfloatr   post)r   r/   r,   r0   r1   r2   r3   r#   r$   payloadsus               r   createThreadsClient.createb   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/)r3   r#   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:
    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/   Nr9   r:   r3   r'   r<   )r>   r?   r@   r   patch)r   r,   r/   r3   r#   r$   rB   s          r   r*   ThreadsClient.update   st     D $.x"8?#U|,,),(!C!$YY__	{#	 % 
 
 	
 
s   AAAAr(   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(   N)r   r9   r   r,   r#   r$   s       r   r9   ThreadsClient.delete   s+     6 ii9+6WWWs   !+)+
   r   )r/   r6   idsstatuslimitoffsetsort_by
sort_orderselectr#   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)ag  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 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
    )
    ```

)rP   rQ   r/   r6   rN   rO   rR   rS   rT   z/threads/searchr<   Nr   rA   )r   r/   r6   rN   rO   rP   rQ   rR   rS   rT   r#   r$   rB   s                r   searchThreadsClient.search   s     ^ #
 "*J &H EN &H!(I$.L! &HYY^^	 $ 
 
 	
 
s   A2A;4A95A;)r/   r6   rO   r#   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)ac  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/   r6   rO   z/threads/countr<   NrV   )r   r/   r6   rO   r#   r$   rB   s          r   countThreadsClient.countB  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'   z/copyNr<   rV   rK   s       r   copyThreadsClient.copyb  s;     6 YY^^	{%(tW $ 
 
 	
 
s   #,*,r9   )r;   r#   r$   c               p   #    SU0nUS:w  a  X%S'   U R                   R                  SXSUS9I Sh  vN $  N7f)a  Prune threads by ID.

Args:
    thread_ids: List of thread IDs to prune.
    strategy: The prune strategy. `"delete"` removes threads entirely.
        `"keep_latest"` prunes old checkpoints but keeps threads and their
        latest state. Defaults to `"delete"`.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    A dict containing `pruned_count` (number of threads pruned).

???+ example "Example Usage"

    ```python
    client = get_client(url="http://localhost:2024")
    result = await client.threads.prune(
        thread_ids=["thread_1", "thread_2"],
    )
    print(result)  # {'pruned_count': 2}
    ```


thread_idsr9   r;   z/threads/pruner<   NrV   )r   r`   r;   r#   r$   rB   s         r   pruneThreadsClient.prune  sQ     B *#
 x"*JYY^^7F $ 
 
 	
 
s   -646F)	subgraphsr#   r$   c                 #    U(       a*  U R                   R                  SU S3X$S.UUS9I Sh  vN $ U(       aC  SU0nU(       a  0 UE[        U5      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5      EnU R                   R                  SU S	3UUS9I Sh  vN $  N NG 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:
    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'   z/state/checkpoint)
checkpointrc   r<   Nrc   z/state/)r$   r#   /state)r   rA   dictr+   )r   r,   re   checkpoint_idrc   r#   r$   
get_paramss           r   	get_stateThreadsClient.get_state  s     \ I;&78$.G	 (    %y1J;
;d6l;
I;gm_=! '    &y1J;
;d6l;
I;f-! '   's5   -CB?A	C9C:A C:C;CCC)r8   re   rh   r#   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:
    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': {}
        }
    }
    ```
r6   rh   re   r8   r'   rf   r<   NrV   )	r   r,   r6   r8   re   rh   r#   r$   rB   s	            r   update_stateThreadsClient.update_state2  sl     f f#
 '4O$$.L!!(IYY^^	{&)QW $ 
 
 	
 
s   AA
AA)rP   beforer/   re   r#   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:
    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,
    )
    ```

rP   ro   r/   re   r'   z/historyr<   NrV   )	r   r,   rP   ro   r/   re   r#   r$   rB   s	            r   get_historyThreadsClient.get_historyq  sp     J U#
  &H"*J$.L!YY^^	{(+	 $ 
 
 	
 
s   A	AAA	run_modes)last_event_idstream_moder#   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:
    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)
    ```

ru   r'   z/streamGETzLast-Event-IDr(   )r*   r   stream)r   r,   rt   ru   r#   r$   r-   s          r   join_streamThreadsClient.join_stream  sy     B ;
 'yy	{'*7DO]3"=b     
 	
s   AAr   )r   r   returnNone)
r,   strr"   Sequence[str] | Noner#   Mapping[str, str] | Noner$   QueryParamTypes | Noner{   r   )r/   r
   r,   
str | Noner0   zOnConflictBehavior | Noner1   z4Sequence[dict[str, Sequence[dict[str, Any]]]] | Noner2   r   r3   int | Mapping[str, Any] | Noner#   r   r$   r   r{   r   )r,   r}   r/   zMapping[str, Any]r3   r   r#   r   r$   r   r{   r   )r,   r}   r#   r   r$   r   r{   r|   )r/   r
   r6   r
   rN   r~   rO   ThreadStatus | NonerP   r?   rQ   r?   rR   zThreadSortBy | NonerS   zSortOrder | NonerT   zlist[ThreadSelectField] | Noner#   r   r$   r   r{   zlist[Thread])r/   r
   r6   r
   rO   r   r#   r   r$   r   r{   r?   )
r`   zSequence[str]r;   r   r#   r   r$   r   r{   zdict[str, Any])NN)r,   r}   re   Checkpoint | Nonerh   r   rc   boolr#   r   r$   r   r{   r   )r,   r}   r6   z&dict[str, Any] | Sequence[dict] | Noner8   r   re   r   rh   r   r#   r   r$   r   r{   r   )r,   r}   rP   r?   ro   zstr | Checkpoint | Noner/   zMapping[str, Any] | Nonere   r   r#   r   r$   r   r{   zlist[ThreadState])r,   r}   rt   r   ru   z-ThreadStreamMode | Sequence[ThreadStreamMode]r#   r   r$   r   r{   zAsyncIterator[StreamPart])__name__
__module____qualname____firstlineno____doc__r   r+   rE   r*   r9   rW   rZ   r]   ra   rj   rm   rq   ry   __static_attributes__ r!   r   r   r      sW    )-,0)-3
3
 &	3

 *3
 '3
 
3
p  $/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)-

 *	

 '
 

F #+,0)-'
!'
  	'

 *'
 ''
 
'
X )-$(	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-
 *-
 '-
 
#-
 -
r!   r   N)r   
__future__r   collections.abcr   r   r   typingr   langgraph_sdk._async.httpr   langgraph_sdk.schemar	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r   <module>r      s7    5 " < <  0   $w

 w

r!   