Skip to main content

HttpAgent

HttpAgent is a low-level HTTP transport implementation that provides direct control over AG-UI protocol communication. It handles the core HTTP communication, Server-Sent Events (SSE) parsing, and event verification, serving as the foundation for higher-level agent implementations.

Usage Scenarios

Custom Agent Implementation

Build custom agent behavior on top of the HTTP transport:

Protocol-Level Access

Direct access to AG-UI protocol events:

Configuration

HttpAgent uses the same configuration as other agents:

Methods

run

Execute an AG-UI protocol request:
Parameters:
  • input: Complete AG-UI protocol input with messages, state, tools, etc.
Returns: Flow<BaseEvent> - Stream of protocol events Example:

Event Processing

Raw Protocol Events

HttpAgent emits all AG-UI protocol events:

Event Verification

HttpAgent includes automatic event verification:

HTTP Transport Details

Server-Sent Events (SSE)

HttpAgent uses SSE for real-time streaming:
  • Automatic connection management
  • Reconnection on connection loss
  • Proper SSE event parsing
  • Content-Type: text/event-stream

Request Format

POST requests to /agent endpoint with:

Platform HTTP Engines

  • Android: Uses ktor-client-android (OkHttp under the hood)
  • iOS: Uses ktor-client-darwin (NSURLSession under the hood)
  • JVM: Uses ktor-client-cio

Error Handling

Network Errors

Automatic Retries

Advanced Usage

Custom Event Processing Pipeline

State Management Integration

Thread Safety

HttpAgent is thread-safe and can handle concurrent requests:

Performance Considerations

Connection Reuse

Large Responses

Best Practices

Input Validation

Error Recovery

Resource Management