agent.process().
The Think-Act Loop
Agents follow a loop pattern:- Think: LLM analyzes the goal and decides what to do
- Act: Execute selected tools
- Observe: Process tool results
- Decide: Continue looping or return result

Execution Phases
1. Think Phase
The LLM receives a structured prompt containing:- The user’s goal/input
- Descriptions of all available tools
- History of previous iterations (if any)
- Memory contents (if memory is enabled)
- Reasoning about what to do next
- Which tools to call (with arguments)
- A final answer (if ready to complete)
2. Act Phase
When tools are selected, the agent:- Validates tool arguments against schemas
- Executes each tool (in parallel when possible)
- Captures results or errors
- Records execution time
3. Observe Phase
After tools execute:- Results are added to the execution history
- The iteration counter increments
- The loop continues back to Think
4. Output Phase
When the LLM decides it’s done (no more tools to call):- The final response is extracted
- Output is validated against the output schema (if defined)
- Result is returned to the caller
Execution History
Each iteration adds a cycle to the history:Iteration Limits
Themax_iterations parameter prevents infinite loops:
- The agent stops iterating
- It returns the best result it has
- A warning may be logged
Token Usage
Each iteration consumes tokens:Tracing with Spans
Each agent execution creates a trace with spans:Error Handling
Tool Errors
When a tool throws an error:- The error is caught and recorded
- The error message is sent to the LLM
- The LLM can decide to retry or try a different approach
Agent Errors
Fatal errors (like LLM failures) propagate up:Debugging Tips
- Enable verbose mode: See what the agent is thinking
- Use hooks: Log specific events
- Check the dashboard: View full traces with timing
- Reduce max_iterations: Faster debugging cycles