Skip to main content

Module 24: Spring Boot Client

Use the autoconfigured ACP client in a Spring Boot application. Connect to agents with just properties — no manual transport or client construction.

Prerequisites

What You’ll Learn

  • Injecting AcpSyncClient from autoconfiguration
  • Configuring the client transport via application.properties
  • Property-driven transport selection (stdio vs WebSocket)

Dependencies

Same starter as the agent side:
<dependency>
    <groupId>org.springaicommunity</groupId>
    <artifactId>acp-spring-boot-starter</artifactId>
    <version>0.11.0</version>
</dependency>

The Client

The autoconfigured AcpSyncClient is injected like any Spring bean:
@SpringBootApplication
public class ClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }

    @Bean
    CommandLineRunner demo(AcpSyncClient client) {
        return args -> {
            // Initialize the connection
            client.initialize();

            // Create a session
            String cwd = System.getProperty("user.dir");
            var session = client.newSession(new NewSessionRequest(cwd, List.of()));

            // Send a prompt
            var response = client.prompt(new PromptRequest(
                session.sessionId(),
                List.of(new TextContent("Hello from Spring Boot client!"))));

            System.out.println("Stop reason: " + response.stopReason());
        };
    }
}

Configuration

application.properties:
# Connect to the module-23 agent via stdio transport
spring.acp.client.transport.stdio.command=java
spring.acp.client.transport.stdio.args=-jar,module-23-spring-boot-agent/target/module-23-spring-boot-agent-1.0.0-SNAPSHOT.jar

# Increase timeout for Spring Boot agent startup
spring.acp.client.request-timeout=60s
The autoconfiguration detects the stdio.command property and creates a StdioAcpClientTransport that launches the agent as a subprocess.

What the Autoconfiguration Does

  1. Detects transport propertiesstdio.command triggers stdio transport; websocket.uri triggers WebSocket
  2. Creates AcpSyncClient and AcpAsyncClient — configured with timeout and client capabilities
  3. Manages shutdownDisposableBean calls closeGracefully() on context close

Transport Selection

The autoconfiguration picks the transport based on which properties are set:
Properties SetTransport Created
spring.acp.client.transport.stdio.commandStdioAcpClientTransport
spring.acp.client.transport.websocket.uriWebSocketAcpClientTransport
spring.acp.client.transport.type=stdioExplicit stdio selection
spring.acp.client.transport.type=websocketExplicit WebSocket selection

Build & Run

# Build both the agent and client
./mvnw package -pl module-23-spring-boot-agent,module-24-spring-boot-client -q

# Run the client (from repo root)
./mvnw spring-boot:run -pl module-24-spring-boot-client

Client Configuration Properties

PropertyDefaultDescription
spring.acp.client.request-timeout30sRequest timeout
spring.acp.client.transport.typeauto-detectstdio or websocket
spring.acp.client.transport.stdio.commandCommand to launch agent
spring.acp.client.transport.stdio.argsCommand arguments
spring.acp.client.transport.stdio.env.*Environment variables
spring.acp.client.transport.websocket.uriWebSocket URI
spring.acp.client.transport.websocket.connect-timeout10sConnection timeout
spring.acp.client.capabilities.read-text-filetrueAdvertise file read capability
spring.acp.client.capabilities.write-text-filetrueAdvertise file write capability
spring.acp.client.capabilities.terminalfalseAdvertise terminal capability
View on GitHub