Skip to main content

Overview

AgentLoop::iterate() yields the agent state after each step, giving you fine-grained control over the execution. This is useful for streaming progress, implementing custom stop logic, or inspecting intermediate states between LLM calls. You can combine iterate() with AgentEventConsoleObserver to get detailed event output (tool calls, inference, continuation decisions) alongside your own step-by-step logic. The logger hooks into the event system and prints as events fire during iteration. Key concepts:
  • iterate(): Returns an iterable that yields AgentState after each step
  • AgentEventConsoleObserver: Attach via wiretap() for detailed execution logging
  • Step-by-step inspection of tool calls, token usage, and agent decisions
  • Early termination by breaking out of the loop

Example