Build garageTry it → read → next · ~11 min

Tutorials · Chapter D (4/4) · ~11 min

Agents in code

Try it → see it → read → next

Wire a **Think → Act → Observe** loop — model picks tools, your code runs them, results feed back until done or max steps.

On paths: Builder · Student

Optional on: Professional

Try tools: Agents & automation

Try yourself

Playground

Agent loop in code

Think → act → observe — cap steps and gate dangerous tools.

  1. Model plans next action
  2. Tool call returned — validate args
  3. Append tool result to messages
  4. Stop at max steps or final answer

Recap

What you just did

You stepped through the minimal loop: plan → validate tool call → append observation → stop at a cap.

Read

Starter pattern

  1. Define 1–2 safe tools with JSON schemas
  2. Send goal + tool list to the model
  3. On tool call → validate args → run function
  4. Append tool message → ask model again
  5. Max 5 steps — no infinite loops

Read

Safety gates

  • No shell/exec without human approval
  • Log every step (see tracing lab)
  • Eval golden tasks before shipping