
    c
ih                        d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
Z
ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZ  G d d	          ZdS )
z2Async client for managing assistants in LangGraph.    )annotations)Mapping)AnyLiteralcastoverloadN)
HttpClient)	AssistantAssistantSelectFieldAssistantSortByAssistantsSearchResponseAssistantVersionConfigContextGraphSchemaJsonOnConflictBehaviorQueryParamTypes	SortOrder	Subgraphsc                  r   e Zd ZdZdOdZddddPdZdddddQdZddddRdZ	 	 dSddddTdZ	 dUddddddddddVd+Z	ddddddddd,dWd-Z
dddd.dXd0Zedddd1d2dddddd3
dYd@            Zedddd1d2ddddAdddBdZdE            Zdddd1d2ddddAdddBd[dHZddddddId\dJZ	 	 	 d]dddd^dLZdddd_dNZdS )`AssistantsClienta]  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")
        ```
    httpr	   returnNonec                    || _         d S N)r   )selfr   s     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langgraph_sdk/_async/assistants.py__init__zAssistantsClient.__init__*   s    			    Nheadersparamsassistant_idstrr#   Mapping[str, str] | Noner$   QueryParamTypes | Noner
   c               R   K   | j                             d| ||           d{V S )a  Get an assistant by ID.

        Args:
            assistant_id: The ID of the assistant to get.
            headers: Optional custom headers to include with the request.
            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   getr   r%   r#   r$   s       r   r,   zAssistantsClient.get-   sS      R Y]])<))76 # 
 
 
 
 
 
 
 
 	
r!   F)xrayr#   r$   r.   
int | booldict[str, list[dict[str, Any]]]c                  K   d|i}|r|                     |           | j                            d| d||           d{V S )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__'}
                    ]
            }
            ```


        r.   r*   z/graphr$   r#   N)updater   r,   )r   r%   r.   r#   r$   query_paramss         r   	get_graphzAssistantsClient.get_graphZ   s{      d ~ 	('''Y]]/<///g # 
 
 
 
 
 
 
 
 	
r!   r   c               T   K   | j                             d| d||           d{V S )a  Get the schemas of an assistant by ID.

        Args:
            assistant_id: The ID of the assistant to get the schema of.
            headers: Optional custom headers to include with the request.
            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*   z/schemasr"   Nr+   r-   s       r   get_schemaszAssistantsClient.get_schemas   sV      j Y]]1<11176 # 
 
 
 
 
 
 
 
 	
r!   	namespace
str | Nonerecurseboolr   c                  K   d|i}|ri |t          |          }|)| j                            d| d| ||           d{V S | j                            d| d||           d{V S )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.

        r:   Nr*   z/subgraphs/r2   z
/subgraphs)dictr   r,   )r   r%   r8   r:   r#   r$   
get_paramss          r   get_subgraphszAssistantsClient.get_subgraphs  s      ,  )
 	87J7$v,,7J C|CC	CC! '          7|777! '         r!   )contextmetadatar%   	if_existsnamer#   descriptionr$   graph_idconfigConfig | Noner@   Context | NonerA   r   rB   OnConflictBehavior | NonerC   rD   c                  K   d|i}|r||d<   |r||d<   |r||d<   |r||d<   |r||d<   |r||d<   |	r|	|d<   | j                             d	|||

           d{V S )a  Create a new assistant.

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

        Args:
            graph_id: The ID of the graph the assistant should use. The graph ID is normally set in your langgraph.json configuration.
            config: Configuration to use for the graph.
            metadata: Metadata to add to assistant.
            context: Static context to add to the assistant.
                !!! version-added "Added in version 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"
            )
            ```
        rE   rF   r@   rA   r%   rB   rC   rD   z/assistantsjsonr#   r$   Nr   post)r   rE   rF   r@   rA   r%   rB   rC   r#   rD   r$   payloads               r   createzAssistantsClient.create3  s      f #
  	' &GH 	)!(GI 	+"*GJ 	3&2GN# 	-#,GK  	#"GFO 	1%0GM"Y^^ $ 
 
 
 
 
 
 
 
 	
