Module 23: Spring Boot Agent
Build an ACP agent as a Spring Boot application. No manual transport or lifecycle wiring required.Prerequisites
- Java 21+ (Spring Boot 4.x requirement)
- Completed Module 12: Echo Agent
What You’ll Learn
- Using
@AcpAgentannotations with Spring Boot autoconfiguration - How the starter eliminates boilerplate transport and lifecycle code
- Redirecting logging to stderr for stdio agents
Dependencies
Add the ACP Spring Boot Starter:The Agent
Compare this with Module 12’s builder-based agent. The annotation approach replaces the builder chain with annotated methods on a Spring bean:@SpringBootApplication:
What the Autoconfiguration Does
When Spring Boot starts, the ACP autoconfiguration:- Creates a
StdioAcpAgentTransport— the default for agents (reads stdin, writes stdout) - Discovers the
@AcpAgentbean — scans the application context for exactly one@AcpAgent-annotated bean - Wires through
AcpAgentSupport— resolves@Initialize,@NewSession,@Prompthandler methods - Starts via
SmartLifecycle— the agent starts after the application context refreshes and stops on shutdown
agent.run() call. No manual transport creation. Spring manages it all.
Stdio and Logging
Agent stdout is reserved for the JSON-RPC protocol. Spring Boot’s default logging writes to stdout, which would corrupt the protocol stream. Three configuration changes fix this: application.properties:keep-alive setting is essential. Without it, the Spring Boot application starts the agent, then exits immediately because there’s no web server keeping the JVM alive.
logback-spring.xml:
Build & Run
Module 12 vs Module 23
| Aspect | Module 12 (Builder) | Module 23 (Spring Boot) |
|---|---|---|
| Transport | Manual new StdioAcpAgentTransport() | Autoconfigured |
| Handlers | Lambda callbacks via builder | Annotated methods on a bean |
| Lifecycle | Explicit agent.run() | SmartLifecycle (automatic) |
| Configuration | Hardcoded in Java | application.properties |
| Dependencies | acp-core only | acp-spring-boot-starter |
Configuration Properties
| Property | Default | Description |
|---|---|---|
spring.acp.agent.enabled | true | Enable/disable agent autoconfiguration |
spring.acp.agent.request-timeout | 60s | Request processing timeout |
spring.acp.agent.transport.type | stdio | Transport type (currently only stdio) |