Skip to main content
Complete API reference for the ACP Java SDK, covering client, agent (all three styles), protocol types, transports, errors, and test utilities.

Installation

Maven (0.14.0 — stable)

Core SDK (client + sync/async agent APIs):
Annotation-based agent support (includes acp-core transitively):
Test utilities:
WebSocket server transport for agents:

Gradle

Snapshot (0.15.0-SNAPSHOT)

For unreleased features, add the snapshot repository and use the snapshot version:
Then use 0.15.0-SNAPSHOT in place of 0.14.0 in your dependencies.

Three Agent API Styles

Quick Comparison

FeatureAnnotation-basedSyncAsync
Entry Point@AcpAgent classAcpAgent.sync()AcpAgent.async()
Handler StyleAnnotated methodsLambda callbacksLambda callbacks returning Mono
Return ValuesAuto-converted (StringPromptResponse)Direct protocol typesMono<ProtocolType>
BoilerplateLowestModerateModerate
Best ForMost applicationsSimple blocking handlersReactive applications
RuntimeAcpAgentSupportAcpSyncAgentAcpAsyncAgent
All three produce identical protocol behavior and support the same capabilities.

When to Use Each

  • Annotation-based — default choice. Least boilerplate, auto-converts return types, supports interceptors and custom argument resolvers.
  • Sync — when you want explicit control over every handler without annotations. Blocking void methods for sending updates.
  • Async — when your agent needs non-blocking I/O. Uses Project Reactor Mono for composable async chains.

Client API

AcpClient — Factory

MethodReturn TypeDescription
sync(transport)AcpSyncClient.BuilderCreate blocking client builder
async(transport)AcpAsyncClient.BuilderCreate reactive client builder

AcpSyncClient — Blocking Client

MethodReturn TypeDescription
initialize()InitializeResponseProtocol handshake with defaults
initialize(request)InitializeResponseHandshake with custom capabilities
authenticate(request)AuthenticateResponseAuthenticate with a method ID
logout(request)LogoutResponseClear stored credentials (0.14.0)
newSession(request)NewSessionResponseCreate a new session
loadSession(request)LoadSessionResponseResume an existing session (replays history)
listSessions(request)ListSessionsResponseList sessions, optional cwd filter (0.12.0)
resumeSession(request)ResumeSessionResponseReconnect to session without history replay (0.12.0)
closeSession(request)CloseSessionResponseClose session and free resources (0.12.0)
deleteSession(request)DeleteSessionResponsePermanently delete a stored session (0.14.0)
forkSession(request)ForkSessionResponseFork a session into a new branch (0.12.0, unstable)
setSessionConfigOption(request)SetSessionConfigOptionResponseSet a session config value (0.12.0)
listProviders(request)ListProvidersResponseList configurable model/backend providers (0.14.0, unstable)
setProvider(request)SetProviderResponseConfigure a provider (protocol, base URL, headers) (0.14.0, unstable)
disableProvider(request)DisableProviderResponseDisable a provider by id (0.14.0, unstable)
prompt(request)PromptResponseSend prompt, block until response
cancel(notification)voidCancel current prompt (fire-and-forget)
getAgentCapabilities()NegotiatedCapabilitiesCapabilities reported by agent
close()voidClose connection

Builder Configuration

Example — Complete client lifecycle

This launches Gemini CLI as an ACP agent subprocess and sends it a prompt. AgentParameters builds the command line; StdioAcpClientTransport spawns the process and handles JSON-RPC framing over stdin/stdout.

Agent API — Annotation-Based

The acp-agent-support module provides a declarative programming model using annotations.

Annotations

Class-Level

AnnotationDescription
@AcpAgentMarks a class as an ACP agent. Optional name and version attributes.

Handler Methods

