7. Skills AI
A skill is a reusable, named tool definition. Building a skill library
means you write a tool once and use it across many agents and sessions.
This chapter covers the anatomy of a skill, a code_metrics example,
and composing multiple skills in a single agent call.
Why build a skill library?
- Copy-pasting tool definitions into every script creates maintenance debt.
A shared library means a fix reaches every agent at once.
- Named, well-described skills are self-documenting — the model reads
the description and knows what the tool does without explanation in the prompt.
- A library of composable skills lets you assemble new agents quickly from
existing parts.
7.1 Anatomy of a Skill
def skill_code_metrics(path: str) -> dict:
"""Count lines, functions, and blank lines in a Python source file.
Returns {"lines": int, "functions": int, "blanks": int}.
"""
import ast, pathlib
src = pathlib.Path(path).read_text()
tree = ast.parse(src)
functions = sum(1 for n in ast.walk(tree) if isinstance(n, ast.FunctionDef))
lines = src.count("\n")
blanks = sum(1 for ln in src.splitlines() if not ln.strip())
return {"lines": lines, "functions": functions, "blanks": blanks}
SKILL_CODE_METRICS = {
"name": "code_metrics",
"description": skill_code_metrics.__doc__,
"input_schema": {
"type": "object",
"properties": {"path": {"type": "string"}},
"required": ["path"]
}
}
7.2 Composing Skills
Pass a list of skill definitions to a single agent call. The model chooses which
tools to invoke and in what order. Keep each skill focused on one action —
composition happens at the agent level, not inside a skill.
all_skills = [SKILL_READ_FILE, SKILL_CODE_METRICS, SKILL_LIST_DIR]
resp = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=2048,
tools=all_skills,
messages=[{
"role": "user",
"content": "Report metrics for every .py file in src/."
}]
)
7.3 References