r!   )rE   rF   r@   rA   rC   r#   rD   r$   c                  K   i }
|r||
d<   |||
d<   |||
d<   |r||
d<   |r||
d<   |r||
d<   | j                             d| |
||		           d{V S )
a  Update an assistant.

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

        Args:
            assistant_id: Assistant to update.
            graph_id: The ID of the graph the assistant should use.
                The graph ID is normally set in your langgraph.json configuration. If `None`, assistant will keep pointing to same graph.
            config: Configuration to use for the graph.
            context: Static context to add to the assistant.
                !!! version-added "Added in version 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:
            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}
            )
            ```

        rE   NrF   r@   rA   rC   rD   r*   rK   )r   patch)r   r%   rE   rF   r@   rA   rC   r#   rD   r$   rO   s              r   r3   zAssistantsClient.updatez  s      ^ #% 	+"*GJ &GH!(GI 	+"*GJ 	#"GFO 	1%0GM"Y__)<))	 % 
 
 
 
 
 
 
 
 	
r!   )delete_threadsr#   r$   rS   c                  K   i }|rd|d<   |r|                     |           | j                            d| ||pd           d{V  dS )a  Delete an assistant.

        Args:
            assistant_id: The assistant ID to delete.
            delete_threads: If true, delete all threads with `metadata.assistant_id`
                matching this assistant, along with runs and checkpoints belonging to
                those threads.
            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"
            )
            ```

        TrS   r*   Nr"   )r3   r   delete)r   r%   rS   r#   r$   r4   s         r   rU   zAssistantsClient.delete  s      > (* 	2-1L)* 	('''i)<))'4  
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r!   
   r   )
rA   rE   rC   limitoffsetsort_by
sort_orderselectr#   r$   rW   intrX   rY   AssistantSortBy | NonerZ   SortOrder | Noner[   !list[AssistantSelectField] | Noneresponse_formatLiteral['object']r   c               
   K   d S r    r   rA   rE   rC   rW   rX   rY   rZ   r[   r`   r#   r$   s               r   searchzAssistantsClient.search  s       $'3r!   array)rA   rE   rC   rW   rX   rY   rZ   r[   r`   r#   r$   Literal['array']list[Assistant]c               
   K   d S r   rc   rd   s               r   re   zAssistantsClient.search  s       #r!   Literal['array', 'object']*AssistantsSearchResponse | list[Assistant]c               R  K   |	dvrt          d|	          ||d}|r||d<   |r||d<   |r||d<   |r||d<   |r||d<   |r||d	<   d
dfd}t          t          t                   | j                            d||
||	dk    r|nd
           d
{V           }|	dk    r|dS |S )ak  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.
            name: The name of the assistant to filter by.
                The filtering logic will match assistants where 'name' is a substring (case insensitive) of the assistant name.
            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.
            select: Specific assistant fields to include in the response.
            response_format: Controls the response shape. Use `"array"` (default)
                to return a bare list of assistants, or `"object"` to return
                a mapping containing assistants plus pagination metadata.
                Defaults to "array", though this default will be changed to "object" in a future release.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            A list of assistants (when `response_format="array"`) or a mapping
            with the assistants and the next pagination cursor (when
            `response_format="object"`).

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            response = await client.assistants.search(
                metadata = {"name":"my_name"},
                graph_id="my_graph_id",
                limit=5,
                offset=5,
                response_format="object"
            )
            next_cursor = response["next"]
            assistants = response["assistants"]
            ```
        )rf   objectz1response_format must be 'array' or 'object', got rW   rX   rA   rE   rC   rY   rZ   r[   Nresponsehttpx.Responser   r   c                <    | j                             d          d S )NzX-Pagination-Next)r#   r,   )ro   next_cursors    r   capture_paginationz3AssistantsClient.search.<locals>.capture_paginationV  s    "*../BCCKKKr!   z/assistants/searchrm   )rL   r#   r$   on_response)
assistantsnext)ro   rp   r   r   )
ValueErrorr   listr
   r   rN   )r   rA   rE   rC   rW   rX   rY   rZ   r[   r`   r#   r$   rO   rs   ru   rr   s                  @r   re   zAssistantsClient.search	  sl     n "555WOWW   #
 #
  	+"*GJ 	+"*GJ 	#"GFO 	)!(GI 	/$.GL! 	' &GH"&	D 	D 	D 	D 	D 	D O)..$2AX2M2M..SW !        	
 	

 h&&",kBBBr!   )rA   rE   rC   r#   r$   c               |   K   i }|r||d<   |r||d<   |r||d<   | j                             d|||           d{V S )aO  Count assistants matching filters.

        Args:
            metadata: Metadata to filter by. Exact match for each key/value.
            graph_id: Optional graph id to filter by.
            name: Optional name to filter by.
                The filtering logic will match assistants where 'name' is a substring (case insensitive) of the assistant name.
            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.
        rA   rE   rC   z/assistants/countrK   NrM   )r   rA   rE   rC   r#   r$   rO   s          r   countzAssistantsClient.counth  s      , #% 	+"*GJ 	+"*GJ 	#"GFOY^^gwv $ 
 
 
 
 
 
 
 
 	
