Skip to main content

AbstractAgent

AbstractAgent is the base class that provides the foundation for implementing custom agent connectivity patterns. It defines the core contract and common functionality that all agent implementations must follow, making it the starting point for building specialized agent types.

Overview

AbstractAgent provides:
  • Core HTTP client configuration and management
  • Authentication handling
  • Request/response lifecycle hooks
  • Common utility methods
  • Standardized error handling patterns

Usage

Creating Custom Agent Types

Specialized Agent Implementation

Configuration

AbstractAgent uses AgUiAgentConfig for configuration:

Core Methods

Abstract Methods

run

Must be implemented by subclasses to define request execution:
Parameters:
  • input: Complete AG-UI protocol input
Returns: Flow<BaseEvent> - Stream of protocol events

Protected Properties

httpClient

Pre-configured HTTP client with authentication:

config

Access to agent configuration:

agentUrl

The configured agent endpoint URL:

Utility Methods

generateId

Generate unique IDs for messages and runs:

generateRunId

Generate unique run identifiers:

HTTP Client Configuration

AbstractAgent automatically configures the HTTP client with:

Authentication

Based on config, sets up:
  • Bearer token authentication
  • API key authentication
  • Basic authentication
  • Custom authentication providers

Platform-Specific Engines

  • Android: ktor-client-android
  • iOS: ktor-client-darwin
  • JVM: ktor-client-cio

Content Negotiation

  • JSON serialization with kotlinx.serialization
  • Automatic request/response handling

Logging

Optional request/response logging when config.debug = true

Common Implementation Patterns

Request Preprocessing

Event Filtering

Response Transformation

Error Handling

Best Practices

Configuration Validation

Resource Management

Thread Safety