Module 5 – Tool Calling and the Responses/Agent Loop

Learning outcomes

Build an agent loop that calls typed tools, validates arguments, handles failures, and stops predictably.

Agent loop

  1. Send instructions, user input, and available tool schemas.
  2. The model returns text, structured output, or tool calls.
  3. The application validates the tool name and arguments.
  4. Authorization and approval checks run before side effects.
  5. The application executes the tool and returns a bounded result.
  6. The loop continues until a final answer, limit, error, or approval pause.

Production controls

  • Strict JSON schemas and server-side validation
  • Idempotency keys for retryable writes
  • Timeouts, concurrency limits, and maximum agent turns
  • Allowlisted tools and least-privilege credentials
  • Human approval for destructive, financial, publishing, or permission-changing actions

Lab 5

Create three tools: search documentation, read an issue, and draft a change plan. Keep all tools read-only. Add schema validation, timeouts, and a maximum of six agent turns.