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 ¶
- func MessageFromAGUI(msg *aguitypes.Message) types.Message
- func MessageToAGUI(msg *types.Message) aguitypes.Message
- func MessagesFromAGUI(msgs []aguitypes.Message) []types.Message
- func MessagesToAGUI(msgs []types.Message) []aguitypes.Message
- func ToolsFromAGUI(aguiTools []aguitypes.Tool) []*tools.ToolDescriptor
- func ToolsToAGUI(descs []tools.ToolDescriptor) []aguitypes.Tool
- type AdapterOption
- type EventAdapter
- type EventBusProvider
- type Sender
- type StateProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MessageFromAGUI ¶
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 ¶
MessageToAGUI converts a PromptKit Message to an AG-UI Message. It maps roles, content (text or multimodal), tool calls, and tool results.
func MessagesFromAGUI ¶
MessagesFromAGUI converts a slice of AG-UI Messages to PromptKit Messages.
func MessagesToAGUI ¶
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 ¶
RunSend sends a message through the conversation and emits AG-UI events.
Event sequence on success:
- RunStartedEvent
- StateSnapshotEvent (if StateProvider is configured)
- TextMessageStartEvent
- TextMessageContentEvent (full text in a single delta)
- For each tool call: ToolCallStartEvent, ToolCallArgsEvent, ToolCallEndEvent
- TextMessageEndEvent
- 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 ¶
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 ¶
StateProvider produces a state snapshot for the AG-UI StateSnapshotEvent.