§
    ÚŽ’jé  ã            	       ó„   — d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	m
Z
mZ dedefd„Zd	edefd
„Z	 	 ddedededefd„ZdS )zThe tool module utils.é    N)ÚAnyÚDictÚCallable)Úparse)ÚFieldÚcreate_modelÚ
ConfigDictÚschemaÚreturnc                 óR  — d| v r|                       d¦  «         d| v rA| d                              ¦   «         D ]&}t          |t          ¦  «        rt	          |¦  «         Œ'd| v r0t          | d         t          ¦  «        rt	          | d         ¦  «         d| v r0t          | d         t          ¦  «        rt	          | d         ¦  «         d| v r\t          | d         t          ¦  «        rA| d                              ¦   «         D ]&}t          |t          ¦  «        rt	          |¦  «         Œ'| S )zLRemove the title field from the JSON schema to avoid
    misleading the LLM.ÚtitleÚ
propertiesÚitemsÚadditionalPropertiesz$defs)ÚpopÚvaluesÚ
isinstanceÚdictÚ_remove_title_field)r
   ÚpropÚ
def_schemas      úDC:\Projects\DSCons\.venv\Lib\site-packages\agentscope\tool\_utils.pyr   r   
   sD  € ð �&ÐÐØ�
Š
�7ÑÔÐð �vÐÐØ˜<Ô(×/Ò/Ñ1Ô1ð 	*ð 	*ˆDÝ˜$¥Ñ%Ô%ð *Ý# DÑ)Ô)Ð)øð �&ÐÐ�Z¨¨w¬½Ñ>Ô>ÐÝ˜F 7œOÑ,Ô,Ð,ð  Ð'Ð'­JØÐ%Ô&Ýñ-ô -Ð'õ 	˜FÐ#9Ô:Ñ;Ô;Ð;ð �&ÐÐ�Z¨¨w¬½Ñ>Ô>ÐØ  œ/×0Ò0Ñ2Ô2ð 	0ð 	0ˆJÝ˜*¥dÑ+Ô+ð 0Ý# JÑ/Ô/Ð/øà€Mó    Ú	docstringc                 óÖ   — t          | pd¦  «        }g }|j        �|                     |j        ¦  «         |j        �|                     |j        ¦  «         d                     |¦  «        S )zðExtract the function description from the docstring.

    Args:
        docstring (`str`):
            The docstring to extract the function description from.

    Returns:
        `str`:
            The extracted function description.
    Ú Nú
)r   Úshort_descriptionÚappendÚlong_descriptionÚjoin)r   Úparsed_docstringÚdescriptionss      r   Ú_extract_func_descriptionr$   .   so   € õ ˜Y˜_¨"Ñ-Ô-ÐØ€LØÔ)Ð5Ø×ÒÐ,Ô>Ñ?Ô?Ð?àÔ(Ð4Ø×ÒÐ,Ô=Ñ>Ô>Ð>à�9Š9�\Ñ"Ô"Ð"r   FÚ	tool_funcÚinclude_var_positionalÚinclude_var_keywordc                 óð  — t          | j        pd¦  «        }d„ |j        D ¦   «         }i }t          j        | ¦  «        j                             ¦   «         D �]ß\  }}|dv rŒ|j        t          j        j	        k    r¤|sŒ(|j
        t          j        j        k    rt          t          t          f         nt          t          |j
        f         t          |                     d|› �|                     |d¦  «        ¦  «        |j        |j        u ri n|j        ¬¦  «        f||<   ŒÉ|j        t          j        j        k    r—|sŒæ|j
        t          j        j        k    rt&          t                   nt&          |j
                 t          |                     d|› �|                     |d¦  «        ¦  «        |j        |j        u rg n|j        ¬¦  «        f||<   �Œz|j
        t          j        j        k    rt          n|j
        t          |                     |d¦  «        |j        |j        u rdn|j        ¬¦  «        f||<   �Œát)          	 dd
t+          d¬¦  «        i|¤Ž}|                     ¦   «         }	t/          |	¦  «         |	S )aë  Extract input schema from the tool function's docstring

    Args:
        tool_func (`Callable`):
            The tool function to extract the JSON schema from.
        include_var_positional (`bool`):
            Whether to include variable positional arguments in the JSON
            schema.
        include_var_keyword (`bool`):
            Whether to include variable keyword arguments in the JSON schema.

    Returns:
        `dict`:
            The extracted input JSON schema.
    r   c                 ó(   — i | ]}|j         |j        “ŒS © )Úarg_nameÚdescription)Ú.0Ú_s     r   ú
<dictcomp>z)_extract_input_schema.<locals>.<dictcomp>Y   s   € ÐLÐLÐL°a˜œ
 A¤MÐLÐLÐLr   )ÚselfÚclsz**N)r,   ÚdefaultÚ*.Ú_StructuredOutputDynamicClassÚ
__config__T)Úarbitrary_types_allowed)r4   )r   Ú__doc__ÚparamsÚinspectÚ	signatureÚ
parametersr   ÚkindÚ	ParameterÚVAR_KEYWORDÚ
annotationÚemptyr   Ústrr   r   Úgetr2   ÚVAR_POSITIONALÚlistr   r	   Úmodel_json_schemar   )
r%   r&   r'   r   Úparams_docstringÚfieldsÚnameÚparamÚ
base_modelÚparams_json_schemas
             r   Ú_extract_input_schemarL   D   sº  € õ( �iÔ'Ð-¨2Ñ.Ô.€IØLÐL¸9Ô;KÐLÑLÔLÐð €FÝÔ(¨Ñ3Ô3Ô>×DÒDÑFÔFð 7ñ 7‰ˆˆeà�?Ð"Ð"Øð Œ:�Ô*Ô6Ò6Ð6Ø&ð Øð Ô#¥wÔ'8Ô'>Ò>Ð>õ •S�#�X”�å�#˜uÔ/Ð/Ô0ÝØ 0× 4Ò 4Ø#˜T˜˜Ø(×,Ò,¨T°4Ñ8Ô8ñ!ô !ð
 ”}¨¬Ð3Ð3ð ˜Bàœðñ ô ð	ˆF�4‰LˆLð ŒZ�7Ô,Ô;Ò;Ð;Ø)ð Øð Ô#¥wÔ'8Ô'>Ò>Ð>õ •S”	�	å˜%Ô*Ô+ÝØ 0× 4Ò 4Ø"˜D˜
˜
Ø(×,Ò,¨T°4Ñ8Ô8ñ!ô !ð
 ”}¨¬Ð3Ð3ð ˜Bàœðñ ô ð	ˆF�4‰L‰Lð$ Ô#¥wÔ'8Ô'>Ò>Ð>õ �àÔ%ÝØ 0× 4Ò 4°T¸4Ñ @Ô @à”}¨¬Ð3Ð3ð  ˜Càœð	ñ ô ð	
ˆF�4‰L‰Lõ Ø'ðð å°dÐ;Ñ;Ô;ðð ðð €Jð
 $×5Ò5Ñ7Ô7Ðõ Ð*Ñ+Ô+Ð+àÐr   )FF)r7   r9   Útypingr   r   r   Údocstring_parserr   Úpydanticr   r   r	   r   r   rA   r$   ÚboolrL   r*   r   r   ú<module>rQ      s  ðà Ð Ø €€€Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à "Ð "Ð "Ð "Ð "Ð "Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4ð! ð !¨ð !ð !ð !ð !ðH#¨ð #°ð #ð #ð #ð #ð0 $)Ø %ð\ð \Øð\à ð\ð ð\ð 
ð	\ð \ð \ð \ð \ð \r   