r!   list[AssistantVersion]c               n   K   ||d}|r||d<   | j                             d| d|||           d{V S )a%  List all versions of an assistant.

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

        Returns:
            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"
            )
            ```
        rn   rA   r*   z	/versionsrK   NrM   )r   r%   rA   rW   rX   r#   r$   rO   s           r   get_versionszAssistantsClient.get_versions  s      D #
 #
  	+"*GJY^^2<222	 $ 
 
 
 
 
 
 
 
 	
r!   versionc               ^   K   d|i}| j                             d| d|||           d{V S )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 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
            )
            ```

        r~   r*   z/latestrK   NrM   )r   r%   r~   r#   r$   rO   s         r   
set_latestzAssistantsClient.set_latest  sd      > $-g"6Y^^0<000	 $ 
 
 
 
 
 
 
 
 	
r!   )r   r	   r   r   )r%   r&   r#   r'   r$   r(   r   r
   )
r%   r&   r.   r/   r#   r'   r$   r(   r   r0   )r%   r&   r#   r'   r$   r(   r   r   )NF)r%   r&   r8   r9   r:   r;   r#   r'   r$   r(   r   r   r   )rE   r9   rF   rG   r@   rH   rA   r   r%   r9   rB   rI   rC   r9   r#   r'   rD   r9   r$   r(   r   r
   )r%   r&   rE   r9   rF   rG   r@   rH   rA   r   rC   r9   r#   r'   rD   r9   r$   r(   r   r
   )
r%   r&   rS   r;   r#   r'   r$   r(   r   r   )rA   r   rE   r9   rC   r9   rW   r\   rX   r\   rY   r]   rZ   r^   r[   r_   r`   ra   r#   r'   r$   r(   r   r   )rA   r   rE   r9   rC   r9   rW   r\   rX   r\   rY   r]   rZ   r^   r[   r_   r`   rg   r#   r'   r$   r(   r   rh   )rA   r   rE   r9   rC   r9   rW   r\   rX   r\   rY   r]   rZ   r^   r[   r_   r`   rj   r#   r'   r$   r(   r   rk   )rA   r   rE   r9   rC   r9   r#   r'   r$   r(   r   r\   )NrV   r   )r%   r&   rA   r   rW   r\   rX   r\   r#   r'   r$   r(   r   r{   )
r%   r&   r~   r\   r#   r'   r$   r(   r   r
   )__name__
__module____qualname____doc__r    r,   r5   r7   r?   rP   r3   rU   r   re   rz   r}   r   rc   r!   r   r   r      s            -1)-+
 +
 +
 +
 +
 +
b !,0)-8
 8
 8
 8
 8
 8
| -1)-w
 w
 w
 w
 w
 w
x !%	$ -1)-$ $ $ $ $ $R !%E

 #'#'/3,0"&)-E
 E
 E
 E
 E
 E
V  $ $"&,0"&)-A
 A
 A
 A
 A
 A
N  %,0)-(
 (
 (
 (
 (
 (
T  #*.'+48,0)-' ' ' ' ' X'   #*.'+48,3,0)-     X& #*.'+486=,0)-] ] ] ] ] ]D #,0)-
 
 
 
 
 
H ,
 -1)-,
 ,
 ,
 ,
 ,
 ,
f -1)-&
 &
 &
 &
 &
 &
 &
 &
r!   r   )r   
__future__r   collections.abcr   typingr   r   r   r   httpxlanggraph_sdk._async.httpr	   langgraph_sdk.schemar
   r   r   r   r   r   r   r   r   r   r   r   r   r   rc   r!   r   <module>r      s@   8 8 " " " " " " # # # # # # / / / / / / / / / / / /  0 0 0 0 0 0                             "A
 A
 A
 A
 A
 A
 A
 A
 A
 A
r!   