What is AgentLoop?
AgentLoop is a ready-to-use agent that packages everything you need to run an autonomous coding task: tools, system prompt, turn limits, cost limits, session memory, and observability. Under the hood it delegates to Spring AI’s ChatClient + AgentLoopAdvisor for the actual tool-calling loop.
Think of it as “batteries included” — one class, one builder call, working agent:
Built-in Tools
AgentLoop ships with a full set of SWE tools:| Tool | Source | Description |
|---|---|---|
Bash | workflow-tools | Shell commands (git, mvn, docker) |
Read / Write / Edit / LS | spring-ai-agent-utils | File operations |
Glob | spring-ai-agent-utils | Find files by pattern |
Grep | spring-ai-agent-utils | Search file contents |
TodoWrite | spring-ai-agent-utils | Task planning and tracking |
Task | spring-ai-agent-utils | Delegate to sub-agents |
Submit | AgentLoop (internal) | Submit final answer, terminates the loop |
Configuration
AgentLoop.Config is a Java record with a builder:
| Parameter | Default | Description |
|---|---|---|
maxTurns | 20 | Max LLM invocations before termination |
costLimit | 1.0 | Max estimated cost in USD |
commandTimeout | 30s | Timeout for shell commands |
workingDirectory | user.dir | Root directory for file/shell tools |
systemPrompt | Built-in SWE prompt | System instructions for the agent |
toBuilder() to derive variants:
Session Memory
Enable session memory to preserve conversation context across multiple calls:ChatMemory implementation:
Interactive Mode
For TUI/CLI applications, interactive mode enables human-in-the-loop viaAskUserQuestionTool:
Result
AgentLoop.Result is a record with execution details:
Observability
AgentLoop wires Micrometer observations for tool call tracking. You can also provide a customToolCallListener:
Relationship to LoopPattern
AgentLoop is not a LoopPattern implementation. It’s a higher-level construct:
LoopPattern— the abstract interface for loop algorithms (TurnLimitedLoop,EvaluatorOptimizerLoop,StateMachineLoop). Lives inworkflow-api.AgentLoop— a concrete, runnable agent that usesAgentLoopAdvisorinternally. Lives inworkflow-agents.
AgentLoop is what you use when you want to run an agent. LoopPattern is what you implement when you want to create a new loop algorithm.