§
    ÚŽ’jãa  ã                   ó8  — d Z ddlZddl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 ddlmZmZ dd	lm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m 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dl*m+Z+ ddl,m-Z- ddl.m/Z/ dZ0dZ1 G d„ d¦  «        Z2dS )z/The toolkit class for tool calls in AgentScope.é    N)ÚOrderedDict)ÚAsyncGeneratorÚTypeÚ	GeneratorÚSequence)ÚTemplate)Ú	BaseModelÚFieldÚcreate_modelé   )Ú
ResetToolsÚSkillViewer)ÚToolBase)ÚToolResponseÚ	ToolChunké   )ÚSkillLoaderBaseÚSkill)ÚRegisteredTool)Ú_describe_exceptionÚ_json_loads_with_repair)ÚDeveloperOrientedExceptionÚToolNotFoundErrorÚToolGroupInactiveError)Ú	MCPClient)ÚToolCallBlockÚ	TextBlockÚToolResultState)Ú	ToolGroup)Úlogger)Ú
AgentStateaC  {% if groups | length == 0 %}All tool groups are currently deactivated.{% else %}The currently activated tool group(s): {{ groups | map(attribute='name') | join(', ') }}.{% if groups | selectattr('instructions', 'ne', None) | list | length > 0 %}
<tool-instructions>
The tool instructions are a collection of suggestions, rules and notifications about how to use the tools in the activated groups.
{% for group in groups %}{% if group.instructions %}<group name="{{ group.name }}">{{ group.instructions }}</group>{% endif %}{% endfor %}
</tool-instructions>{% endif %}{% endif %}a:  <agent-skills>
Skills are a collection of instructions, scripts, and resources to extend your capabilities.

**IMPORTANT**: Skills are NOT tools, and you cannot call a skill directly. To use a skill, you MUST use the `{{ skill_viewer }}` tool to read the skill's full instructions, and then follow those instructions to use the tools and resources provided by the skill.

# Available Skills:{% for skill in skills %}
<skill>
<name>{{ skill.name }}</name>
<description>{{ skill.description }}</description>
<dir>{{ skill.dir }}</dir>
</skill>{% endfor %}
</agent-skills>
c                   ó*  — e Zd ZdZddddeefdee         dz  dee	e
z  ez           dz  dee         dz  dee         dz  de	de	d	dfd
„Z	 ddee	         dz  d	ee         fd„Zdeded	eeez  df         fd„Z	 ddee	         dz  d	ee	e
f         fd„Z	 ddee	         dz  d	e	dz  fd„Zdee	         dz  d	ee	ef         fd„Zde	dee	         d	efd„Zde	d	edz  fd„Zd	ee         fd„Zd d„Z 	 d!deee         z  de	d	dfd„Z!de	ee	         z  d	dfd„Z"dS )"ÚToolkitaÊ  Toolkit is the core module to register, manage and delete tool
    functions, MCP clients, Agent skills in AgentScope.

    About tool functions:

    - Register and parse JSON schemas from their docstrings automatically.
    - Group-wise tools management, and agentic tools activation/deactivation.
    - Extend the tool function JSON schema dynamically with Pydantic BaseModel.
    - Tool function execution with unified streaming interface.

    About MCP clients:

    - Register tool functions from MCP clients directly.
    - Client-level tool functions removal.

    About Agent skills:

    - Register agent skills from the given directory.
    - Provide prompt for the registered skills to the agent.
    NÚtoolsÚskills_or_loadersÚmcpsÚtool_groupsÚmeta_tool_response_templateÚskill_instruction_templateÚreturnc                 ót  — |�(t          d„ |D ¦   «         ¦  «        rt          d¦  «        ‚t          d|pg |pg |pg ¬¦  «        g|pg z   | _        t	          t          d„ | j        D ¦   «         ¦  «        ¦  «        t	          | j        ¦  «        k    rt          d¦  «        ‚| j        D ]2}|j        D ](}|j        r|j        st          d|j	        › d	�¦  «        ‚Œ)Œ3|| _
        || _        t          t          | j        |¬