AnnotationJSON-RPC MethodDescription
@InitializeinitializeProtocol initialization and capability negotiation
@LogoutlogoutClears stored credentials (0.14.0)
@NewSessionsession/newCreates a new agent session
@LoadSessionsession/loadLoads an existing session by ID (replays history)
@ListSessionssession/listLists sessions with optional cwd filter (0.12.0)
@ResumeSessionsession/resumeReconnects to session without history replay (0.12.0)
@CloseSessionsession/closeCloses session and frees resources (0.12.0)
@DeleteSessionsession/deletePermanently deletes a stored session (0.14.0)
@ForkSessionsession/forkForks a session into a new branch (0.12.0, unstable)
@SetSessionConfigOptionsession/set_config_optionSets a session config value (0.12.0)
@ListProvidersproviders/listLists configurable providers (0.14.0, unstable)
@SetProviderproviders/setConfigures a provider (0.14.0, unstable)
@DisableProviderproviders/disableDisables a provider by id (0.14.0, unstable)
@Promptsession/promptHandles user prompts
@SetSessionModesession/set_modeChanges operational mode
@SetSessionModelsession/set_modelDeprecated — removed from the spec; use @SetSessionConfigOption with a "model" category option
@Cancelsession/cancelCancellation notification (fire-and-forget)
Deprecated: the session-model API (0.14.0). session/set_model and the related types (@SetSessionModel, SetSessionModelRequest/Response, SessionModelState, ModelInfo, and the models field on session responses) were removed from the ACP spec in June 2026 and are marked @Deprecated(forRemoval = true). They still work for now but will be removed in a future release. Expose model selection through session/set_config_option instead: advertise a select config option whose category is "model", and switch models with setSessionConfigOption(...). This is the same mechanism used for session modes (category: "mode") and reasoning level (category: "thought_level").

Parameter Annotations

AnnotationDescription
@SessionIdInjects the current session ID as String
@SessionStateInjects session-specific state

Flexible Method Signatures

Handler methods support flexible parameter resolution:

Return Value Handling

Return TypeConversion
Protocol response typePassed through directly
StringConverted to PromptResponse.text(value)
voidConverted to PromptResponse.endTurn()
Mono<PromptResponse>Unwrapped and returned

SyncPromptContext

Available in @Prompt handlers. Provides blocking methods for agent-client interaction:

AcpAgentSupport — Bootstrap

Interceptors

Cross-cutting concerns like logging, metrics, or error handling:

Example — Complete annotation-based agent


Agent API — Sync (Builder)

Blocking handlers with plain return values. No annotations.

Builder Methods

MethodDescription
initializeHandler(handler)Handle initialize requests
authenticateHandler(handler)Handle authenticate requests
logoutHandler(handler)Handle logout requests (0.14.0)
newSessionHandler(handler)Handle session/new requests
loadSessionHandler(handler)Handle session/load requests
listSessionsHandler(handler)Handle session/list requests (0.12.0)
resumeSessionHandler(handler)Handle session/resume requests (0.12.0)
closeSessionHandler(handler)Handle session/close requests (0.12.0)
deleteSessionHandler(handler)Handle session/delete requests (0.14.0)
forkSessionHandler(handler)Handle session/fork requests (0.12.0, unstable)
setSessionConfigOptionHandler(handler)Handle session/set_config_option requests (0.12.0)
listProvidersHandler(handler)Handle providers/list requests (0.14.0, unstable)
setProviderHandler(handler)Handle providers/set requests (0.14.0, unstable)
disableProviderHandler(handler)Handle providers/disable requests (0.14.0, unstable)
promptHandler(handler)Handle session/prompt requests
cancelHandler(handler)Handle session/cancel notifications

Example

Prompt Handler Context

The context parameter in promptHandler provides:
MethodDescription
getSessionId()Current session ID
sendMessage(text)Send AgentMessageChunk
sendThought(text)Send AgentThoughtChunk
sendUpdate(sessionId, update)Send any SessionUpdate
readFile(path, offset, limit)Read file from client
writeFile(path, content)Write file on client
requestPermission(request)Ask client for permission
getClientCapabilities()Check client capabilities

Agent API — Async (Builder)

Reactive handlers returning Mono. Uses Project Reactor.

Example

The async context’s sendMessage(), sendUpdate(), etc. return Mono<Void>, composable with .then() and .flatMap().

Convenience Methods vs Full API

The SDK provides convenience methods that cover the most common operations. Use these by default — they produce cleaner code and handle the protocol details for you.

When convenience methods are enough (~80% of cases)

When to use the full API (~20% of cases)

Drop to the full API when you need control that convenience methods don’t expose:
The convenience methods are wrappers around the full API — they call the same underlying protocol methods. You can mix and match freely within a single handler.

Protocol Types

All protocol types are defined in AcpSchema as Java records.

Request/Response Types

