agui

package
v1.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package agui provides bidirectional converters between PromptKit internal types and the AG-UI Go SDK types, enabling interoperability between the two systems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MessageFromAGUI

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

MessageFromAGUI converts an AG-UI Message to a PromptKit Message. It maps roles, content (text or multimodal), tool calls, and tool call IDs.

func MessageToAGUI

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

MessageToAGUI converts a PromptKit Message to an AG-UI Message. It maps roles, content (text or multimodal), tool calls, and tool results.

func MessagesFromAGUI

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

MessagesFromAGUI converts a slice of AG-UI Messages to PromptKit Messages.

func MessagesToAGUI

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

MessagesToAGUI converts a slice of PromptKit Messages to AG-UI Messages.

func ToolsFromAGUI

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

ToolsFromAGUI converts a slice of AG-UI Tool definitions to PromptKit ToolDescriptors. Each tool's Parameters (JSON Schema as any) is marshaled to json.RawMessage for InputSchema.

func ToolsToAGUI

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

ToolsToAGUI converts a slice of PromptKit ToolDescriptors to AG-UI Tool definitions.

Types

type AdapterOption

type AdapterOption func(*adapterConfig)

AdapterOption configures an EventAdapter.

func WithRunID

func WithRunID(id string) AdapterOption

WithRunID sets the AG-UI run ID for emitted events.

func WithStateProvider

func WithStateProvider(sp StateProvider) AdapterOption

WithStateProvider sets a provider that produces state snapshots.

func WithThreadID

func WithThreadID(id string) AdapterOption

WithThreadID sets the AG-UI thread ID for emitted events.

func WithWorkflowSteps

func WithWorkflowSteps(enabled bool) AdapterOption

WithWorkflowSteps enables emission of StepStarted/StepFinished events for workflow state transitions observed on the event bus.

type EventAdapter

type EventAdapter struct {
	// contains filtered or unexported fields
}

EventAdapter bridges a PromptKit conversation to an AG-UI event channel. It calls Send on the underlying conversation and translates the response (and any event-bus tool-call events) into AG-UI protocol events.

func NewEventAdapter

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

NewEventAdapter creates a new EventAdapter for the given conversation. The conversation must implement both Sender and EventBusProvider. In practice, *sdk.Conversation satisfies both interfaces.

func (*EventAdapter) Events

func (a *EventAdapter) Events() <-chan aguievents.Event

Events returns the read-only channel of AG-UI events. The channel is closed after RunSend completes (either successfully or with an error).

func (*EventAdapter) RunID

func (a *EventAdapter) RunID() string

RunID returns the run ID used by this adapter.

func (*EventAdapter) RunSend

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

RunSend sends a message through the conversation and emits AG-UI events.

Event sequence on success:

  1. RunStartedEvent
  2. StateSnapshotEvent (if StateProvider is configured)
  3. TextMessageStartEvent
  4. TextMessageContentEvent (full text in a single delta)
  5. For each tool call: ToolCallStartEvent, ToolCallArgsEvent, ToolCallEndEvent
  6. TextMessageEndEvent
  7. RunFinishedEvent

On error, a RunErrorEvent is emitted instead of steps 3-7. The events channel is always closed when RunSend returns.

func (*EventAdapter) ThreadID

func (a *EventAdapter) ThreadID() string

ThreadID returns the thread ID used by this adapter.

type EventBusProvider

type EventBusProvider interface {
	EventBus() *events.EventBus
}

EventBusProvider abstracts access to the conversation's event bus.

type Sender

type Sender interface {
	Send(ctx context.Context, message any, opts ...sdk.SendOption) (*sdk.Response, error)
}

Sender abstracts the conversation Send method so the adapter can be tested without a real Conversation. In production code, *sdk.Conversation satisfies this interface.

type StateProvider

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

StateProvider produces a state snapshot for the AG-UI StateSnapshotEvent.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL