What is ACP?
The Agent Client Protocol is a standardized protocol that enables AI agents to communicate with client applications through a consistent interface. ACP provides:- Bidirectional Communication: Agents receive prompts and send real-time updates
- Event Streaming: Real-time tool call status, reasoning, and progress updates
- Session Management: Lifecycle management with session IDs
- Status Reporting: Comprehensive tool call and execution status
- Real-time Updates: Stream events as the agent executes
- Progress Tracking: Monitor tool calls, reasoning, and completion status
- Client Integration: Standard protocol for connecting agents to UIs and applications
- Session State: Manage long-running agent sessions with full lifecycle support
Installation
Add the ACP integration dependency:gradle
ACP is currently available only on the JVM platform.
Quick Start
Implement an ACP-enabled agent session:agents/agents-features/agents-features-acp/Module.md:43
Configuration
AcpAgent Feature
Install the AcpAgent feature in your agent:Configuration Options
| Property | Type | Required | Description |
|---|---|---|---|
sessionId | String | Yes | Unique session identifier |
protocol | Protocol | Yes | Protocol instance for sending requests |
eventsProducer | ProducerScope<Event> | Yes | Coroutine scope for sending events |
setDefaultNotifications | Boolean | No | Enable automatic notification handlers (default: true) |
Default Notification Handlers
WhensetDefaultNotifications is enabled, AcpAgent automatically handles:
1. Agent Completion
SendsPromptResponseEvent with StopReason.END_TURN when the agent completes successfully.
2. Agent Execution Failures
SendsPromptResponseEvent with appropriate stop reasons:
StopReason.MAX_TURN_REQUESTSfor max iterations exceededStopReason.REFUSALfor other execution failures
3. LLM Responses
Converts and sends LLM responses as ACP events (text, tool calls, reasoning).4. Tool Call Lifecycle
Reports tool call status changes:ToolCallStatus.IN_PROGRESSwhen a tool call startsToolCallStatus.COMPLETEDwhen a tool call succeedsToolCallStatus.FAILEDwhen a tool call fails
agents/agents-features/agents-features-acp/src/jvmMain/kotlin/ai/koog/agents/features/acp/AcpAgent.kt:180
Message Conversion
The ACP integration provides utilities for converting between Koog and ACP message formats:ACP to Koog
Convert ACP content blocks to Koog messages:Koog to ACP
Convert Koog messages to ACP events:agents/agents-features/agents-features-acp/Module.md:148
Supported Content Types
The ACP integration supports the following content types:- Text: Plain text content
- Image: Image data with MIME type
- Audio: Audio data with MIME type
- File: File attachments (embedded or linked)
- Base64-encoded binary data
- Plain text data
- URL references
- Resource: Embedded resources with URI and content
- Resource Link: Links to external resources
Sending Custom Events
Access the ACP feature to send custom events:agents/agents-features/agents-features-acp/Module.md:134
Complete Example
Here’s a complete implementation with proper session management:Implementation Notes
- Use channelFlow: Allows sending events from different coroutines
- Enable Default Notifications: Set
setDefaultNotifications = truefor automatic event handling - Convert Messages: Use
toKoogMessage()to convert ACP content blocks to Koog messages - Separate Coroutine: Run the agent in a separate coroutine for proper cancellation
- Mutex Synchronization: Use mutex to prevent concurrent prompt executions
agents/agents-features/agents-features-acp/Module.md:94
Core Components
AcpAgent
The main feature class for ACP integration:- Manages session lifecycle
- Sends events to ACP clients
- Handles automatic notifications
- Intercepts agent execution events
agents/agents-features/agents-features-acp/src/jvmMain/kotlin/ai/koog/agents/features/acp/AcpAgent.kt:40
MessageConverters
Utilities for converting between Koog and ACP message formats:toKoogMessage(): Convert ACP content to Koog messagestoAcpEvents(): Convert Koog responses to ACP eventstoKoogContentPart(): Convert individual content blockstoAcpContentBlock(): Convert individual content parts
agents/agents-features/agents-features-acp/src/jvmMain/kotlin/ai/koog/agents/features/acp/MessageConverters.kt
Event Types
PromptResponseEvent
Sent when agent completes or encounters an error:SessionUpdateEvent
Sent for tool calls and session updates:Platform Support
- JVM: Full support
- JS: Not supported (ACP Kotlin SDK is JVM-specific)
- Native: Not supported
Common Use Cases
- Web UIs: Connect agents to React/Vue frontends
- Mobile Apps: Real-time agent updates in mobile applications
- IDE Integration: Agent communication in development tools
- CLI Tools: Interactive command-line agents with progress reporting
- Microservices: Agent-to-service communication in distributed systems
Best Practices
- Use Mutex: Synchronize agent execution to prevent concurrent prompts
- Handle Cancellation: Properly cancel agent jobs when sessions end
- Error Handling: Catch and report errors through ACP events
- Event Ordering: Ensure events are sent in the correct sequence
- Resource Cleanup: Close channels and release resources on session end
Examples
Complete working examples are available in the repository:examples/simple-examples/src/main/kotlin/ai/koog/agents/example/acp/
Next Steps
- Learn about Model Context Protocol for tool integration
- Explore Spring Boot integration for enterprise applications
- See Ktor integration for web services
- Check out complete examples