TypeFields
InitializeRequestprotocolVersion, clientCapabilities
InitializeResponseprotocolVersion, agentCapabilities, authMethods, agentInfo
AuthenticateRequestmethodId
AuthenticateResponse(empty)
LogoutRequest(empty) (0.14.0)
LogoutResponse(empty) (0.14.0)
NewSessionRequestcwd, mcpServers, additionalDirectories (additionalDirectories 0.14.0)
NewSessionResponsesessionId, modes, models (models deprecated — see below)
LoadSessionRequestsessionId, cwd, mcpServers, additionalDirectories (additionalDirectories 0.14.0)
LoadSessionResponsemodes, models (deprecated)
ListSessionsRequestcwd (optional filter), cursor (pagination) (0.12.0)
ListSessionsResponsesessions (list of SessionInfo), nextCursor (0.12.0)
ResumeSessionRequestsessionId, cwd, mcpServers, additionalDirectories (0.12.0; additionalDirectories 0.14.0)
ResumeSessionResponsemodes, models (0.12.0; models deprecated)
CloseSessionRequestsessionId (0.12.0)
CloseSessionResponse(empty) (0.12.0)
DeleteSessionRequestsessionId (0.14.0)
DeleteSessionResponse(empty) (0.14.0)
ForkSessionRequestsessionId, cwd, mcpServers, additionalDirectories (0.12.0, unstable)
ForkSessionResponsesessionId, modes, models, configOptions (0.12.0, unstable; models deprecated)
SetSessionConfigOptionRequestsessionId, configId, value, type (0.12.0)
SetSessionConfigOptionResponseconfigOptions (full config state) (0.12.0)
ListProvidersRequest(empty) (0.14.0, unstable)
ListProvidersResponseproviders (list of ProviderInfo) (0.14.0, unstable)
SetProviderRequestid, apiType, baseUrl, headers (0.14.0, unstable)
SetProviderResponse(empty) (0.14.0, unstable)
DisableProviderRequestid (0.14.0, unstable)
DisableProviderResponse(empty) (0.14.0, unstable)
CreateElicitationRequestsessionId, message, mode, requestedSchema (0.12.0, unstable)
CreateElicitationResponseaction (accept/decline/cancel), content (0.12.0, unstable)
CompleteElicitationNotificationelicitationId (0.12.0, unstable)
PromptRequestsessionId, prompt (list of ContentBlock)
PromptResponsestopReason
CancelNotificationsessionId

Session Types (0.12.0)

TypeFieldsDescription
SessionInfosessionId, cwd, title, updatedAt, additionalDirectoriesSession metadata returned by session/list (additionalDirectories 0.14.0)
SessionCapabilitieslist, close, resume, delete, additionalDirectories, forkNested capability flags on AgentCapabilities (delete, additionalDirectories 0.14.0; fork unstable)

Config Option Types (0.12.0)

session/set_config_option is stable. The select variant is the stable shape; boolean is an SDK extension.
TypeDescription
SessionConfigOptionPolymorphic: SessionConfigSelect or SessionConfigBoolean
SessionConfigSelectSelect-type config with currentValue, category, and options list
SessionConfigBooleanBoolean toggle with currentValue (unstable extension)
SessionConfigSelectOptionA named value within a select config (value, name)
ConfigOptionUpdateSessionUpdate variant for agent-pushed config changes

Provider Types (0.14.0, unstable)

Model/backend routing configuration. The agent advertises support with a providers capability; the client manages providers via listProviders / setProvider / disableProvider.
TypeDescription
ProviderInfoA configurable provider: id, supported (protocol ids), required, current
ProviderCurrentConfigCurrent effective routing: apiType, baseUrl
ProvidersCapabilitiesAgent capability marker (presence = supported), on AgentCapabilities
apiType / supported use well-known LlmProtocol ids (anthropic, openai, azure, vertex, bedrock) or a custom string, modeled as String in the SDK.

Elicitation Types (0.12.0, unstable)

TypeDescription
ElicitationSchemaJSON Schema describing form fields (properties, required)
ElicitationPropertySchemaPolymorphic: StringPropertySchema, NumberPropertySchema, IntegerPropertySchema, BooleanPropertySchema, MultiSelectPropertySchema
EnumOptionNamed value for select/multi-select (const, title)
ElicitationCapabilitiesClient capability for form and/or URL elicitation
ElicitationActionEnum: ACCEPT, DECLINE, CANCEL

Content Types

TypeDescription
TextContentText content with text field
ImageContentImage content (base64 or URL)

Session Update Types

