# Mac exercise for mission 12.1: Tool use round by round

Part of the course “AI from Zero to Autonomous Agents” (https://llm.yoga/en). Page for humans: https://llm.yoga/en/mac-12-1

About 20 minutes at your computer · Type this address: **llm.yoga/en/mac-12-1**

In the mission, you played Laura’s app. Here you do it for real: a local model gets the weather question and a tool, responds with a call, and you deliver the result back by hand. For this, Ollama uses OpenAI’s format, that is, `function` and `parameters` instead of `input_schema`; the flow is the same as with Claude. The question and the tool are in German, as in the measurement: „Wie ist das Wetter gerade in Hamburg?“ means “What’s the weather like in Hamburg right now?”, the tool wetter_abfragen means “query weather”, and its field stadt means “city”.

**Before you start**

You need **Ollama** and Python 3 in the terminal. Ollama comes as an app: download it from ollama.com/download and drag it into your Applications folder. On first launch, the app asks permission, if needed, to set up the `ollama` terminal command. It requires macOS 14 or newer. More on this in [chapter 10](https://llm.yoga/en/10-lokale-modelle-4.md). Check:

```
ollama --version
```

Python 3 may need to be installed. On the first `python3` call, macOS may offer to install developer tools; alternatively, Python is available from python.org.

### 1. Download the model and check whether it can use tools

qwen3:1.7b is 1.4 GB and also runs with 8 GB. Only models with the entry `tools` can call tools.

```
ollama pull qwen3:1.7b
```

```
ollama show qwen3:1.7b
```

**Excerpt of the output (Measured on an M4 Mac (24 GB) on November 25, 2026)**

```
  Capabilities
    completion
    tools
    thinking
```

### 2. Round 1: question and tool

Save these lines as `runde1.json`. `"think": false` turns off Qwen3’s thinking so the answer stays short.

```
{"model": "qwen3:1.7b", "stream": false, "think": false,
 "messages": [{"role": "user", "content": "Wie ist das Wetter gerade in Hamburg?"}],
 "tools": [{"type": "function", "function": {
   "name": "wetter_abfragen",
   "description": "Liefert das aktuelle Wetter für eine Stadt.",
   "parameters": {"type": "object", "required": ["stadt"],
     "properties": {"stadt": {"type": "string", "description": "Name der Stadt, z. B. Berlin"}}}}}]}
```

```
curl -s http://localhost:11434/api/chat -d @runde1.json
```

**Excerpt of the output, wrapped (Measured on an M4 Mac (24 GB) on November 25, 2026, under load)**

```
"message":{"role":"assistant","content":"",
 "tool_calls":[{"id":"call_v0jbl1mk","function":{"index":0,
  "name":"wetter_abfragen","arguments":{"stadt":"Hamburg"}}}]},
"done_reason":"stop", … "prompt_eval_count":166, … "eval_count":24
```

No text, only the call. The model didn’t look anything up; it wrote down what it needs.

### 3. For comparison: without the tool

Save the same question without `tools` as `ohne.json` (German for “without”):

```
{"model": "qwen3:1.7b", "stream": false, "think": false, "messages": [{"role": "user", "content": "Wie ist das Wetter gerade in Hamburg?"}]}
```

```
curl -s http://localhost:11434/api/chat -d @ohne.json
```

**Excerpt of the output (Measured on an M4 Mac (24 GB) on November 25, 2026, under load)**

```
"content":"Derzeit in Hamburg ist das Wetter mild und bequem. …
 Die Temperaturen liegen im Bereich von 12 bis 18 Grad Celsius. …"
… "prompt_eval_count":25 …
```

Without the tool, the model guesses: the weather is mild, 12 to 18 degrees Celsius. In an earlier run the same morning, it was 5 to 10 degrees. And it read only 25 tokens instead of 166: the difference is the tool description, which Ollama puts into the prompt as text.

### 4. Round 2: you are the tool

Make up a result and send it back, together with the question and the whole response from round 1. Save it as `runde2.json`; the `id` can differ from yours.

```
{"model": "qwen3:1.7b", "stream": false, "think": false,
 "messages": [
  {"role": "user", "content": "Wie ist das Wetter gerade in Hamburg?"},
  {"role": "assistant", "content": "", "tool_calls": [{"id": "call_0g8ebaa3", "function": {"index": 0, "name": "wetter_abfragen", "arguments": {"stadt": "Hamburg"}}}]},
  {"role": "tool", "tool_name": "wetter_abfragen", "content": "{\"temperatur_c\": 7, \"lage\": \"Nieselregen\", \"wind_kmh\": 25}"}],
 "tools": [{"type": "function", "function": {
   "name": "wetter_abfragen",
   "description": "Liefert das aktuelle Wetter für eine Stadt.",
   "parameters": {"type": "object", "required": ["stadt"],
     "properties": {"stadt": {"type": "string", "description": "Name der Stadt, z. B. Berlin"}}}}}]}
```

```
curl -s http://localhost:11434/api/chat -d @runde2.json
```

**Excerpt of the output (Measured on an M4 Mac (24 GB) on November 25, 2026, under load)**

```
"content":"Das Wetter in Hamburg ist derzeit mit einer Temperatur
 von 7°C und einem Nieselregen. Der Wind betragen 25 km/h."
… "prompt_eval_count":228,"prompt_eval_cached_count":162 …
```

The facts are right (7 °C, drizzle, wind at 25 km/h), but the German stumbles: a model with 2 billion parameters calls tools reliably but doesn’t phrase things like Claude. 162 of the 228 tokens came from the cache, because round 2 starts exactly like round 1.

### 5. Cross-check: a question that needs no tool

In `runde1.json`, replace the question with „Wie viele Tage hat eine Woche?“ (German for “How many days does a week have?”) and send it.

**Excerpt of the output (Measured on an M4 Mac (24 GB) on November 25, 2026)**

```
"content":"Eine Woche hat 7 Tage." … "prompt_eval_count":164
```

The answer means “A week has 7 days.” The tool was on offer but not needed. The model decides on its own, as with `tool_choice: auto` in the Claude API.

### 6. How much of it is the question?

Count the question alone, without the chat template and without the tool. Type it into the field below, and it already appears here in the command.

```
curl -s http://localhost:11434/api/generate -d '{"model": "qwen3:1.7b", "prompt": "Wie ist das Wetter gerade in Hamburg?", "raw": true, "stream": false, "options": {"num_predict": 1}}' | python3 -c 'import json, sys; print(json.load(sys.stdin)["prompt_eval_count"], "Tokens")'
```

**Output (Measured on an M4 Mac (24 GB) on November 25, 2026)**

```
9 Tokens
```

9 tokens for the question, 25 with the chat template, 166 with the tool. So just over 140 tokens are the form that the model reads with every request, even when it doesn’t need the tool at all.

### 7. Let the page check the output

The check needs JavaScript. Without it: the question has 9 tokens, the request with the tool 166.

The page counts the question with the same Qwen3 tokenizer in the browser and compares it with Ollama.

### 8. Clean up

Unload the model from memory:

```
ollama stop qwen3:1.7b
```

If you’re about to do the exercise for 12.2, leave it on the disk. Otherwise:

```
ollama rm qwen3:1.7b
```

#### On the DGX Spark

The JSON files work the same way on the Spark, as long as Ollama runs at `localhost:11434`. The next step is more worthwhile there, an agent that uses tools in a loop: the playbook “Set Up CLI Coding Agents with Local Inference” connects Claude Code, OpenCode or Codex CLI to a local model with `ollama launch`, in the playbook `qwen3.6:35b-a3b-mtp-q4_K_M` at about 23 GB. Have the agent solve a small programming task and count how many tool rounds it needs. (Checked against the documentation, not run here)