¦  «        ¬¦  «        | _        t          t          | j        ¬¦  «        ¬¦  «        | _        dS )a\  Initialize the toolkit.

        Args:
            tools (`list[ToolBase] | None`, optional):
                The tool objects that belong to the "basic" tool group.
            skills_or_loaders (`list[str | Skill | SkillLoaderBase] | None`,             optional):
                The agent skill directories to be registered in the "basic"
                tool group.
            mcps (`list[MCPClient] | None`, optional):
                The mcp clients to be registered in the "basic" tool group.
            tool_groups (`list[ToolGroup] | None`, optional):
                The tool groups to be registered.
            meta_tool_response_template (`str`, optional):
                The template for meta tool responses.
            skill_instruction_template (`str`):
                A Jinja2 template for generating the agent skill instruction.
        Nc              3   ó,   K  — | ]}|j         d k    V — ŒdS )ÚbasicN©Úname©Ú.0Ú_s     úFC:\Projects\DSCons\.venv\Lib\site-packages\agentscope\tool\_toolkit.pyú	<genexpr>z#Toolkit.__init__.<locals>.<genexpr>u   s:   è è € ð +
ð +
Ø"#ˆAŒF�gÒð+
ð +
ð +
ð +
ð +
ð +
ó    z°The 'basic' tool group is reserved for the default tool group. Don't include 'basic' in the tool_groups argument when you also provide tools, skills or mcps in the constructor.r-   )r/   r$   r%   r&   c              3   ó$   K  — | ]}|j         V — Œd S ©Nr.   r0   s     r3   r4   z#Toolkit.__init__.<locals>.<genexpr>‰   s$   è è € Ð4Ð4˜a�1”6Ð4Ð4Ð4Ð4Ð4Ð4r5   z3Tool groups must not contain duplicate tool groups.zThe MCP client 'z!' is stateful, but not connected.)ÚgroupsÚresponse_template)Útool)Úget_skills_method)ÚanyÚ
ValueErrorr   r'   ÚlenÚsetr&   Úis_statefulÚis_connectedr/   r(   r)   r   r   Úbuiltin_meta_toolr   Ú_get_available_skillsÚbuiltin_skill_viewer)	Úselfr$   r%   r&   r'   r(   r)   ÚgroupÚclients	            r3   Ú__init__zToolkit.__init__X   sÖ  € ð: Ð"¥sð +
ð +
Ø'2ð+
ñ +
ô +
ñ (
ô (
Ð"õ ðñô ð õ ØØ�k˜rØ"3Ð"9°rØ�Z˜Rð	ñ ô ð
ð Ð˜Bñ ˆÔõ �sÐ4Ð4 4Ô#3Ð4Ñ4Ô4Ñ4Ô4Ñ5Ô5½ØÔñ:
ô :
ò 
ð 
õ ØEñô ð ð
 Ô%ð 	ð 	ˆEØœ*ð ð �ØÔ%ð ¨fÔ.Að Ý$ð*¨6¬;ð *ð *ð *ñô ð øðð ,GˆÔ(Ø*DˆÔ'å!/Ýð Ô'Ø"=ð	ñ ô ð"
ñ "
ô "
ˆÔõ %3ÝØ"&Ô"<ðñ ô ð%
ñ %
ô %
ˆÔ!Ð!Ð!r5   r8   c              ƒ   óÀ   K  — g }|                       |¦  «        ƒ d{V —†}|                     ¦   «         D ])}|                     |                     ¦   «         ¦  «         Œ*|S )a   Get the JSON schemas of the currently available tool functions
        based on the given activated tool groups.

        .. note:: The preset keyword arguments is removed from the JSON
         schema, and the extended model is applied if it is set.

        Args:
            groups (`list[str] | None`, optional):
                A list of group names to filter the tool function. The "basic"
                group will always be included regardless of the filter. If not
                provided, only the "basic" group will be included.

        Example:
            .. code-block:: JSON
                :caption: Example of tool function JSON schemas

                [
                    {
                        "type": "function",
                        "function": {
                            "name": "google_search",
                            "description": "Search on Google.",
                            "parameters": {
                                "type": "object",
                                "properties": {
                                    "query": {
                                        "type": "string",
                                        "description": "The search query."
                                    }
                                },
                                "required": ["query"]
                            }
                        }
                    },
                    ...
                ]

        Returns:
            `list[dict]`:
                A list of function JSON schemas.
        N)Ú_get_available_toolsÚvaluesÚappendÚget_tool_schema)rE   r8   Úfunction_schemasÚ
