Documentation for encoding Agent User Interaction Protocol events
EventEncoder
class provides the functionality to
encode events into a format that can be sent over HTTP.
from ag_ui.encoder import EventEncoder
The EventEncoder
class is responsible for encoding BaseEvent
objects into
string representations that can be transmitted to clients.
EventEncoder
is typically used in HTTP handlers to convert event objects
into a stream of data. The current implementation encodes events as Server-Sent
Events (SSE), which can be consumed by clients using the EventSource API.
__init__(accept: str = None)
Parameter | Type | Description |
---|---|---|
accept | str (optional) | Content type accepted by the client |
encode(event: BaseEvent) -> str
Parameter | Type | Description |
---|---|---|
event | BaseEvent | The event to encode |