agui

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 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 WithToolResultProvider added in v1.3.8

func WithToolResultProvider(provider ToolResultProvider) AdapterOption

WithToolResultProvider sets a callback that supplies results for pending client tools. When configured, the adapter will suspend, call the provider, resolve each tool, then call Resume to continue the pipeline.

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 server-side tool call: ToolCallStartEvent, ToolCallArgsEvent, ToolCallEndEvent
  6. If pending client tools (and ToolResultProvider configured): a. ToolCallStart/Args/End for each pending tool b. CustomEvent("promptkit.client_tools_pending") c. Provider is called → ToolCallResult per resolved tool d. Resume → loop back to step 4
  7. TextMessageEndEvent
  8. RunFinishedEvent

On error, a RunErrorEvent is emitted instead of steps 3-8. 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)
	SendToolResult(ctx context.Context, callID string, result any) error
	RejectClientTool(ctx context.Context, callID, reason string)
	Resume(ctx context.Context) (*sdk.Response, error)
}

Sender abstracts the conversation methods needed by the adapter. 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.

type ToolResult added in v1.3.8

type ToolResult struct {
	CallID   string // must match PendingClientTool.CallID
	Result   any    // JSON-serializable; ignored when Rejected is true
	Rejected bool
	Reason   string // rejection reason (used when Rejected is true)
}

ToolResult carries the caller-provided outcome for a single client tool call.

type ToolResultProvider added in v1.3.8

type ToolResultProvider func(ctx context.Context, tools []sdk.PendingClientTool) ([]ToolResult, error)

ToolResultProvider is a callback the caller implements to supply results for pending client tools. The adapter calls it when the LLM response contains deferred client tools that need fulfillment before the pipeline can continue.

Jump to

Keyboard shortcuts

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