tools_dictr:   s        r3   Úget_tool_schemaszToolkit.get_tool_schemas«   sz   è è € ðZ Ðð  ×4Ò4°VÑ<Ô<Ð<Ð<Ð<Ð<Ð<Ð<ˆ
Ø×%Ò%Ñ'Ô'ð 	<ð 	<ˆDØ×#Ò# D×$8Ò$8Ñ$:Ô$:Ñ;Ô;Ð;Ð;àÐr5   Ú	tool_callÚstatec                ó�  K  — t          |j        ¬¦  «        }|                      |j        j        ¦  «        ƒ d{V —†}|j        |vrÿ|                      d„ | j        D ¦   «         ¬¦  «        ƒ d{V —†}|j        |v ry||j                 j        }t          t          d|j        › d|› d| j
        j        j        › d�¬	¦  «        gt          j        ¬
¦  «        }|W V — |                     |¦  «        W V — dS t          t          d|j        › d�¬	¦  «        gt          j        ¬
¦  «        }|W V — |                     |¦  «        W V — dS ||j                 j        }	 t          |j        ¦  «        }	|j        r|j        s|j        s||	d<   t)          j        |j        ¦  «        r |di |	¤Žƒ d{V —†}
n |di |	¤Ž}
t/          |
t          ¦  «        r|
W V — |                     |
¦  «         n�t/          |
t0          ¦  «        r&|
2 3 d{V —†}|W V — |                     |¦  «         Œ"6 nUt/          |
t2          ¦  «        r |
D ]}|W V — |                     |¦  «         Œn t5          dt7          |
¦  «        › d�¦  «        ‚�n?# t8          j        j        j        $ rR}t          t          dd|› �¬¦  «        gt          j        ¬
¦  «        }|W V — |                     |¦  «         Y d}~nÙd}~wt@          $ rt}t/          |t4          ¦  «        r|d‚t          t          dtC          |¦  «        ¬¦  «        gt          j        ¬
¦  «        }|W V — |                     |¦  «         Y d}~n]d}~wtD          j#        $ rH t          t          dd¬¦  «        gt          j$        ¬
¦  «        }|W V — |                     |¦  «         Y nw xY w|W V — dS # |W V — w xY w)aé  Call the tool function, return the incremental tool result in
        a ToolChunk stream, and finally return the complete tool result in a
        ToolResponse object. **Note the accumulation process occurs within this
        function, so the tool functions only need to return/yield the
        ToolChunk objects in an incremental manner.**

        Args:
            tool_call (`ToolCallBlock`):
                A tool call block.
            state (`AgentState`):
                The current agent state, used to state injection.

        Yields:
            `ToolChunk | ToolResponse`:
                The incremental tool result in a ToolChunk stream, and finally
                the complete tool result in a ToolResponse object.
        )ÚidNc                 ó   — g | ]	}|j         ‘Œ
