Chapter 6 — Agent Skills¶
Setup Instructions¶
To ensure you have the required dependencies to run this notebook, you'll need to have our llm-agents-from-scratch framework installed on the running Jupyter kernel. To do this, you can launch this notebook with the following command while within the project's root directory:
uv run --with jupyter jupyter lab
Alternatively, if you just want to use the published version of llm-agents-from-scratch without local development, you can install it from PyPi by uncommenting the cell below.
Setting up the LLM¶
I recommend running these notebooks on Ollama Cloud. It serves much larger models than most laptops can run. The default cloud model is picked by benchmarking candidates on these notebooks, and an automated run checks every notebook against it each week. The notebook status page shows the current model and results.
- Create an API key at https://ollama.com/settings/keys.
- Export it before launching Jupyter:
export OLLAMA_API_KEY=<your key>. - That's all. When a notebook builds its LLM, it detects the key and uses Ollama Cloud.
Prefer to run locally? Install Ollama from https://ollama.com/download
and pull the model with ollama pull qwen3:14b. If no key is set, the
notebook starts the Ollama service for you, so there is no need to run
ollama serve. Local models are smaller, so your outputs will differ from
the recorded ones.
Prefer OpenAI or Anthropic?
- Install the extra:
uv sync --extra openaioruv sync --extra anthropic. - Export
OPENAI_API_KEYorANTHROPIC_API_KEYbefore launching Jupyter. If you forget, you will be prompted for it, which keeps the key out of the saved notebook. - Set
LLM_PROVIDER=openai(oranthropic), or passprovider="openai"tomake_llm(). A key on its own never switches providers, so one exported for unrelated work cannot reroute you.
The switch applies wherever a notebook builds its LLM with make_llm().
A notebook that constructs OllamaLLM directly stays on Ollama. Output on
gpt-5 or Claude will differ from the recorded outputs, and prompt-sensitive
examples (the ch09 evaluator pattern, ch08 supervised trajectories) may
behave noticeably differently.
# Uncomment the line below to install `llm-agents-from-scratch` from PyPi
# !pip install llm-agents-from-scratch
from llm_agents_from_scratch.notebook_utils import make_llm
The Hailstone Skill¶
The examples in this notebook use a hailstone-sequence skill that instructs the agent to compute a full Hailstone (Collatz) sequence using a next_number tool.
Important: Run this notebook from within the chapter-notebooks/ch06/ directory so the skill is discovered as a project-scoped skill.
The skill is located at: chapter-notebooks/shared/.agents/skills/stop-at-one/SKILL.md, linked into this chapter's folder as .agents
Tip: If you're running the notebook on a Windows machine, Git only checks out symlinks as real links when symlink support is turned on in Git (the installer's "Enable symbolic links" option, or cloning with
git clone -c core.symlinks=true) and Windows allows creating them (Developer Mode, or an administrator shell). Otherwise, the.agentsfolder contained in this chapter's notebook directory ends up as a plain text file. In that case, delete it and copychapter-notebooks/shared/.agentsinto this folder.
Tip: If you're running the notebook on Google Colab, uploading the notebook on its own leaves out the files it reads from this chapter's folder, such as the
.agentsfolder that holds its skills. Instead, clone the repository and switch into this chapter's folder by running the following in a new first cell, then uncomment the PyPI install cell below:!git clone https://github.com/nerdai/llm-agents-from-scratch %cd llm-agents-from-scratch/chapter-notebooks/ch06Colab doesn't come with a local Ollama server, so set your Ollama Cloud key in the notebook with
os.environ["OLLAMA_API_KEY"] = "<your key>"before building the LLM.
Note on obfuscation: The skill is intentionally named
stop-at-oneand contains no mention of "Hailstone" or "Collatz". This prevents the LLM from relying on its parametric knowledge of the Collatz conjecture to simulate the sequence internally — forcing it to actually call thenext_numbertool at each step as the skill instructs.
Examples¶
Example 1: Skill Discovery¶
from llm_agents_from_scratch import LLMAgent
from llm_agents_from_scratch.data_structures import Task
llm = make_llm()
agent = LLMAgent(llm=llm)
task = Task(instruction="Compute the stop-at-one sequence for 8.")
handler = LLMAgent.TaskHandler(llm_agent=agent, task=task)
print(handler.skills_registry)
print(handler.skills_registry["stop-at-one"].frontmatter)
print(handler.skills_registry["stop-at-one"].scope)
✓ Using Ollama Cloud (deepseek-v4.1-flash)
{'stop-at-one': <llm_agents_from_scratch.skills.skill.Skill object at 0x7e9e4d6216a0>}
name='stop-at-one' description='Compute a sequence for a given starting number by repeatedly calling the next_number tool until the value 1 is reached.' license=None compatibility=None metadata=None allowed_tools=None
SkillScope.PROJECT
Example 2: UseSkillTool Activation Result¶
from llm_agents_from_scratch.data_structures import ToolCall
from llm_agents_from_scratch.skills.tools import UseSkillTool
tool = UseSkillTool(skills_registry=handler.skills_registry)
tool_call = ToolCall(
tool_name="from_scratch__use_skill",
arguments={"name": "stop-at-one"},
)
result = tool(tool_call=tool_call)
print(result.content)
<skill_content name="stop-at-one"> # Stop At One Compute a full sequence from a starting number down to 1 using the `next_number` tool. ## Arguments The user must provide a **starting number** (a positive integer greater than 1). If no starting number is given, ask the user before proceeding. ## Steps ### 1. Initialize Set the current number `x` to the starting number provided by the user. Begin tracking the sequence as a list: `[x]`. ### 2. Call the tool Call `next_number` with the current value of `x`. ``` next_number(x=<current_number>) ``` **STOP and WAIT** for the tool result before continuing. ### 3. Record the result Append the returned value to the sequence list. Set `x` to the returned value. ### 4. Check termination - If `x == 1`, proceed to Step 5. - Otherwise, go back to Step 2. **Important rules:** - NEVER fabricate or simulate tool call results. - NEVER make multiple tool calls in a single response. - ALWAYS wait for the actual tool response before deciding next steps. ### 5. Report the result Print the complete sequence from start to finish, for example: ``` 6 → 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1 ``` Also report: - **Starting number** - **Total steps taken** (number of tool calls made) - **Maximum value reached** in the sequence Skill directory: /home/nerdai/Projects/llm-agents-from-scratch/chapter-notebooks/shared/.agents/skills/stop-at-one </skill_content>
Example 3: Model-driven Skill Activation¶
import logging
from llm_agents_from_scratch.logger import enable_console_logging
enable_console_logging(logging.INFO)
from llm_agents_from_scratch import LLMAgent
from llm_agents_from_scratch.data_structures import Task
from llm_agents_from_scratch.tools.simple_function import SimpleFunctionTool
def next_number(x: int) -> int:
if x % 2 == 0:
return x // 2
return 3 * x + 1
next_number_tool = SimpleFunctionTool(func=next_number)
llm = make_llm()
agent = LLMAgent(llm=llm, tools=[next_number_tool])
task = Task(instruction="Compute the stop-at-one sequence for 8.")
result = await agent.run(task)
✓ Using Ollama Cloud (deepseek-v4.1-flash)
INFO (llm_agents_fs.LLMAgent) : 🚀 Starting task: Compute the stop-at-one sequence for 8.
INFO (llm_agents_fs.TaskHandler) : ⚙️ Processing Step: Compute the stop-at-one sequence for 8.
INFO (llm_agents_fs.TaskHandler) : 🛠️ Executing Tool Call: from_scratch__use_skill
INFO (llm_agents_fs.TaskHandler) : ✅ Successful Tool Call: <skill_content name="stop-at-one">
# Stop At One
Compute a full sequence from a starting number down to 1
using the `next_num...[TRUNCATED]
INFO (llm_agents_fs.TaskHandler) : ✅ Step Result: I need to make the following tool-calls:
{
"id_": "a245e16a-5f2f-4f66-8496-d0296b5e7dc1",
"tool_name": "next_number",
"argu...[TRUNCATED]
INFO (llm_agents_fs.TaskHandler) : 🧠 New Step: Execute the pending tool call: next_number with x=8, then wait for the result before continuing the stop-at-one sequence.
INFO (llm_agents_fs.TaskHandler) : ⚙️ Processing Step: Execute the pending tool call: next_number with x=8, then wait for the result before continuing the stop-at-one sequence.
INFO (llm_agents_fs.TaskHandler) : 🛠️ Executing Tool Call: next_number
INFO (llm_agents_fs.TaskHandler) : ✅ Successful Tool Call: 4
INFO (llm_agents_fs.TaskHandler) : ✅ Step Result: I need to make the following tool-calls:
{
"id_": "b10f8208-d8ff-466b-92e9-6e1f5897bf11",
"tool_name": "next_number",
"argu...[TRUNCATED]
INFO (llm_agents_fs.TaskHandler) : 🧠 New Step: Execute the pending tool call: next_number with x=4, then wait for the result before continuing the stop-at-one sequence for 8.
INFO (llm_agents_fs.TaskHandler) : ⚙️ Processing Step: Execute the pending tool call: next_number with x=4, then wait for the result before continuing the stop-at-one sequence for 8.
INFO (llm_agents_fs.TaskHandler) : 🛠️ Executing Tool Call: next_number
INFO (llm_agents_fs.TaskHandler) : ✅ Successful Tool Call: 2
INFO (llm_agents_fs.TaskHandler) : ✅ Step Result: I need to make the following tool-calls:
{
"id_": "05de6c52-c39c-4170-9053-9ac360ec9d90",
"tool_name": "next_number",
"argu...[TRUNCATED]
INFO (llm_agents_fs.TaskHandler) : 🧠 New Step: Execute the pending tool call: next_number with x=2, then wait for the result before continuing the stop-at-one sequence for 8.
INFO (llm_agents_fs.TaskHandler) : ⚙️ Processing Step: Execute the pending tool call: next_number with x=2, then wait for the result before continuing the stop-at-one sequence for 8.
INFO (llm_agents_fs.TaskHandler) : 🛠️ Executing Tool Call: next_number
INFO (llm_agents_fs.TaskHandler) : ✅ Successful Tool Call: 1
INFO (llm_agents_fs.TaskHandler) : ✅ Step Result: The sequence has reached 1, so it's complete. Let me report the full result.
**Stop-at-one sequence for 8:**
```
8 → 4 → 2 → 1
```
-...[TRUNCATED]
INFO (llm_agents_fs.TaskHandler) : No new step required.
INFO (llm_agents_fs.LLMAgent) : 🏁 Task completed: The sequence has reached 1, so it's complete. Let me report the full result.
**Stop-at-one sequence for 8:**
```
8 → 4 → 2 → 1
```...[TRUNCATED]
print(result)
The sequence has reached 1, so it's complete. Let me report the full result. **Stop-at-one sequence for 8:** ``` 8 → 4 → 2 → 1 ``` - **Starting number:** 8 - **Total steps taken:** 3 tool calls (8→4, 4→2, 2→1) - **Maximum value reached:** 8