Example
Anthropic Claude — a tool-using agent turn

A real, runnable mini-project. Download it and run with Docker.

June 28, 2026

Anthropic Claude — a tool-using agent turn

A tiny agent loop built on the official Anthropic SDK: Claude is given one tool (get_weather), decides to call it, and the script feeds the result back as a tool_result — looping until Claude writes a final answer. That loop is the core agentic pattern.

Configure

cd samples/anthropic-claude_1
cp .env.sample .env
# edit .env: set ANTHROPIC_API_KEY (and optionally MODEL)

Get a key at console.anthropic.com. MODEL defaults to claude-opus-4-8; see the model list.

.env is gitignored — only .env.sample is committed.

Run with Docker

cd samples/anthropic-claude_1
docker build -t aas-anthropic-claude .
docker run --rm --env-file .env aas-anthropic-claude "What should I wear in Seoul today?"

Run with Docker (in a devcontainer with DooD)

In a dev container that talks to the host Docker daemon (Docker-outside-of-Docker), the foreground docker run above often prints nothing and exits 0 — but the run itself succeeds. The script runs to completion and Docker captures all of its output; only the live attached stream drops it over the VM boundary. You can confirm this: docker logs on the same container shows the full output, the container exits 0, and it is not an OOM. Run detached and follow the logs instead:

cd samples/anthropic-claude_1
docker build -t aas-anthropic-claude .
docker logs -f "$(docker run -d --env-file .env aas-anthropic-claude \
  "What should I wear in Seoul today?")"

Run locally

cd samples/anthropic-claude_1
pip install -r requirements.txt
python app.py "What should I wear in Seoul today?"

python-dotenv loads .env automatically.


Example run

Output varies by model and run — LLMs are non-deterministic, so the exact wording (and an agent's steps) differ each time. Below is one run with claude-opus-4-8.

I'll check the current weather in Seoul to help you decide what to wear.
[tool call] get_weather({'city': 'Seoul'})
It's a beautiful day in Seoul today—**22°C and sunny**! Here's what I'd recommend:

- A light long-sleeve shirt or a t-shirt
- Comfortable pants, jeans, or a skirt/dress
- A light jacket or cardigan if you tend to get chilly, especially in the evening
- Sunglasses, maybe a hat, and a bit of sunscreen since it's sunny
...
22°C is mild and pleasant—no need for heavy layers. Enjoy your day!

Files

.env.sample
# Copy this file to `.env` and add your Anthropic API key.
#   cp .env.sample .env
#
# Get a key at https://console.anthropic.com/
ANTHROPIC_API_KEY=

# Model id — see https://docs.anthropic.com/en/docs/about-claude/models
#   claude-opus-4-8              most capable
#   claude-sonnet-4-6            balanced cost/latency
#   claude-haiku-4-5-20251001    fastest/cheapest
MODEL=claude-opus-4-8