S © r.   r0   s     r3   ú
<listcomp>z%Toolkit.call_tool.<locals>.<listcomp>   s   € Ð9Ð9Ð9 1˜œÐ9Ð9Ð9r5   )r8   ú"ToolGroupInactiveError: The tool 'ú' in group 'úM' is currently inactive. You should first activate the group by calling the 'ú' tool.)Útext)ÚcontentrR   ú#ToolNotFoundError: The tool named 'ú' doesn't exist.Ú_agent_statezoThe tool function must return a ToolChunk object, or an AsyncGenerator/Generator of ToolChunk objects, but got ú.r\   z&Error occurred when calling MCP tool: )Útyper\   zR<system-reminder>The tool call has been interrupted by the user.</system-reminder>rV   )%r   rT   rJ   Útool_contextÚactivated_groupsr/   r'   rF   r   r   rB   r:   r   ÚERRORÚappend_chunkr   ÚinputÚis_state_injectedÚis_mcpÚis_external_toolÚinspectÚiscoroutinefunctionÚ__call__Ú
isinstancer   r   r   rb   ÚmcpÚsharedÚ
exceptionsÚMcpErrorÚ	ExceptionÚstrÚasyncioÚCancelledErrorÚINTERRUPTED)rE   rQ   rR   Útool_responseÚavailable_toolsÚ	all_toolsÚ
group_nameÚchunkÚ	tool_funcÚkwargsÚresÚes               r3   Ú	call_toolzToolkit.call_toolá   s—  è è € õ, %¨	¬Ð5Ñ5Ô5ˆð !%× 9Ò 9ØÔÔ/ñ!
ô !
ð 
ð 
ð 
ð 
ð 
ð 
ˆð Œ> Ð0Ð0Ø"×7Ò7Ø9Ð9¨Ô(8Ð9Ñ9Ô9ð 8ñ ô ð ð ð ð ð ð ˆIð Œ~ Ð*Ð*Ø& y¤~Ô6Ô<�
Ý!å!ð!NØ$-¤Nð!Nð !NØ@Jð!Nð !Nð %)Ô$:Ô$?Ô$Dð	!Nð !Nð !Nðñ ô ð
õ *Ô/ðñ ô �ð ����Ø#×0Ò0°Ñ7Ô7Ð7Ð7Ð7Ð7Ø�õ åð=Ø%œNð=ð =ð =ðñ ô ðõ &Ô+ðñ ô ˆEð ˆKˆKˆKˆKØ×,Ò,¨UÑ3Ô3Ð3Ð3Ð3Ð3ØˆFð $ I¤NÔ3Ô8ˆ	ð[	 å,¨Y¬_Ñ=Ô=ˆFð Ô+ð/à!Ô(ð/ð "Ô2ð/ð
 */��~Ñ&åÔ*¨9Ô+=Ñ>Ô>ð *Ø%˜IÐ/Ð/¨Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/��ð  �iÐ)Ð) &Ð)Ð)�å˜#�yÑ)Ô)ð Ø�	�	�	�	Ø×*Ò*¨3Ñ/Ô/Ð/Ð/õ ˜C¥Ñ0Ô0ð Ø#&ð 6ð 6ð 6ð 6ð 6ð 6ð 6˜%Ø�K�K�K�KØ!×.Ò.¨uÑ5Ô5Ð5Ð5ð $' 3õ
 ˜C¥Ñ+Ô+ð 
Ø ð 6ð 6�EØ�K�K�K�KØ!×.Ò.¨uÑ5Ô5Ð5Ð5ð6õ
 1ð,å# C™yœyð,ð ,ð ,ñô ð ùøõ ŒzÔ$Ô-ð 	.ð 	.ð 	.ÝåØ#ØIÀaÐIÐIðñ ô ðõ &Ô+ðñ ô ˆEð ˆKˆKˆKˆKØ×&Ò& uÑ-Ô-Ð-Ð-Ð-Ð-Ð-Ð-øøøøåð 	.ð 	.ð 	.å˜!Õ7Ñ8Ô8ð "Ø˜TÐ!õ åØ#Ý  ™VœVðñ ô ðõ &Ô+ðñ ô ˆEð ˆKˆKˆKˆKØ×&Ò& uÑ-Ô-Ð-Ð-Ð-Ð-Ð-Ð-øøøøåÔ%ð 	.ð 	.ð 	.ÝåØ#ð-ðñ ô ðõ &Ô1ðñ ô ˆEð ˆKˆKˆKˆKØ×&Ò& uÑ-Ô-Ð-Ð-Ð-ð	.øøøð$  ÐÐÐÐÐÐø�-ÐÐÐÐÐøøøs_   ÅB%I8 Ç=HÈA3I8 É6N> É8N4ÊAKËN> ËN4Ë+A*MÍN> ÍAN4Î1N> Î3N4Î4N> Î>Oc              ƒ   óþ   K  — dg|pg z   }t          ¦   «         }| j        D ]\}|j        |vrŒ|                     ¦   «         ƒ d{V —†D ]5}|j        |v r t	          j        d|j        |j        ¦  «         |||j        <   Œ6Œ]|S )a  A unified method to collect all skills from the registered skill
        loaders.

        Args:
            groups (`list[str] | None`, optional):
                A list of group names to filter the skill loaders. The "basic"
                group will always be included regardless of the filter. If not
                provided, only the "basic" group will be included.

        Returns:
            `dict[str, Skill]`:
                A dictionary of skill name and their corresponding Skill
                objects.
        r-   Nz>Duplicate skill name '%s' found in group '%s', overwriting it.)r   r'   r/   Úlist_skillsr    Úwarning)rE   r8   Úgroups_filterÚskillsrF   Úskills         r3   rC   zToolkit._get_available_skills†  s½   è è € ð$ !˜	 V \¨rÑ2ˆå‘”ˆØÔ%ð 	+ð 	+ˆEØŒz Ð.Ð.Øà$×0Ò0Ñ2Ô2Ð2Ð2Ð2Ð2Ð2Ð2ð +ð +�Ø”: Ð'Ð'Ý”Nð*àœ
