Skip to content

AG-UI Integration Reference

API reference for the sdk/agui package, which provides converters and an event adapter for bridging PromptKit conversations to the AG-UI protocol.


import "github.com/AltairaLabs/PromptKit/sdk/agui"

Dependency: This package requires the AG-UI Go community SDK:

github.com/ag-ui-protocol/ag-ui/sdks/community/go

Functions for converting between PromptKit types.Message and AG-UI types.Message.

func MessageToAGUI(msg *types.Message) aguitypes.Message

Converts a PromptKit message to an AG-UI message. Maps roles, content (text or multimodal), tool calls, and tool results.

func MessageFromAGUI(msg *aguitypes.Message) types.Message

Converts an AG-UI message to a PromptKit message. The inverse of MessageToAGUI.

func MessagesToAGUI(msgs []types.Message) []aguitypes.Message

Batch converts a slice of PromptKit messages to AG-UI messages.

func MessagesFromAGUI(msgs []aguitypes.Message) []types.Message

Batch converts a slice of AG-UI messages to PromptKit messages.


func ToolsToAGUI(descs []tools.ToolDescriptor) []aguitypes.Tool

Converts PromptKit tool descriptors to AG-UI tool definitions. Use this to expose PromptKit tools to AG-UI frontends.

func ToolsFromAGUI(aguiTools []aguitypes.Tool) []*tools.ToolDescriptor

Converts AG-UI tool definitions to PromptKit tool descriptors. Use this to pass frontend-defined tools into a PromptKit conversation.


The EventAdapter observes a PromptKit conversation and emits AG-UI events on a channel. It handles the translation from PromptKit’s internal event model to the AG-UI SSE event stream.

func NewEventAdapter(conv interface {
Sender
EventBusProvider
}, opts ...AdapterOption) *EventAdapter

Creates a new event adapter bound to a conversation. In practice, *sdk.Conversation satisfies both Sender and EventBusProvider. The adapter does not start emitting events until RunSend is called.

Parameters:

ParameterDescription
convThe PromptKit conversation (must implement Sender and EventBusProvider)
optsFunctional options (see below)
func (a *EventAdapter) Events() <-chan aguievents.Event

Returns a read-only channel of AG-UI events. The channel is closed when the run completes (either successfully or with an error). Consumers should range over this channel to receive all events.

func (a *EventAdapter) RunSend(ctx context.Context, msg *types.Message) error

Executes a conversation turn with the given message and emits AG-UI events as the conversation progresses. This method blocks until the turn completes. Typically called in a goroutine so the caller can simultaneously read from Events().

The event sequence for a successful run:

  1. RunStartedEvent
  2. TextMessageStartEvent (per assistant message)
  3. TextMessageContentEvent (per text chunk)
  4. TextMessageEndEvent
  5. RunFinishedEvent

If the agent invokes tools, tool call events are interleaved:

  1. ToolCallStartEvent
  2. ToolCallArgsEvent (streamed argument chunks)
  3. ToolCallEndEvent
  4. ToolCallResultEvent

If an error occurs at any point, a RunErrorEvent is emitted and the channel is closed.


OptionSignatureDescription
WithThreadIDWithThreadID(id string) AdapterOptionSets the thread ID included in lifecycle events.
WithRunIDWithRunID(id string) AdapterOptionSets the run ID included in lifecycle events.
WithStateProviderWithStateProvider(sp StateProvider) AdapterOptionAttaches a state provider for emitting STATE_SNAPSHOT events at run start.
WithWorkflowStepsWithWorkflowSteps(enabled bool) AdapterOptionEnables emission of STEP_STARTED/STEP_FINISHED events for workflow state transitions observed on the event bus.

type StateProvider interface {
Snapshot(sender Sender) (any, error)
}

Interface for providing state snapshots to the frontend. Called at the start of each run to emit a STATE_SNAPSHOT event.

MethodDescription
Snapshot(sender)Returns the current state snapshot. The Sender is provided so the state provider can query the conversation if needed.

Complete mapping from PromptKit conversation activity to AG-UI events:

PromptKit ActivityAG-UI EventFields
Send startsRunStartedEventthreadId, runId
Text response beginsTextMessageStartEventmessageId, role
Text token streamedTextMessageContentEventmessageId, delta
Text response endsTextMessageEndEventmessageId
Tool call initiatedToolCallStartEventtoolCallId, toolCallName
Tool arguments streamedToolCallArgsEventtoolCallId, delta
Tool call completeToolCallEndEventtoolCallId
Tool result returnedToolCallResultEventtoolCallId, result
Workflow step beginsStepStartedEventstepName
Workflow step endsStepFinishedEventstepName
Send completesRunFinishedEventthreadId, runId
Error occursRunErrorEventmessage