AG-UI-4K_README.md
A production-ready Kotlin Multiplatform client library for connecting applications to AI agents that implement the Agent User Interaction Protocol (AG-UI).
AG-UI-4K enables seamless integration with AI agents across all major platforms through a unified, type-safe API.
- True Multiplatform: Write once, run everywhere with platform-specific optimizations
- Modern Kotlin: Leveraging coroutines, flows, and the latest K2 compiler for exceptional performance
- π Real-time Streaming: Event-driven architecture with Kotlin Flows for live agent responses
- π‘οΈ Type Safety: Fully typed protocol implementation with compile-time guarantees
- β‘ High Performance: Optimized with K2 compiler and efficient state management
- π§ Extensible Tools: Comprehensive framework for extending agent capabilities
- π State Management: Automatic synchronization with JSON Patch support
- π Secure: Built-in authentication options (Bearer, API Key, Basic Auth)
- π¦ Modular Architecture: Clean separation between core, client, tools, and SDK layers
- π― Latest Tech Stack: Kotlin 2.1.21, Ktor 3.x, kotlinx.serialization 1.8.x
- π§ͺ Well Tested: Unit tests and Android-specific platform tests
- π Fully Documented: Extensive KDocs, example Chat App
Add the SDK to your project:
// For high-level agent interactions
dependencies {
implementation("com.contextable:agui4k-agent-sdk:0.2.1")
}
// For direct protocol access (advanced users)
dependencies {
implementation("com.contextable:agui4k-client:0.2.1")
implementation("com.contextable:agui4k-core:0.2.1")
}
import com.contextable.agui4k.sdk.*
import kotlinx.coroutines.flow.collect
// Create a stateless agent
val agent = AgUi4KAgent("https://your-agent-api.com/agent") {
bearerToken = "your-api-token"
systemPrompt = "You are a helpful AI assistant"
}
// Send a message and receive streaming responses
agent.sendMessage("What's the weather like?").collect { state ->
println("State updated: $state")
}
// Create a stateful agent that maintains conversation history
val chatAgent = StatefulAgUi4KAgent("https://your-agent-api.com/agent") {
bearerToken = "your-api-token"
systemPrompt = "You are a friendly conversational AI"
initialState = buildJsonObject {
put("userName", "Alice")
put("preferences", buildJsonObject {
put("language", "en")
})
}
}
// Have a conversation
chatAgent.chat("Hello!").collect { /* ... */ }
chatAgent.chat("What's my name?").collect { state ->
// Agent remembers the conversation context
}
// Create an agent with tools
val agent = agentWithTools(
url = "https://your-agent-api.com/agent",
toolRegistry = toolRegistry {
addTool(WeatherToolExecutor())
addTool(CalculatorToolExecutor())
addTool(ConfirmationToolExecutor(uiHandler))
}
) {
bearerToken = "your-api-token"
}
// Agent can now use tools during conversation
agent.sendMessage("What's 15% tip on $85.50?").collect { state ->
// Agent will use calculator tool automatically
}
AG-UI-4K follows a clean, modular architecture:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your Application β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β agui4k-agent-sdk β
β βββββββββββββββ βββββββββββββββββββββ ββββββββββββββββ β
β β AgUi4KAgent β βStatefulAgUi4KAgentβ β Builders β β
β βββββββββββββββ βββββββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β agui4k-client β agui4k-tools β
β ββββββββββββββ βββββββββββββββ β ββββββββββββββββββββββββ β
β β HttpAgent β βAbstractAgentβ β β ToolRegistry β β
β ββββββββββββββ€ βββββββββββββββ€ β ββββββββββββββββββββββββ€ β
β βEventVerifierβ βDefaultApply β β β ToolExecutor β β
β β SseParser β β Events β β βToolExecutionManager β β
β ββββββββββββββ βββββββββββββββ β ββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β agui4k-core β
β Protocol Types & Event Definitions β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- agui4k-core: Protocol definitions, event types, and message structures
- agui4k-client: Low-level client infrastructure and transport implementations
- agui4k-tools: Tool execution framework and built-in tool executors
- agui4k-agent-sdk: High-level APIs for common agent interaction patterns
Platform | Status | Minimum Version | Notes |
---|---|---|---|
Android | β Stable | API 26+ | Full feature support |
iOS | β Stable | iOS 13+ | Native performance (not tested beyond unit tests) |
JVM | β Stable | Java 11+ | Desktop |
- API Reference - Complete API documentation
- Chat Application - Basic chat client
- Tool Examples - Custom tool implementations
-
Clone the repository
git clone https://github.com/contextable/ag-ui-4k.git cd ag-ui-4k
-
Build the project
cd library ./gradlew build
-
Run tests
./gradlew test
-
Generate documentation
./gradlew dokkaHtml
AG-UI-4K | Kotlin | Ktor | AG-UI Protocol |
---|---|---|---|
0.2.x | 2.1.21+ | 3.1.x | 1.0 |
This project is licensed under the MIT License - see the LICENSE file for details.
- Built on the AG-UI Protocol specification
- Powered by Kotlin Multiplatform
- Networking by Ktor
- Serialization with kotlinx.serialization
- Issues: GitHub Issues