Skip to content

Latest commit

 

History

History

module-42-in-process

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Module 42: One Agent, Three Frameworks, In Process

New in SDK 0.82.0. One agent class, carrying only @AcpAgent and no framework import, is served in process by a Spring Boot, a Micronaut and a Quarkus application. Each application sets its framework's transport.type=in-process property, injects AcpSyncClient, and declares one AcpPermissionHandler bean. The integration serves the agent on one side of an InMemoryTransportPair and hands the application an initialized client on the other side. The application writes no transport, pair, client or lifecycle code. No process, no port, no API key.

Requires Java 21+ for the Spring Boot application (Spring Boot 4.x); the agent, Micronaut and Quarkus modules build on Java 17.

Layout

Module What it is
agent/ ReleaseAgent: the one @AcpAgent class, in a plain jar built on acp-annotations and acp-core only
spring-boot/ A Spring Boot application that serves it in process
micronaut/ A Micronaut application that serves it in process
quarkus/ A Quarkus application that serves it in process

The agent is compiled once, into module-42-agent.jar, and each application depends on that jar. This is how a team shares one agent across applications, and it shows what each framework needs to find a class it did not compile.

The agent

@AcpAgent(name = "release-agent", version = "1.0.0")
public class ReleaseAgent {

    @NewSession
    public NewSessionResponse newSession(NewSessionRequest request) {
        return new NewSessionResponse(UUID.randomUUID().toString(), null, null);
    }

    @Prompt
    public PromptResponse prompt(PromptRequest request, SyncPromptContext context) {
        String action = request.text();
        context.sendMessage("I am ready to " + action + ".");
        boolean allowed = context.askPermission(action);      // one session/request_permission
        context.sendMessage(allowed ? "Done: " + action + "." : "Not done: permission refused.");
        return PromptResponse.endTurn();
    }
}

What each framework needs

These are all the lines each application needs. Everything else in the three applications is the same Java: ReleaseDesk (injects AcpSyncClient, opens a session, sends a prompt), Approver (the AcpPermissionHandler, which allows once) and Transcript (an AcpSessionUpdateHandler that keeps the agent's messages). Only their bean annotation differs.

Spring Boot Micronaut Quarkus
Dependency com.agentclientprotocol:acp-spring-boot-starter com.agentclientprotocol:acp-micronaut com.agentclientprotocol:acp-quarkus, built by quarkus-maven-plugin
Annotation processor none com.agentclientprotocol:acp-micronaut-processor beside io.micronaut:micronaut-inject-java none
In process spring.acp.agent.transport.type=in-process acp.agent.transport.type=in-process quarkus.acp.agent.transport.type=in-process
Find the agent in the shared jar none: the @SpringBootApplication class is in com.acptutorial.module42, which encloses the agent's package @Import(packages = "com.acptutorial.module42.agent") on the application class quarkus.index-dependency.agent.group-id=com.agentclientprotocol
quarkus.index-dependency.agent.artifact-id=module-42-agent
The client ReleaseDesk(AcpSyncClient client, ...) ReleaseDesk(AcpSyncClient client, ...) ReleaseDesk(AcpSyncClient client, ...)
Permission handler bean @Component class Approver implements AcpPermissionHandler @Singleton class Approver implements AcpPermissionHandler @ApplicationScoped class Approver implements AcpPermissionHandler
Test @SpringBootTest ApplicationContext.run() @QuarkusTest

Why "find the agent" differs

@AcpAgent alone makes a class a bean in all three frameworks, but each framework finds classes its own way. A class compiled elsewhere meets each one differently:

  • Spring Boot scans the application's packages at startup, those of its @SpringBootApplication, and the scan covers jars on the classpath. An application class placed above the agent's package is enough. With the application class in a sibling package, the agent would not be found. In that case, import it or declare it as a bean.
  • Micronaut has no runtime scan. Its annotation processors write bean definitions at compile time, and only for the sources they compile. acp-micronaut-processor maps @AcpAgent to @Singleton there, but the agent arrives already compiled. @Import(packages = ...) tells the processors to write definitions for that package's classes while they compile the application. Without it, the application has no agent bean, and its client's first session/new fails with "Call initialize() first: the agent has not answered initialize".
  • Quarkus finds @AcpAgent at build time in its Jandex index. The index covers the application's classes and jars that carry an index, but not a plain jar like this one. quarkus.index-dependency.* adds the jar to the index. Without it, the build finds no agent, and startup fails with "No ACP client transport is configured".

Each of these three failures was reproduced by removing that one line and running the module's test.

If the agent class sits in each application's own sources instead of a shared jar, the "find the agent" row is empty for all three. Micronaut still needs acp-micronaut-processor.

The permission handler

The agent asks permission once per prompt (context.askPermission(action)). The client the framework built passes the request to the application's one AcpPermissionHandler bean, here Approver, which selects the allow_once option. Changed in SDK 0.82.0: without such a bean, the client refuses. It selects the agent's first reject option, so this agent would answer "Not done: permission refused." Before 0.82.0, the client answered -32601, method not found. More than one permission handler bean fails the startup.

Tests

One test per framework runs a prompt round trip that includes the permission request. It asserts end_turn, that Approver was asked once about "publish the release notes", and that the agent said "I am ready to publish the release notes." and then "Done: publish the release notes.".

./mvnw verify -pl module-42-in-process/agent,module-42-in-process/spring-boot,module-42-in-process/micronaut,module-42-in-process/quarkus -am

Running

# The shared agent jar, once
./mvnw -q install -pl module-42-in-process/agent -am -DskipTests

./mvnw -q compile exec:java -pl module-42-in-process/spring-boot
./mvnw -q compile exec:java -pl module-42-in-process/micronaut
./mvnw -q package -pl module-42-in-process/quarkus -DskipTests
java -jar module-42-in-process/quarkus/target/quarkus-app/quarkus-run.jar

Each one prints:

=== Module 42: <framework>, in process ===
agent: I am ready to publish the release notes.
agent: Done: publish the release notes.
stop reason: end_turn