Skip to main content

Module 23: Spring Boot Agent

Build an ACP agent as a Spring Boot application. No manual transport or lifecycle wiring required.

Prerequisites

What Youโ€™ll Learn

  • Using @AcpAgent annotations 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:
The application class is a standard @SpringBootApplication:

What the Autoconfiguration Does

When Spring Boot starts, the ACP autoconfiguration:
  1. Creates a StdioAcpAgentTransport โ€” the default for agents (reads stdin, writes stdout)
  2. Discovers the @AcpAgent bean โ€” scans the application context for exactly one @AcpAgent-annotated bean
  3. Wires through AcpAgentSupport โ€” resolves @Initialize, @NewSession, @Prompt handler methods
  4. Starts via SmartLifecycle โ€” the agent starts after the application context refreshes and stops on shutdown
No explicit 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:
The 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

AspectModule 12 (Builder)Module 23 (Spring Boot)
TransportManual new StdioAcpAgentTransport()Autoconfigured
HandlersLambda callbacks via builderAnnotated methods on a bean
LifecycleExplicit agent.run()SmartLifecycle (automatic)
ConfigurationHardcoded in Javaapplication.properties
Dependenciesacp-core onlyacp-spring-boot-starter

Configuration Properties

PropertyDefaultDescription
spring.acp.agent.enabledtrueEnable/disable agent autoconfiguration
spring.acp.agent.request-timeout60sRequest processing timeout
spring.acp.agent.transport.typestdioTransport type (currently only stdio)

Next

Module 24: Spring Boot Client โ€” use the autoconfigured client to connect to agents. View on GitHub