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
