Lesson 2.3

Multi-step agent loops

An agent is a loop: send the conversation, get either a final answer or a tool request, execute, append the result, repeat.

4mIntermediate12.2k students

Overview

A loop with a budget

An agent is a loop: send the conversation, get either a final answer or a tool request, execute, append the result, repeat. The pattern is simple; the discipline is in the limits.

Always bound the step count and the total token spend. A model that keeps trying a failing tool will loop until something stops it, and without a cap that something is your bill.

Log every step — the request, the arguments, the result. When an agent produces a strange answer, the trace is the only way to find out which step went wrong.

In this lesson you will:

  • Run a call-execute-continue loop
  • Bound the number of steps
  • Log each step for debugging

Resources

Previous Lesson
Next Lesson
Multi-step agent loops — Building LLM Applications — Vertex