Reference · How-to · ~10 min

How to build a minimal agent loop

Last updated

Think → tool → observe in code — starter pattern in ~10 minutes.

Think → tool → observe in code — starter pattern in ~10 minutes.

Steps

1. Define 1–2 safe tools with JSON schemas

2. Send user goal + tool list to the model

3. If model returns tool call → validate args → run your function

4. Append tool result as a message → ask model again

5. Stop after N steps or final natural-language answer

Safety

  • Max 5 steps
  • No shell/exec tools without human gate
  • Log inputs and outputs
  • **Try the lesson:** `what-are-agents` in Lane C · cheatsheet `agent-loop`