Skip to content

Commit f1803cd

Browse files
author
Mark Pollack
committed
Framework integrations: an @AcpAgent in process with configuration only
An application that drives its own agent set up an InMemoryTransportPair, an agent transport bean, a client and its initialization order, the agent's close and a stdio default by hand, in every framework. Now one property does it, in Spring Boot, Micronaut and Quarkus: spring.acp.agent.transport.type=in-process acp.agent.transport.type=in-process quarkus.acp.agent.transport.type=in-process P1, the in-process type (AcpTransportType.IN_PROCESS, written in-process): the integration serves the @AcpAgent bean on one side of a pair, one per application, and the application's client on the other. A client transport configured as well fails the startup. Shared rules are in acp-integration (AcpInProcess). P2, the client: AcpSyncClient and AcpAsyncClient on the pair's client side, with the client properties, initialized right after the agent starts, closed on shutdown. New handler beans, AcpSessionUpdateHandler (every bean gets every update) and AcpPermissionHandler (at most one), apply to every client the integrations build and may block. Without a permission handler, requests are refused: the agent's reject option, else cancelled. P3, discovery: @AcpAgent alone makes a class a bean. Spring Boot scans the auto-configuration packages (AcpAgentScanAutoConfiguration); Micronaut maps @AcpAgent to @singleton at compile time with the new acp-micronaut-processor on the annotation processor path; Quarkus already did. acp-annotations keeps no framework dependency. P4, lifecycle: shutdown-on-transport-end applies to stdio only (AcpAgentSettings.shutsDownWhenEnded), and an AutoCloseable agent bean is closed once the agent has stopped, on every transport. The deprecated acp-test InMemoryTransportPair is removed. Breaking changes are listed in the CHANGELOG. Each framework has an acceptance test of an application whose agent carries only @AcpAgent: initialize, a prompt with streamed updates, a permission request answered by a handler bean, a clean shutdown that closes the agent once (Micronaut's in a new, unpublished acp-micronaut-integration-tests module).
1 parent 6c2faee commit f1803cd

85 files changed

Lines changed: 2788 additions & 159 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,74 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
Breaking changes in this release are marked **Breaking**; pre-1.0, they come without compatibility shims.
11+
1012
### Added
1113

14+
- **An `@AcpAgent` runs in process with configuration only, in Spring Boot, Micronaut and Quarkus.** Set
15+
`spring.acp.agent.transport.type=in-process`, `acp.agent.transport.type=in-process` or
16+
`quarkus.acp.agent.transport.type=in-process`, and the integration serves the `@AcpAgent` bean on one side of
17+
an `InMemoryTransportPair` and gives the application its `AcpSyncClient` and `AcpAsyncClient` on the other,
18+
with the client properties, initialized once the agent has started and closed when the application stops.
19+
The application writes no transport, pair, client or lifecycle code. Setting a client transport property as
20+
well fails the startup. `AcpTransportType.IN_PROCESS` is the new value, written `in-process`.
21+
- **Client handler beans:** `AcpSessionUpdateHandler` (every bean receives every session update) and
22+
`AcpPermissionHandler` (at most one; it answers `session/request_permission`), in
23+
`com.agentclientprotocol.sdk.integration`. Every client the three integrations build picks them up, on every
24+
transport; they may block.
25+
- **`@AcpAgent` alone makes a class a bean in Spring Boot and Micronaut**, as it already did in Quarkus.
26+
Spring Boot scans the application's packages (those of its `@SpringBootApplication`) for `@AcpAgent` classes
27+
and registers each that is not a bean already. Micronaut needs the new `acp-micronaut-processor` on the
28+
annotation processor path, beside `micronaut-inject-java`; it maps `@AcpAgent` to `@Singleton` at compile
29+
time. `acp-annotations` keeps no framework dependency.
30+
- **The integrations close an `AutoCloseable` agent bean** once the agent has stopped: Micronaut and Quarkus
31+
now do it themselves, on every transport; Spring Boot closes such a bean as it closes any.
32+
- **`AcpClient.AsyncSpec.defaultRequestPermissionHandler`**, a permission handler that applies when the
33+
application registers none, for frameworks, like `defaultSessionUpdateHandler`.
1234
- **A supported in-process transport, `com.agentclientprotocol.sdk.agent.transport.InMemoryTransportPair`, in
1335
acp-core.** It connects an ACP client and an agent in the same JVM, without a process or a port: build the
14-
agent on `agentTransport()` and the client on `clientTransport()`. An application that serves its own agent
15-
to its own code (a web endpoint that drives an `@AcpAgent`, for instance) no longer needs acp-test at
16-
runtime. The two sides exchange ACP's JSON-RPC messages as `AcpSchema` objects, in order, from any number
17-
of sending threads. `create()` takes the JSON mapper from the classpath once for the pair;
18-
`create(AcpJsonMapper)` takes one you configure.
36+
agent on `agentTransport()` and the client on `clientTransport()`. The two sides exchange ACP's JSON-RPC
37+
messages as `AcpSchema` objects, in order, from any number of sending threads. `create()` takes the JSON
38+
mapper from the classpath once for the pair; `create(AcpJsonMapper)` takes one you configure.
1939

2040
### Changed
2141

42+
- **Breaking: `shutdown-on-transport-end` applies to stdio only.** Before, the end of any single transport,
43+
an application's own `AcpAgentTransport` bean included, closed the application; now only the end of a stdio
44+
transport does, in all three integrations. An application that relied on its own transport's end to stop
45+
must stop itself.
46+
- **Breaking: a client an integration builds refuses permission requests it has no handler for.** Without an
47+
`AcpPermissionHandler` bean or a customizer's handler, the client answers `session/request_permission` by
48+
selecting the agent's first reject option (`reject_once`, else `reject_always`), or `cancelled` when it
49+
offers none. Before, it answered `-32601` (method not found). A permission handler bean and a customizer's
50+
permission handler together fail the startup.
51+
- **Breaking: in Spring Boot, every `@AcpAgent` class in the application's packages is a bean.** An
52+
application with several such classes there, one of them a bean of its own before, now fails the startup
53+
("Found 2 @AcpAgent beans"): keep one, or exclude `AcpAgentScanAutoConfiguration` and declare the agent
54+
yourself.
55+
- **Breaking: `AcpClients.async(...)` takes the handler beans** (`AcpClientHandlers`) before the customizers;
56+
framework integrations pass `AcpClientHandlers.of(updateHandlers, permissionHandlers)`.
57+
- **Breaking: `AcpTransportType.parse` and `value()` know `in-process`**, reading `-` and `_` alike; its error
58+
message lists the four values. `AcpAgentSettings.servesHttp()` is true for `http` and `websocket` only. A
59+
client's `transport.type=in-process` fails, naming the agent setting.
60+
- **Breaking (Quarkus internals):** `AcpStdioAgentHost` and `AcpHttpAgentHost` take CDI `Instance`s of the
61+
client and the assembly; `AcpStdioAgentHost` starts the agent early in `StartupEvent`, so the application's
62+
own startup observers find the in-process client ready.
2263
- **Either side's close now ends the in-process connection for both.** Closing the client, the agent, either
2364
transport or the pair completes both transports' `awaitTermination()`: `AcpSyncAgent.run()` returns once
2465
the client closes, the client fails its requests still waiting for the agent at once instead of at their
2566
timeout, and a request the agent sent the client and that is still unanswered fails with `-32603`, as on
2667
stdio. Messages sent before the end are still delivered; a send after it fails with
27-
`AcpConnectionException` (it was a `RuntimeException`). Before, the agent transport ended only when the
28-
agent side closed and the client transport never reported an end.
68+
`AcpConnectionException` (it was a `RuntimeException`).
2969
- **`connect()` and `start()` on the in-process transports complete at once**, as the transport interfaces
3070
specify, instead of when the connection ends. A handler failure on one message no longer stops delivery of
3171
the next on the client side, and transport errors are logged at WARN unless an exception handler is set.
3272

33-
### Deprecated
73+
### Removed
3474

35-
- **`com.agentclientprotocol.sdk.test.InMemoryTransportPair` (acp-test)** delegates to the acp-core class and
36-
is deprecated for removal in a later release. Change the import to
37-
`com.agentclientprotocol.sdk.agent.transport.InMemoryTransportPair`; nothing else changes.
75+
- **Breaking: `com.agentclientprotocol.sdk.test.InMemoryTransportPair` (acp-test).** Use
76+
`com.agentclientprotocol.sdk.agent.transport.InMemoryTransportPair` from acp-core, or, in a framework
77+
application, `transport.type=in-process`. acp-test keeps `MockAcpAgent` and `MockAcpClient`.
3878

3979
## [0.81.0] - 2026-11-10
4080

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,15 @@ that authenticates in front. Browser requests whose `Origin` is not a loopback o
487487
| [`acp-test`](https://central.sonatype.com/artifact/com.agentclientprotocol/acp-test) | In-memory transport and mock utilities for testing |
488488
| `acp-spring-boot-starter` | Spring Boot 4.1 starter: serves an `@AcpAgent` bean over stdio, Streamable HTTP or WebSocket, and builds a client from `spring.acp.client.*`; the autoconfiguration is `acp-spring-boot-autoconfigure` ([README](acp-spring-boot-autoconfigure/README.md)) |
489489
| `acp-micronaut` | Micronaut 4 integration: serves an `@AcpAgent` bean over stdio, Streamable HTTP or WebSocket, and builds a client from `acp.client.*` ([README](acp-micronaut/README.md)) |
490+
| `acp-micronaut-processor` | Micronaut annotation processing: makes an `@AcpAgent` class a singleton bean; add it to the annotation processor path ([README](acp-micronaut/README.md)) |
490491
| `acp-quarkus` | Quarkus extension: an `@AcpAgent` bean over stdio, or Streamable HTTP and WebSocket on the Quarkus HTTP server; client beans from `quarkus.acp.*` ([README](acp-quarkus/README.md)) |
491492

492493
### Transports
493494

494495
| Transport | Client | Agent | Module |
495496
|-----------|--------|-------|--------|
496497
| Stdio | `StdioAcpClientTransport` | `StdioAcpAgentTransport` | acp-core |
497-
| In-process (client and agent in one JVM) | `InMemoryTransportPair.clientTransport()` | `InMemoryTransportPair.agentTransport()` | acp-core |
498+
| In-process (client and agent in one JVM) | `InMemoryTransportPair.clientTransport()` | `InMemoryTransportPair.agentTransport()` | acp-core; in Spring Boot, Micronaut and Quarkus, `transport.type=in-process` on the agent wires both and gives the application its client |
498499
| WebSocket | `WebSocketAcpClientTransport` | `StreamableHttpAcpAgentTransport` (upgrade on the same path) | acp-core / acp-streamable-http-jetty |
499500
| Streamable HTTP | `StreamableHttpAcpClientTransport` | `StreamableHttpAcpAgentTransport` | acp-core / acp-streamable-http-jetty |
500501
| Streamable HTTP and WebSocket in your own Servlet 6 container | `StreamableHttpAcpClientTransport`, `WebSocketAcpClientTransport` | `StreamableHttpAcpServlet` (WebSocket where the container has Jakarta WebSocket 2.1) | acp-core / acp-http-servlet |

‎acp-integration/README.md‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ AcpAgentDiscovery.requireSingle(candidates, "my.acp.agent.enabled").ifPresent(ag
8282
AcpAgentSupport.Builder builder = AcpAgents.builder(agent, settings, interceptors, resolvers, handlers);
8383
AcpHost host = settings.servesHttp()
8484
? new AcpListenerHost(AcpListeners.listener(settings, builder.buildFactory()))
85-
: new AcpAgentHost(builder.transport(AcpAgentTransports.stdio()).build(),
86-
settings.shutdownOnTransportEnd() ? container::close : () -> { });
85+
: new AcpAgentHost(builder.transport(transport).build(), // stdio, or the in-process pair's agent side
86+
settings.shutsDownWhenEnded(transport) ? container::close : () -> { });
8787
host.start(); // from the container's start hook
8888
// host.stop(Duration.ofSeconds(30)) // from its stop hook, or a JVM shutdown hook
8989
});
@@ -104,15 +104,23 @@ AcpAgentDiscovery.requireSingle(candidates, "my.acp.agent.enabled").ifPresent(ag
104104
the `onTransportEnd` action given at construction runs once, on a thread of the host's own,
105105
never when the host stopped the agent itself.
106106
- `AcpListenerHost`: the SDK listener, one agent per connection; it ends only when stopped.
107+
- `settings.shutsDownWhenEnded(transport)`: `shutdown-on-transport-end` applies to a stdio
108+
transport only.
109+
- In process (`transport.type=in-process`, `settings.inProcess()`): `AcpInProcess.pair(...)` once,
110+
refusing a client transport configured as well; serve the agent on `pair.agentTransport()`, build
111+
the client on `pair.clientTransport()`, and `AcpInProcess.initialize(client)` right after the
112+
host has started. On stop, an `AutoCloseable` agent bean is closed once the agent has stopped.
107113
- `AcpServletHost.closeBeforeShutdown`: closes the servlet's connections before the container's
108114
graceful shutdown, which would otherwise wait for every open SSE response.
109115

110116
## The client
111117

112-
`AcpClients.async(transport, settings, customizers)` builds the one async client: capabilities,
113-
request and prompt timeouts, a session-update handler that logs each update at DEBUG, its content
114-
included, then the
115-
`AcpClientCustomizer`s in order. Building the client connects the transport (for stdio, it starts
118+
`AcpClients.async(transport, settings, handlers, customizers)` builds the one async client:
119+
capabilities, request and prompt timeouts, a session-update handler that logs each update at
120+
DEBUG, its content included, a permission handler that refuses, then the application's handler beans
121+
(`AcpClientHandlers.of(sessionUpdateHandlers, permissionHandlers)`: every `AcpSessionUpdateHandler`,
122+
at most one `AcpPermissionHandler`, each run where it may block), then the `AcpClientCustomizer`s in
123+
order. Building the client connects the transport (for stdio, it starts
116124
the agent process); a stdio command that cannot be started, or a transport already connected,
117125
fails the build. The ACP handshake waits for the application's `initialize()`.
118126
`AcpClients.sync(async)` is the sync facade over that same client

‎acp-integration/src/main/java/com/agentclientprotocol/sdk/integration/AcpAgentSettings.java‎

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import java.util.Objects;
1010
import java.util.function.Consumer;
1111

12+
import com.agentclientprotocol.sdk.agent.transport.StdioAcpAgentTransport;
1213
import com.agentclientprotocol.sdk.agent.transport.StreamableHttpAcpAgentTransportOptions;
14+
import com.agentclientprotocol.sdk.spec.AcpAgentTransport;
1315
import org.jspecify.annotations.Nullable;
1416

1517
/**
@@ -30,7 +32,7 @@
3032
* cancel-grace-period SDK default, 60s
3133
* max-prompt-duration SDK default (none)
3234
* shutdown-on-transport-end true
33-
* transport.type stdio | http | websocket (same as http)
35+
* transport.type stdio | http | websocket (same as http) | in-process
3436
* transport.http.path /acp
3537
* transport.http.allowed-origins none (loopback origins only)
3638
* transport.http.max-post-body-size, keep-alive-interval, mailbox-capacity,
@@ -53,8 +55,8 @@
5355
* @param cancelGracePeriod how long a prompt handler has after {@code session/cancel}; null for
5456
* the SDK default
5557
* @param maxPromptDuration how long a prompt turn may run; null for the SDK default (no limit)
56-
* @param shutdownOnTransportEnd whether the application stops when a single transport (stdio)
57-
* ends by itself
58+
* @param shutdownOnTransportEnd whether the application stops when the stdio transport ends by
59+
* itself; it never applies to another transport ({@link #shutsDownWhenEnded})
5860
* @param transport the transport; {@link AcpTransportType#WEBSOCKET} means the same as
5961
* {@link AcpTransportType#HTTP}
6062
* @param http the Streamable HTTP endpoint, used only when {@link #servesHttp()}
@@ -146,10 +148,34 @@ public record Listener(@Nullable String host, int port, @Nullable Integer maxCon
146148
* Returns whether the agent is served over Streamable HTTP (and WebSocket) rather than on one
147149
* transport. A framework uses it to choose between an {@link AcpListenerHost} or servlet and
148150
* an {@link AcpAgentHost}.
149-
* @return true for {@code http} and {@code websocket}, false for {@code stdio}
151+
* @return true for {@code http} and {@code websocket}, false for {@code stdio} and
152+
* {@code in-process}
150153
*/
151154
public boolean servesHttp() {
152-
return transport != AcpTransportType.STDIO;
155+
return transport == AcpTransportType.HTTP || transport == AcpTransportType.WEBSOCKET;
156+
}
157+
158+
/**
159+
* Returns whether the agent is served in process, with the application's client on the other
160+
* side of an {@link com.agentclientprotocol.sdk.agent.transport.InMemoryTransportPair}.
161+
* @return true for {@code in-process}
162+
*/
163+
public boolean inProcess() {
164+
return transport == AcpTransportType.IN_PROCESS;
165+
}
166+
167+
/**
168+
* Returns whether the application stops when this transport ends by itself: only when
169+
* {@link #shutdownOnTransportEnd()} is true and the transport is stdio, where the end means
170+
* the client that started the agent process has gone. An in-process transport, or another
171+
* transport the application provides, ends when the application's own client closes, so it
172+
* never stops the application. The framework gives an {@link AcpAgentHost} the action that
173+
* stops it only when this is true.
174+
* @param transport the transport the agent is served on
175+
* @return whether the transport's end stops the application
176+
*/
177+
public boolean shutsDownWhenEnded(AcpAgentTransport transport) {
178+
return shutdownOnTransportEnd && transport instanceof StdioAcpAgentTransport;
153179
}
154180

155181
/**
@@ -350,9 +376,9 @@ public Builder maxPromptDuration(@Nullable Duration maxPromptDuration) {
350376
}
351377

352378
/**
353-
* Sets whether the application stops when a single transport (stdio) ends by itself,
354-
* that is, when the client closed the agent's input. Default true. The framework acts on
355-
* it through the action it gives {@link AcpAgentHost}.
379+
* Sets whether the application stops when the stdio transport ends by itself, that is,
380+
* when the client closed the agent's input. Default true; it never applies to another
381+
* transport. The framework acts on it through the action it gives {@link AcpAgentHost}.
356382
* @param shutdownOnTransportEnd whether to stop at transport end
357383
* @return this builder
358384
*/
@@ -363,7 +389,8 @@ public Builder shutdownOnTransportEnd(boolean shutdownOnTransportEnd) {
363389

364390
/**
365391
* Sets the transport. Default {@link AcpTransportType#STDIO};
366-
* {@link AcpTransportType#WEBSOCKET} means the same as {@link AcpTransportType#HTTP}.
392+
* {@link AcpTransportType#WEBSOCKET} means the same as {@link AcpTransportType#HTTP}, and
393+
* {@link AcpTransportType#IN_PROCESS} serves the agent to the application's own client.
367394
* @param transport the transport
368395
* @return this builder
369396
*/

0 commit comments

Comments
 (0)