§
    ÚŽ’jŽ  ã                   ó²   — d Z ddlmZmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZmZmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddlmZ  G d„ de¦  «        ZdS )zThe meta tool class.é    )ÚAnyÚList)ÚFieldÚcreate_model)ÚTemplateé   )Ú	ToolGroupé   )ÚPermissionContextÚPermissionDecisionÚPermissionBehavior)Ú	ToolChunk)ÚToolBaseÚToolMiddlewareBase)ÚDeveloperOrientedException)Ú	TextBlock)Ú
AgentStatec            	       ó  ‡ — e Zd ZU dZdZeed<   dZeed<   dZe	ed<   dZ
e	ed<   d	Ze	ed
<   dZe	ed<   d	Ze	ed<   	 ddee         dedee         dz  ddfˆ fd„Zedeeef         fd„¦   «         Zdeeef         dedefd„Zdededefd„Zˆ xZS )Ú
ResetToolszuA meta tool allows agent to self-manage its equipped tools by
    activating or deactivating tool groups dynamically.Úreset_toolsÚnameuA  This tool allows you to reset your equipped tools based on your current task requirements. These tools are organized into different groups, and you can activate/deactivate them by specifying the boolean values for each group in the input.

**Important: The input booleans are the final state of their corresponding tool groups, not incremental changes.** Any group not explicitly set to True will be deactivated, regardless of its previous state.

**Best practice**: Actively manage your tool groupsâ€”â€”activate only what you need for the current task, and promptly deactivate groups as soon as they are no longer needed to conserve context space.

This tool will return the usage instructions for the activated tool groups, which you **MUST pay attention to and follow**. You can also reuse this tool to re-check the instructions.ÚdescriptionFÚis_mcpÚis_read_onlyTÚis_concurrency_safeÚis_external_toolÚis_state_injectedNÚgroupsÚresponse_templateÚmiddlewaresÚreturnc                 óh   •— t          ¦   «                              |¬¦  «         || _        || _        dS )z6Initialize the meta tool with the current tool groups.)r    N)ÚsuperÚ__init__r   r   )Úselfr   r   r    Ú	__class__s       €úLC:\Projects\DSCons\.venv\Lib\site-packages\agentscope\tool\_builtin\_meta.pyr$   zResetTools.__init__0   s5   ø€ õ 	‰Œ×Ò [ÐÑ1Ô1Ð1ØˆŒØ!2ˆÔÐÐó    c                 óÀ   — i }| j         D ]3}|j        dk    rŒt          t          d|j        ¬¦  «        f||j        <   Œ4t          di |¤Ž}|                     ¦   «         }|S )zYDynamically generate the input schema based on the current
        available tool groups.ÚbasicF)Údefaultr   Ú_DynamicModel)r,   )r   r   Úboolr   r   r   Úmodel_json_schema)r%   ÚfieldsÚgroupÚmodelÚschemas        r'   Úinput_schemazResetTools.input_schema;   s„   € ð ˆØ”[ð 		ð 		ˆEØŒz˜WÒ$Ð$ØåÝØ!Ø %Ô 1ðñ ô ð"ˆF�5”:ÑÐõ Ð7Ð7°Ð7Ð7ˆØ×(Ò(Ñ*Ô*ˆØˆr(   Ú
tool_inputÚcontextc              ƒ   ó<   K  — t          t          j        d ¬¦  «        S )z-The meta tool is always allowed to be called.)ÚbehaviorÚmessage)r   r   ÚALLOW)r%   r4   r5   s      r'   Úcheck_permissionszResetTools.check_permissionsO   s(   è è € õ "Ý'Ô-ØCð
ñ 
ô 
ð 	
r(   Ú_agent_stateÚkwargsc              ‹   óR  ‡K  — |€t          d¦  «        ‚|j        j                             ¦   «          g Š|                     ¦   «         D ]f\  }}t          |t          ¦  «        s5t          t          d|› dt          |¦  «        › d�¬¦  «        g¬¦  «        c S |r‰ 
                    |¦  «         Œg|j        j                             ‰¦  «         t          | j        ¦  «        }ˆfd„| j        D ¦   «         }t          t          |                     |¬	¦  «        ¬¦  «        g¬¦  «        S )
