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
- type ToolResult
- type ToolResultProvider
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 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 ¶
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 server-side tool call: ToolCallStartEvent, ToolCallArgsEvent, ToolCallEndEvent
- 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
- TextMessageEndEvent
- 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 ¶
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 ¶
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.