AI Agents by HandAll problemsAbout

All problems

Short, timed exercises for learning how LLM agents work by building their parts yourself: the tool-use loop, tool schemas, retries, approval gates, context compaction, evals and more. Each problem gives you starter code, a task and hidden tests. Everything runs in your browser (Python via Pyodide), the tests use a fake model client, so no install, no account and no API key are needed.

Build the agent

Get a tool result back to the model, decide what's allowed to run, and keep a conversation intact when something fails.

  • Write the tool-use loop Agent problem · easy · ~15 min
    Implement run_agent: call the model, run every tool_use block, send results back, stop on end_turn or max_turns.
  • Tool schemas and input validation Agent problem · easy · ~15 min
    Write tool schemas from a contract table and validate inputs (required, unknown, type, enum) before execution.
  • Build a stateful chat agent Agent problem · medium · ~15 min
    History across calls, hooks, and no corrupted state after a failure.

Evaluate and control it

Tell a plausible answer from correct behaviour: did the lookup succeed, was the refund issued once, did the approver see what actually ran?

  • Write an eval harness Agent problem · medium · ~15 min
    Grade runs on must-call, must-not-call, answer content and tool-call limits, and survive crashing cases.
  • Debug a support agent Agent problem · medium · ~15 min
    Three prompts fail: a status lookup that errors, a refund that goes wrong, and a two-order comparison that crashes.
  • Approval gate and injected instructions Agent problem · medium · ~20 min
    An approval callback for a destructive tool, instructions injected through logs, and inputs that need normalizing.

Improve and integrate it

Cut model calls and input tokens (two different costs), then put retrieval, evidence, abstention and untrusted content together.

  • Answer in fewer model calls Agent problem · medium · ~20 min
    A working agent takes too many round trips for a two-lookup question. Get it down to two model calls.
  • Halve the input-token cost Agent problem · medium · ~20 min
    A knowledge-base agent answers correctly but expensively. Halve its input tokens without losing the answer.
  • Document answerer with citations (multi-part) Agent problem · hard · ~55 min
    Retrieval with per-run citation evidence, strict structured output, and untrusted document content.

Advanced

Concurrency under a deadline, retrying only what's safe to retry, and surviving a crash without repeating a write.

  • Run tool calls in parallel Agent problem · hard · ~20 min
    Run all tool_use blocks of a turn concurrently with asyncio, keep result order and ids, cancel a hung tool.
  • Retry and backoff on API errors Agent problem · medium · ~15 min
    Write the tool loop with retry/backoff on rate limits, overloads and connection errors, but never on a 400.
  • Resumable run with idempotent writes Agent problem · hard · ~20 min
    Save the run to disk, resume from it, and never repeat a write call that already happened.

Debugging practice

Agents that look fine and fail. Read the trace, find the root cause, fix it where it belongs.

  • Debug a weather agent Agent problem · easy · ~15 min
    Make three failing prompts pass in an agent with a working-looking loop.
  • Debug a travel planner Agent problem · medium · ~15 min
    Three prompts fail: one crashes, one gets the budget badly wrong, and one is rejected by the API.
  • Debug an inventory agent Agent problem · medium · ~15 min
    Three prompts fail: a two-SKU comparison crashes, a low-stock report misses items, and a refused transfer still changes state.

More agent problems

  • Structured report via a terminal tool Agent problem · hard · ~20 min
    Return a validated report through a submit tool: reject evidence the model never fetched, recover from max_tokens.
  • Delegate to a sub-agent Agent problem · medium · ~20 min
    Add a tool that runs a separate researcher agent with its own tools, history and budget, and returns only its answer.
  • Stream a chat agent Agent problem · medium · ~15 min
    Switch a chat agent to messages.stream: text to on_text as it arrives, tools from the final message.
  • Compact long history Agent problem · hard · ~20 min
    When a request goes over the token budget, summarize the history with one tool-less call and carry the summary forward.

Python drills: Mutation and references

  • d01 · Roll back history Python drill · medium · ~5 min
    Run a step that edits the conversation; if it raises, restore the history exactly as it was.
  • d02 · Add a cache breakpoint Python drill · easy · ~5 min
    Mark the last content block for prompt caching without touching the caller's messages.
  • d03 · Build handlers from a table Python drill · easy · ~4 min
    Turn a name→factor table into tool handlers that each keep their own factor.
  • d04 · Log tool calls Python drill · easy · ~4 min
    Append each tool call to a log that later edits by the caller can't change.

Python drills: Serialization

Python drills: Parsing strings

Python drills: Numbers, missing values, time

Python drills: Chunking text