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
  • Why no @Initialize method is needed: the SDK derives it from the class
  • Redirecting logging to stderr for stdio agents

Dependencies

Add the ACP Spring Boot Starter:
As of 0.80.0, the starter is a module of the ACP Java SDK itself (com.agentclientprotocol, replacing org.springaicommunity), versioned together with it; see the 0.80.0 migration guide. It brings the Jackson 3 JSON module, acp-json-jackson3, so you add no JSON dependency yourself.
The downloadable module builds against the released starter (org.springaicommunity, SDK 0.18.0) by default; build with -Psdk-candidate to use the SDK’s own starter at the coordinates shown above.

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:
No @Initialize method: as of 0.80.0, the SDK derives the initialize answer from the class itself (agentInfo from @AcpAgent(name, version) here). See Clients and Agents in Java for the full derivation rules. 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 @NewSession, @Prompt, and any other handler methods; derives initialize from the class if there’s no @Initialize
  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

Configuration Properties

Next

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