liveBook · Manning

Useskilltool

As explained in Build a Multi-Agent System (from Scratch)

UseSkillTool is the example framework's tool class for activating a skill and returning its formatted content.

When an agent needs a skill, UseSkillTool turns activation into an explicit tool call: it accepts a skill name and returns formatted content containing the skill’s instructions and available resources. section 6.4.1

Its execution flow:

  • Expose visible skill names in the tool description and the name parameter’s JSON schema. section 6.4.2
  • Check that the supplied name is a string and exists in the skills registry. section 6.4.2
  • Build the skill content and return it in a ToolCallResult. section 6.4.2
  • Add the tool to TaskHandler’s available tools so the agent can request activation during a task. section 6.4.3
Listing 6.14 Implementing UseSkillTool: __call__()
# llm_agents_from_scratch/skills/tools.py
… #A
import json
from typing import Any
from ..data_structures import ToolCall, ToolCallResult
 
class UseSkillTool(BaseTool):
    … #B
 
    def __call__(
        self,
        tool_call: ToolCall,
        *args: Any,
        **kwargs: Any,
    ) -> ToolCallResult:
        """Execute the skill activation tool."""
        skill_name = tool_call.arguments.get("name")
        if not isinstance(skill_name, str): #C
            return ToolCallResult(
                tool_call_id=tool_call.id_,
                content=json.dumps(
                    {
                        "error_type": "ValueError",
                        "message": "'name' argument must be a string.",
                    },
                ),
                error=True,
            )
        if skill_name not in self._skills_registry: #D
            return ToolCallResult(
                tool_call_id=tool_call.id_,
                content=json.dumps(
                    {
                        "error_type": "ValueError",
                        "message": f"Skill '{skill_name}' not found.",
                    },
                ),
                error=True,
            )
        content = self._build_skill_content(skill_name) #E
 
        return ToolCallResult( #F
            tool_call_id=tool_call.id_,
            content=content,
            error=False,
        )

Inspect the callable implementation, including its input checks and error results. section 6.4.2

How Build a Multi-Agent System (from Scratch) covers it

How deep it goes
Defines the tool interface, schema, validation, and result; omits a walkthrough of the content-formatting helper.
Examples
Demonstrates activating a stop-at-one skill and an agent using it to compute the sequence from 8.
What it assumes
Requires a skills registry and a BaseTool-based tool implementation.
What you can do after
Apply the tool interface to activate a registered skill and return its formatted content to an agent.
How it connects
Connects BaseTool, skill catalogs, and TaskHandler tool disclosure to skill activation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Multi-Agent System (from Scratch). The section links point to the parts of the book it draws on.