TypeDescription
UserMessageChunkIncremental user message text (optional messageId)
AgentMessageChunkIncremental response text (optional messageId — 0.14.0)
AgentThoughtChunkAgent thinking process (optional messageId — 0.14.0)
ToolCallTool execution start
ToolCallUpdateNotificationTool progress update
PlanAgent’s planned steps
AvailableCommandsUpdateAdvertised slash commands
CurrentModeUpdateAgent mode change
UsageUpdateContext window and cost usage
ConfigOptionUpdateSession config option changes
Content chunks (UserMessageChunk, AgentMessageChunk, AgentThoughtChunk) carry an optional messageId: chunks sharing the same id belong to one logical message, and a change in id starts a new message (0.14.0).

Stop Reasons

ValueDescription
END_TURNAgent finished responding
MAX_TOKENSToken limit reached
REFUSALAgent refused the request
CANCELLEDPrompt was cancelled

Convenience Methods


Capabilities

Client Capabilities

Advertised during initialize:

NegotiatedCapabilities

Check capabilities before using them:
Or use require methods that throw AcpCapabilityException if unsupported:

Session Capabilities (0.12.0)

Agents advertise session management support via SessionCapabilities. The NegotiatedCapabilities accessors are: supportsListSessions(), supportsCloseSession(), supportsResumeSession(), supportsDeleteSession() (0.14.0), supportsAdditionalDirectories() (0.14.0), and supportsForkSession() (unstable) — each with a matching require*() that throws AcpCapabilityException.

Elicitation Capabilities (0.12.0, unstable)

Clients advertise elicitation support during initialization:

@UnstableAcpApi

APIs marked @UnstableAcpApi correspond to protocol elements in schema.unstable.json. They are public and functional but may change in any minor release. When the protocol element stabilizes, the annotation is removed (compatible change). See Versioning for the full policy. IntelliJ users can configure the Unstable API Usage inspection (Settings > Inspections > JVM languages) to flag usages.

Transports

TransportClient ClassAgent ClassModule
StdioStdioAcpClientTransportStdioAcpAgentTransportacp-core
WebSocketWebSocketAcpClientTransportWebSocketAcpAgentTransportacp-core / acp-websocket-jetty
In-Memoryvia InMemoryTransportPairvia InMemoryTransportPairacp-test

Stdio Transport

The default transport. The client launches the agent as a subprocess and communicates via JSON-RPC over stdin/stdout. This is the same mechanism Zed, JetBrains, and VS Code use to talk to agents. Client sideAgentParameters specifies the command to launch. Any executable that speaks ACP over stdin/stdout works (Gemini CLI, your own agent JAR, etc.):
Agent side — reads JSON-RPC from stdin, writes responses to stdout. The agent doesn’t need to know what launched it:

WebSocket Transport

For network-based communication. Client (JDK-native, no extra dependencies):
Agent (requires acp-websocket-jetty):

In-Memory Transport

For testing. No subprocess or network I/O.

Errors

Exception Hierarchy

ExceptionDescription
AcpProtocolExceptionJSON-RPC protocol error with code and message
AcpCapabilityExceptionTried to use an unsupported capability
AcpConnectionExceptionTransport-level connection failure

Error Codes

Agent-Side Error Handling

Throw AcpProtocolException from handlers to send structured errors to clients:

Test Utilities

The acp-test module provides utilities for testing without subprocesses.

InMemoryTransportPair


Packages

PackageDescription
com.agentclientprotocol.sdk.specProtocol types (AcpSchema.*)
com.agentclientprotocol.sdk.clientClient SDK (AcpClient, AcpAsyncClient, AcpSyncClient)
com.agentclientprotocol.sdk.agentAgent SDK (AcpAgent, AcpAsyncAgent, AcpSyncAgent)
com.agentclientprotocol.sdk.agent.supportAnnotation-based agent runtime (AcpAgentSupport)
com.agentclientprotocol.sdk.annotationAgent annotations (@AcpAgent, @Prompt, etc.)
com.agentclientprotocol.sdk.capabilitiesCapability negotiation (NegotiatedCapabilities)
com.agentclientprotocol.sdk.errorExceptions (AcpProtocolException, AcpCapabilityException)
com.agentclientprotocol.sdk.testTest utilities (InMemoryTransportPair)

Maven Artifacts

ArtifactDescription
acp-coreClient and Agent SDKs, stdio and WebSocket client transports
acp-annotations@AcpAgent, @Prompt, and other annotations
acp-agent-supportAnnotation-based agent runtime (includes acp-annotations + acp-core)
acp-testIn-memory transport and test utilities
acp-websocket-jettyJetty-based WebSocket server transport for agents

See Also