Øœ
ñ	ô ð ð &+��u”zÑ"Ð"ð+ð ˆr5   rd   c              ƒ   ó$  K  — |€d„ | j         D ¦   «         }|                      |¦  «        ƒ d{V —†}t          |¦  «        dk    rdS t          | j        ¦  «        }|                     |                     ¦   «         | j        j        j	        ¬¦  «        S )aÝ  Get the prompt for all registered agent skills, which can be
        attached to the system prompt for the agent.

        The prompt is consisted of an overall instruction and the detailed
        descriptions of each skill, including its name, description, and
        directory.

        .. note:: If no skill is registered, None will be returned.

        Args:
            activated_groups (`list[str] | None`, optional):
                The currently activated tool groups. If omitted, all groups
                will be included for backwards compatibility.

        Returns:
            `str | None`:
                The combined prompt for registered agent skills, or None
                if no skill is registered.
        Nc                 ó   — g | ]	}|j         ‘Œ
S rV   r.   r0   s     r3   rW   z2Toolkit.get_skill_instructions.<locals>.<listcomp>Ã  s   € ÐAÐAÐA¨1 ¤ÐAÐAÐAr5   r   )r†   Úskill_viewer)
r'   rC   r>   r   r)   ÚrenderrK   rD   r:   r/   )rE   rd   r†   Útemplates       r3   Úget_skill_instructionszToolkit.get_skill_instructions«  s·   è è € ð. Ð#ØAÐA°Ô0@ÐAÑAÔAÐà×1Ò1Øñ
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ˆõ
 ˆv‰;Œ;˜!ÒÐØ�4õ ˜DÔ;Ñ<Ô<ˆà�ŠØ—=’=‘?”?ØÔ2Ô7Ô<ð ñ 
ô 
ð 	
r5   c              ƒ   ó^  K  — i }|                       |¦  «        ƒ d{V —†}t          |¦  «        r| j        || j        j        j        <   t          | j        ¦  «        dk    r| j        d         j        dk    st          | j        ¦  «        dk    r| j        || j        j        j        <   dg|pg z   }| j        D ]ö}|j        |vrŒg }|j        D ]}|                     |¦  «         Œ|j	        D ]u}	 | 
                    |                     ¦   «         ƒ d{V —†¦  «         Œ1# t          $ r8}	t          j        d|j        |j        t          |	¦  «        ¦  «         Y d}	~	Œnd}	~	ww xY w|D ]I}|j        |v r t          j        d|j        |j        ¦  «         t!          ||j        ¬¦  «        ||j        <   ŒJŒ÷|S )a  Return the currently available tools based on the given
        activated tool groups. Tools in the ``"basic"`` group are always
        included. When at least one tool group is registered, the built-in
        meta tool is also included.

        Args:
            groups (`list[str]`):
                The list of currently activated tool group names.

        Returns:
            `dict[str, RegisteredTool]`:
                The dictionary of available tool name and their corresponding
                RegisteredTool objects.
        Nr   r   r-   zASkipping MCP '%s' in group '%s': listing its tools failed with %sú=Duplicate tool name '%s' found in group '%s', overwriting it.)r:   rF   )rC   r>   rD   r:   r/   r'   rB   r$   rL   r&   ÚextendÚ
list_toolsrs   r    r„   r   r   )
rE   r8   ry   r†   r…   rF   Úcache_toolsr:   rG   r€   s
             r3   rJ   zToolkit._get_available_toolsÕ  sN  è è € ð$ ˆð ×1Ò1°&Ñ9Ô9Ð9Ð9Ð9Ð9Ð9Ð9ˆÝˆv‰;Œ;ð 	*ð Ô)ð ØÔ)Ô.Ô3ñõ �Ô Ñ!Ô! QÒ&Ð&ØÔ  Ô#Ô(¨GÒ3Ð3Ý�4Ô#Ñ$Ô$ qÒ(Ð(ð Ô&ð ØÔ&Ô+Ô0ñð
 !˜	 V \¨rÑ2ˆØÔ%ð '	ð '	ˆEØŒz Ð.Ð.ØàˆKàœð )ð )�Ø×"Ò" 4Ñ(Ô(Ð(Ð(ð  œ*ð ð �ðØ×&Ò&¨V×->Ò->Ñ-@Ô-@Ð'@Ð'@Ð'@Ð'@Ð'@Ð'@ÑAÔAÐAÐAøÝ ð ð ð õ
 ”Nð/àœØœ
Ý+¨AÑ.Ô.ñô ð ð ð ð ð ð øøøøðøøøð $ð ð �Ø”9 Ð/Ð/Ý”Nð*àœ	Øœ
ñ	ô ð õ .<ØØœ*ð.ñ .ô .� ¤	Ñ*Ð*ðð Ðs   Ã--DÄ
EÄ%.EÅEÚ	tool_namec           	   ƒ   ó  K  — |                       |¦  «        ƒ d{V —†}||vrt          d|› d�¦  «        ‚||         j        }|dk    r,||vr(t          d|› d|› d| j        j        j        › d�¦  «        ‚||         j        S )	a  Check if the tool is available now. If not, raise the
        agent-oriented exception.

        Args:
            tool_name (`str`):
                The name of the tool to be checked.
            activated_groups (`list[str]`):
                The currently activated tool groups.

        Returns:
            `ToolBase`:
                If the tool is available, return the corresponding ToolBase
                object. Otherwise, raise the agent-oriented exception with the
                error message.
        Nr^   r_   r-   rX   rY   rZ   r[   )rJ   r   rF   r   rB   r:   r/   )rE   r“   rd   r$   r{   s        r3   Úcheck_tool_availablezToolkit.check_tool_available(  sã   è è € ð( ×/Ò/Ð0@ÑAÔAÐAÐAÐAÐAÐAÐAˆØ˜EÐ!Ð!Ý#ð°ið ð ð ñô ð ð
 ˜9Ô%Ô+ˆ
Ø˜Ò Ð  ZÐ7GÐ%GÐ%GÝ(ð>°Yð >ð >Øð>ð >ð Ô*Ô/Ô4ð>ð >ð >ñô ð ð �YÔÔ$Ð$r5   r/   c              ƒ   óœ   K  — |                       d„ | j        D ¦   «         ¦  «        ƒ d{V —†}|                     |d¦  «        }|€dS |j        S )z÷Get tool instance by its name.

        Args:
            name (`str`):
                The name of the tool to be checked.

        Returns:
            `ToolBase | None`:
                The tool instance, or `None` if no tool is found.
        c                 ó   — g | ]	}|j         ‘Œ
S rV   r.   r0   s     r3   rW   z$Toolkit.get_tool.<locals>.<listcomp>Z  s   € Ð.Ð.Ð.˜ˆQŒVÐ.Ð.Ð.r5   N)rJ   r'   Úgetr:   )rE   r/   r$   Úregistered_tools       r3   Úget_toolzToolkit.get_toolN  sx   è è € ð ×/Ò/Ø.Ð.˜TÔ-Ð.Ñ.Ô.ñ
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ˆð  Ÿ)š) D¨$Ñ/Ô/ˆØÐ"Ø�4ØÔ#Ð#r5   c                 ó”   — i }| j         D ]3}|j        dk    rŒt          t          d|j        ¬¦  «        f||j        <   Œ4t          di |¤ŽS )z:Get the meta tool schema based on the current tool groups.r-   F)ÚdefaultÚdescriptionÚ_DynamicModel)rž   )r'   r/   Úboolr
   r�   r   )rE   ÚfieldsrF   s      r3   Ú_get_meta_tool_schemazToolkit._get_meta_tool_schemaa  sn   € àˆØÔ%ð 		ð 		ˆEØŒz˜WÒ$Ð$ØåÝØ!Ø %Ô 1ðñ ô ð"ˆF�5”:ÑÐõ Ð6Ð6¨vÐ6Ð6Ð6r5   c                 ó8   — | j                              ¦   «          dS )z,Clear the registered tools, skills and MCPs.N)r'   Úclear)rE   s    r3   r£   zToolkit.clearp  s   € àÔ×ÒÑ Ô Ð Ð Ð r5   r-   r:   r{   c              ƒ   óÖ  ‡K  — t          |t          ¦  «        r|n|g}| j        D ] }|j        |k    r“d„ |j        D ¦   «         }|D ]|Š‰j        |v r=t          j        d‰j        |j        ¦  «         ˆfd„|j        D ¦   «         ‰gz   |_        ŒH|j                             ‰¦  «         |                     ‰j        ¦  «         Œ} dS Œ¡t          d|› dd„ | j        D ¦   «         › d�¦  «        ‚)	zéAdd tool to the toolkit on-the-fly.

        Args:
            tool (`ToolBase | list[ToolBase]`):
                The tool to be added.
            group_name (`str`):
                The group name of the tool to be added.
        c                 ó   — h | ]	}|j         ’Œ
