public interface AcpAgent
This class serves as the main entry point for implementing ACP-compliant agents, implementing the agent-side of the ACP specification. The protocol follows a client-agent architecture where:
The class provides factory methods to create either:
AcpAsyncAgent for non-blocking operations with Mono/Flux responsesAcpSyncAgent for blocking operations with direct responsesExample of creating a basic asynchronous agent:
AcpAsyncAgent agent = AcpAgent.async(transport)
.requestTimeout(Duration.ofSeconds(30))
.agentInfo(new AcpSchema.AgentCapabilities(true, null, null))
.initializeHandler(request -> {
return Mono.just(new AcpSchema.InitializeResponse(1,
new AcpSchema.AgentCapabilities(), List.of()));
})
.newSessionHandler(request -> {
return Mono.just(new AcpSchema.NewSessionResponse(
"session-1", null, null));
})
.promptHandler((request, updater) -> {
updater.sendUpdate(new AcpSchema.AgentMessageChunk(
"agent_message_chunk",
new AcpSchema.TextContent("Working on it...")));
return Mono.just(new AcpSchema.PromptResponse(AcpSchema.StopReason.END_TURN));
})
.build();
agent.start().block();
The agent supports:
AcpAsyncAgent,
AcpAgentTransport| 限定符和类型 | 接口和说明 |
|---|---|
static class |
AcpAgent.AsyncAgentBuilder
Builder for creating asynchronous ACP agents.
|
static interface |
AcpAgent.AuthenticateHandler
Functional interface for handling authenticate requests.
|
static interface |
AcpAgent.CancelHandler
Functional interface for handling cancel notifications.
|
static interface |
AcpAgent.InitializeHandler
Functional interface for handling initialize requests.
|
static interface |
AcpAgent.LoadSessionHandler
Functional interface for handling load session requests.
|
static interface |
AcpAgent.NewSessionHandler
Functional interface for handling new session requests.
|
static interface |
AcpAgent.PromptHandler
Functional interface for handling prompt requests with full agent context.
|
static interface |
AcpAgent.SetSessionModeHandler
Functional interface for handling set session mode requests.
|
static interface |
AcpAgent.SetSessionModelHandler
Functional interface for handling set session model requests.
|
static class |
AcpAgent.SyncAgentBuilder
Builder for creating synchronous ACP agents.
|
static interface |
AcpAgent.SyncAuthenticateHandler
Synchronous functional interface for handling authenticate requests.
|
static interface |
AcpAgent.SyncCancelHandler
Synchronous functional interface for handling cancel notifications.
|
static interface |
AcpAgent.SyncInitializeHandler
Synchronous functional interface for handling initialize requests.
|
static interface |
AcpAgent.SyncLoadSessionHandler
Synchronous functional interface for handling load session requests.
|
static interface |
AcpAgent.SyncNewSessionHandler
Synchronous functional interface for handling new session requests.
|
static interface |
AcpAgent.SyncPromptHandler
Synchronous functional interface for handling prompt requests with full agent context.
|
static interface |
AcpAgent.SyncSetSessionModeHandler
Synchronous functional interface for handling set session mode requests.
|
static interface |
AcpAgent.SyncSetSessionModelHandler
Synchronous functional interface for handling set session model requests.
|
| 限定符和类型 | 字段和说明 |
|---|---|
static java.time.Duration |
DEFAULT_REQUEST_TIMEOUT
Default request timeout duration.
|
static org.slf4j.Logger |
logger |
static reactor.core.scheduler.Scheduler |
SYNC_HANDLER_SCHEDULER
Library-owned scheduler for executing synchronous handlers.
|
| 限定符和类型 | 方法和说明 |
|---|---|
static AcpAgent.AsyncAgentBuilder |
async(AcpAgentTransport transport)
Start building an asynchronous ACP agent with the specified transport layer.
|
static AcpAgent.SyncAgentBuilder |
sync(AcpAgentTransport transport)
Start building a synchronous ACP agent with the specified transport layer.
|
static final org.slf4j.Logger logger
static final java.time.Duration DEFAULT_REQUEST_TIMEOUT
static final reactor.core.scheduler.Scheduler SYNC_HANDLER_SCHEDULER
static AcpAgent.SyncAgentBuilder sync(AcpAgentTransport transport)
transport - The transport layer to use for communicationstatic AcpAgent.AsyncAgentBuilder async(AcpAgentTransport transport)
transport - The transport layer to use for communication