zmActivate or deactivate tool groups based on the input arguments,
        and return their usage instructions.Nz0Error: ResetTools requires state to be provided.z Invalid arguments: the argument z! should be a bool value, but got ú.)Útext)Úcontentc                 ó&   •— g | ]}|j         ‰v ¯|‘ŒS © )r   )Ú.0Ú_Úto_activates     €r'   ú
<listcomp>z#ResetTools.call.<locals>.<listcomp>{   s%   ø€ ÐLÐLÐL !°a´fÀÐ6KÐ6K˜AÐ6KÐ6KÐ6Kr(   )r   )r   Útool_contextÚactivated_groupsÚclearÚitemsÚ
isinstancer-   r   r   ÚtypeÚappendÚextendr   r   r   Úrender)r%   r;   r<   ÚkeyÚvalueÚtemplaterH   rE   s          @r'   ÚcallzResetTools.callZ   s|  øè è € ð ÐÝ,ØBñô ð ð
 	Ô!Ô2×8Ò8Ñ:Ô:Ð:àˆØ Ÿ,š,™.œ.ð 	(ð 	(‰JˆC�Ý˜e¥TÑ*Ô*ð Ý å!ð"NÀCð "Nð "NÝ?CÀE¹{¼{ð"Nð "Nð "Nðñ ô ððñ ô ð ð ð ð ð (Ø×"Ò" 3Ñ'Ô'Ð'øàÔ!Ô2×9Ò9¸+ÑFÔFÐFå˜DÔ2Ñ3Ô3ˆØLÐLÐLÐL t¤{ÐLÑLÔLÐÝåØ!ŸšÐ0@˜ÑAÔAðñ ô ðð
ñ 
ô 
ð 	
r(   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚstrÚ__annotations__r   r   r-   r   r   r   r   Úlistr	   r   r   r$   ÚpropertyÚdictr   r3   r   r   r:   r   r   rS   Ú__classcell__)r&   s   @r'   r   r      s¡  ø€ € € € € € ð;ð ;ð €Dˆ#ÐÐÑð	=ð �ð ð ñ ð  €FˆDÐÐÑØ€L�$ÐÐÑØ $Ð˜Ð$Ð$Ñ$Ø"Ð�dÐ"Ð"Ñ"Ø"Ð�tÐ"Ð"Ñ"ð 8<ð		3ð 	3à�Y”ð	3ð ð	3ð Ð,Ô-°Ñ4ð		3ð
 
ð	3ð 	3ð 	3ð 	3ð 	3ð 	3ð ð˜d 3¨ 8œnð ð ð ñ „Xðð&	
à˜˜c˜”Nð	
ð #ð	
ð 
ð		
ð 	
ð 	
ð 	
ð(
à ð(
ð ð(
ð 
ð	(
ð (
ð (
ð (
ð (
ð (
ð (
ð (
r(   r   N)rW   Útypingr   r   Úpydanticr   r   Újinja2r   Ú_tool_groupr	   Ú
permissionr   r   r   Ú	_responser   Ú_baser   r   Ú	exceptionr   r8   r   Ústater   r   rB   r(   r'   ú<module>rg      s1  ðà Ð Ø Ð Ð Ð Ð Ð Ð Ð à (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø Ð Ð Ð Ð Ð à #Ð #Ð #Ð #Ð #Ð #ðð ð ð ð ð ð ð ð ð ð
 "Ð !Ð !Ð !Ð !Ð !Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø  Ð  Ð  Ð  Ð  Ð  Ø Ð Ð Ð Ð Ð ðm
ð m
ð m
ð m
ð m
�ñ m
ô m
ð m
ð m
ð m
r(   