S rV   r.   r0   s     r3   ú	<setcomp>z#Toolkit.add_tool.<locals>.<setcomp>†  s   € Ð!>Ð!>Ð!>¨Q !¤&Ð!>Ð!>Ð!>r5   r�   c                 ó4   •— g | ]}|j         ‰j         k    ¯|‘ŒS rV   r.   )r1   ÚtÚnew_tools     €r3   rW   z$Toolkit.add_tool.<locals>.<listcomp>�  s.   ø€ ð 'ð 'ð 'Ø"#°a´fÀÄÒ6MÐ6M˜AÐ6MÐ6MÐ6Mr5   NzCannot find group 'z' in toolkit, only c                 ó   — g | ]	}|j         ‘Œ
S rV   r.   r0   s     r3   rW   z$Toolkit.add_tool.<locals>.<listcomp>›  s   € Ð1Ð1Ð1˜1�”Ð1Ð1Ð1r5   z are available.)
rn   Úlistr'   r/   r$   r    r„   rL   Úaddr=   )rE   r:   r{   Ú	new_toolsrF   Úexisting_toolsr©   s         @r3   Úadd_toolzToolkit.add_toolt  sY  øè è € õ ' t­TÑ2Ô2Ð>�D�D¸¸ˆ	àÔ%ð 	ð 	ˆEØŒz˜ZÒ'Ð'Ø!>Ð!>°%´+Ð!>Ñ!>Ô!>�Ø )ð :ð :�HØ”}¨Ð6Ð6Ýœð.à$œMØ!œJñ	ô ð ð'ð 'ð 'ð 'Ø',¤{ð'ñ 'ô 'à%˜Jñ''˜œ˜ð œ×*Ò*¨8Ñ4Ô4Ð4Ø&×*Ò*¨8¬=Ñ9Ô9Ð9Ð9à��ð% (õ( ðC *ð Cð CØ1Ð1 Ô 0Ð1Ñ1Ô1ðCð Cð Cñ
ô 
ð 	
r5   c              ƒ   ó€   ‡K  — t          ‰t          ¦  «        r‰gŠ| j        D ]}ˆfd„|j        D ¦   «         |_        ŒdS )zŸRemove tool from the toolkit on-the-fly.

        Args:
            tool_name (`str | list[str]`):
                The name of the tool to be removed.
        c                 ó&   •— g | ]}|j         ‰v¯|‘ŒS rV   r.   )r1   r:   r“   s     €r3   rW   z'Toolkit.remove_tool.<locals>.<listcomp>©  s,   ø€ ð ð ð Ø°´	ÀÐ0JÐ0J�Ð0JÐ0JÐ0Jr5   N)rn   rt   r'   r$   )rE   r“   rF   s    ` r3   Úremove_toolzToolkit.remove_toolž  sl   øè è € õ �i¥Ñ%Ô%ð 	$Ø"˜ˆIàÔ%ð 	ð 	ˆEðð ð ð Ø!&¤ðñ ô ˆEŒKˆKð	ð 	r5   r7   )r*   N)r-   )#Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú#DEFAULT_META_TOOL_RESPONSE_TEMPLATEÚDEFAULT_SKILL_INSTRUCTIONr«   r   r   rt   r   r   r   r   rH   ÚdictrP   r   r!   r   r   r   r�   rC   r�   r   rJ   r•   rš   r   r	   r¡   r£   r¯   r²   rV   r5   r3   r#   r#   B   s  € € € € € ðð ð. (,àØ'+Ø.2Ø+NØ*CðQ
ð Q
à�HŒ~ Ñ$ðQ
ð $ C¨%¡K°/Ñ$AÔBØ
ñðQ
ð
 �9Œo Ñ$ðQ
ð ˜)”_ tÑ+ðQ
ð &)ðQ
ð %(ðQ
ð 
ðQ
ð Q
ð Q
ð Q
ðj $(ð4 ð 4 à�S”	˜DÑ ð4 ð 
ˆdŒð4 ð 4 ð 4 ð 4 ðlc à ðc ð ðc ð 
˜	 LÑ0°$Ð6Ô	7ð	c ð c ð c ð c ðN $(ð#ð #à�S”	˜DÑ ð#ð 
ˆc�5ˆjÔ	ð#ð #ð #ð #ðN .2ð(
ð (
à˜sœ) dÑ*ð(
ð 
ˆt‰ð(
ð (
ð (
ð (
ðTQà�S”	˜DÑ ðQð 
ˆc�>Ð!Ô	"ðQð Qð Qð Qðf$%àð$%ð ˜sœ)ð$%ð 
ð	$%ð $%ð $%ð $%ðL$ 3ð $¨8°d©?ð $ð $ð $ð $ð&7 t¨I¤ð 7ð 7ð 7ð 7ð!ð !ð !ð !ð "ð(
ð (
à˜˜hœÑ'ð(
ð ð(
ð 
ð	(
ð (
ð (
ð (
ðT¨3°°c´©?ð ¸tð ð ð ð ð ð r5   r#   )3r¶   ru   rk   Úcollectionsr   Útypingr   r   r   r   ro   Újinja2r   Úpydanticr	   r
   r   Ú_builtinr   r   Ú_baser   Ú	_responser   r   r‡   r   r   Ú_typesr   Ú_utils._commonr   r   Ú	exceptionr   r   r   r   Úmessager   r   r   Ú_tool_groupr   Ú_loggingr    rR   r!   r·   r¸   r#   rV   r5   r3   ú<module>rÇ      s<  ðà 5Ð 5Ø €€€Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #ðð ð ð ð ð ð ð ð ð ð ð ð €
€
€
Ø Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð .Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ø Ð Ð Ð Ð Ð Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ø "Ð "Ð "Ð "Ð "Ð "Ø IÐ IÐ IÐ IÐ IÐ IÐ IÐ Iðð ð ð ð ð ð ð ð ð ð
 Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð
 #Ð "Ð "Ð "Ð "Ð "Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ð'.Ð #ðÐ ði	ð i	ð i	ð i	ð i	ñ i	ô i	ð i	ð i	ð i	r5   