agui

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package agui implements the AG-UI protocol over Server-Sent Events without depending on a protocol SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func History

func History(input RunAgentInput) ([]*schema.Message, string, error)

History converts all messages except the final user prompt into Eino chat history, and returns the final prompt separately.

Types

type ContentPart

type ContentPart struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
	URL  string `json:"url,omitempty"`
}

ContentPart is one part of a multi-part message.

type Emitter

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

Emitter writes AG-UI events as SSE frames. It tracks open text and reasoning messages so the server can close them before starting another block or finishing the run.

func NewEmitter

func NewEmitter(w http.ResponseWriter, threadID, runID string, newID func(string) string, onError func()) (*Emitter, error)

NewEmitter starts an SSE response. onError is called once when the client connection can no longer be written to.

func (*Emitter) Err

func (e *Emitter) Err() error

Err reports the first transport error.

func (*Emitter) ReasoningContent

func (e *Emitter) ReasoningContent(delta string)

ReasoningContent appends a reasoning delta.

func (*Emitter) ReasoningEnd

func (e *Emitter) ReasoningEnd()

ReasoningEnd closes the reasoning block.

func (*Emitter) ReasoningStart

func (e *Emitter) ReasoningStart()

ReasoningStart opens a reasoning block.

func (*Emitter) RunError

func (e *Emitter) RunError(message string)

RunError reports a terminal failure.

func (*Emitter) RunFinishedInterrupt

func (e *Emitter) RunFinishedInterrupt(interrupts []Interrupt)

RunFinishedInterrupt terminates this connection's stream while leaving the run parked for a later resume.

func (*Emitter) RunFinishedSuccess

func (e *Emitter) RunFinishedSuccess()

RunFinishedSuccess terminates the run successfully.

func (*Emitter) RunStarted

func (e *Emitter) RunStarted()

RunStarted announces a run on this connection.

func (*Emitter) StateSnapshot

func (e *Emitter) StateSnapshot(snapshot map[string]any)

StateSnapshot publishes the current todo list as AG-UI state.

func (*Emitter) TextContent

func (e *Emitter) TextContent(delta string)

TextContent appends a text delta.

func (*Emitter) TextEnd

func (e *Emitter) TextEnd()

TextEnd closes the open text message.

func (*Emitter) TextStart

func (e *Emitter) TextStart() string

TextStart opens an assistant text message.

func (*Emitter) ToolResult

func (e *Emitter) ToolResult(callID, content string)

ToolResult reports the result of a tool call.

func (*Emitter) ToolStart

func (e *Emitter) ToolStart(callID, name, arguments, parentMessageID string)

ToolStart announces one tool call. Arguments are delivered as a single delta and the call block is closed immediately; the result may arrive after an interrupt and resume on another connection.

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

FunctionCall is the function name and JSON-encoded arguments.

type Interrupt

type Interrupt struct {
	ID             string         `json:"id"`
	Reason         string         `json:"reason"`
	Message        string         `json:"message,omitempty"`
	ToolCallID     string         `json:"toolCallId,omitempty"`
	ResponseSchema map[string]any `json:"responseSchema,omitempty"`
	ExpiresAt      string         `json:"expiresAt,omitempty"`
	Metadata       map[string]any `json:"metadata,omitempty"`
}

Interrupt asks the client for input before the run can continue.

type Message

type Message struct {
	ID         string          `json:"id,omitempty"`
	Role       string          `json:"role"`
	Content    json.RawMessage `json:"content,omitempty"`
	Name       string          `json:"name,omitempty"`
	ToolCalls  []ToolCall      `json:"toolCalls,omitempty"`
	ToolCallID string          `json:"toolCallId,omitempty"`
}

Message is one AG-UI chat message. Content is a string or a list of parts.

func (Message) Text

func (m Message) Text() string

Text returns the textual content of a message.

type Resume

type Resume struct {
	InterruptID string          `json:"interruptId"`
	Status      string          `json:"status"`
	Payload     json.RawMessage `json:"payload,omitempty"`
}

Resume answers one interrupt.

type RunAgentInput

type RunAgentInput struct {
	ThreadID       string          `json:"threadId"`
	RunID          string          `json:"runId"`
	Messages       []Message       `json:"messages"`
	Tools          []Tool          `json:"tools,omitempty"`
	Context        json.RawMessage `json:"context,omitempty"`
	State          json.RawMessage `json:"state,omitempty"`
	ForwardedProps map[string]any  `json:"forwardedProps,omitempty"`
	Resume         []Resume        `json:"resume,omitempty"`
}

RunAgentInput is the body of a POST /agui request.

type Server

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

Server serves an AG-UI endpoint backed by the shared runtime.

func New

func New(runner *runtime.Runner, defaultAgent string) (*Server, error)

New creates an AG-UI server.

func (*Server) Handler

func (s *Server) Handler(agentOverride string) http.Handler

Handler returns the AG-UI HTTP handler. agentOverride is used by /agents/{name}/agui routes and otherwise comes from forwardedProps.

type Tool

type Tool struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	Parameters  json.RawMessage `json:"parameters,omitempty"`
}

Tool describes a client-side tool. Oni3 uses its configured tools, so the list is accepted for compatibility and not registered with the model.

type ToolCall

type ToolCall struct {
	ID       string       `json:"id"`
	Type     string       `json:"type,omitempty"`
	Function FunctionCall `json:"function"`
}

ToolCall is an OpenAI-compatible assistant tool call.

Jump to

Keyboard shortcuts

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