agui

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package agui exposes Chronos runs as a standard AG-UI event stream, so any AG-UI-compatible frontend can render an agent run (steps, tool calls, plan updates, state snapshots, interrupts, completion) without Chronos-specific glue. It is a translation layer over the existing engine/stream broker and its per-session SSE routing — the native /api/events/stream is unchanged; this adds a standardized stream alongside it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(broker *stream.Broker) http.HandlerFunc

Handler returns an http.Handler that streams a session's run as AG-UI events over SSE. The session/thread id comes from the request query (see sessionParams); a client that omits it subscribes to the broker firehose (useful for a dashboard). Each Chronos broker event is translated to zero or more AG-UI events and written as `data: <json>` SSE frames, so an AG-UI-compatible frontend renders the run with no Chronos-specific glue.

Per-session routing, subscriber caps, and disconnect cleanup are inherited from the broker; a heartbeat keeps the connection alive.

Types

type Event

type Event struct {
	Type EventType `json:"type"`

	ThreadID string `json:"threadId,omitempty"`
	RunID    string `json:"runId,omitempty"`

	StepName string `json:"stepName,omitempty"`

	MessageID string `json:"messageId,omitempty"`
	Role      string `json:"role,omitempty"`

	ToolCallID   string `json:"toolCallId,omitempty"`
	ToolCallName string `json:"toolCallName,omitempty"`
	Delta        string `json:"delta,omitempty"`
	Content      string `json:"content,omitempty"`

	Snapshot any `json:"snapshot,omitempty"`

	// CUSTOM events carry a name and an arbitrary value.
	Name  string `json:"name,omitempty"`
	Value any    `json:"value,omitempty"`

	// RUN_ERROR carries a message.
	Message string `json:"message,omitempty"`
}

Event is one AG-UI protocol event. Fields are a superset across event types; only those relevant to Type are populated (the rest are omitted on the wire).

type EventType

type EventType string

EventType is an AG-UI protocol event type. The values follow the AG-UI convention (SCREAMING_SNAKE_CASE) so compatible frontends recognize them.

const (
	EventRunStarted       EventType = "RUN_STARTED"
	EventRunFinished      EventType = "RUN_FINISHED"
	EventRunError         EventType = "RUN_ERROR"
	EventStepStarted      EventType = "STEP_STARTED"
	EventStepFinished     EventType = "STEP_FINISHED"
	EventTextMessageStart EventType = "TEXT_MESSAGE_START"
	EventTextMessageChunk EventType = "TEXT_MESSAGE_CONTENT"
	EventTextMessageEnd   EventType = "TEXT_MESSAGE_END"
	EventToolCallStart    EventType = "TOOL_CALL_START"
	EventToolCallArgs     EventType = "TOOL_CALL_ARGS"
	EventToolCallEnd      EventType = "TOOL_CALL_END"
	EventToolCallResult   EventType = "TOOL_CALL_RESULT"
	EventStateSnapshot    EventType = "STATE_SNAPSHOT"
	EventCustom           EventType = "CUSTOM"
)

type Translator

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

Translator converts Chronos stream events into AG-UI events for one stream connection. It holds the per-connection state AG-UI needs: the thread/run ids and a monotonic tool-call id so TOOL_CALL_* events correlate. It is not safe for concurrent use; use one per SSE connection.

func NewTranslator

func NewTranslator(threadID, runID string) *Translator

NewTranslator creates a translator for a stream scoped to threadID (typically the session id). runID identifies this run within the thread.

func (*Translator) Start

func (t *Translator) Start() Event

Start returns the RUN_STARTED event that opens the stream. The handler emits it on connect (not lazily on the first Chronos event) so a client sees a live, well-formed lifecycle immediately, even before the run produces any event.

func (*Translator) Translate

func (t *Translator) Translate(evt stream.Event) []Event

Translate maps one Chronos stream event to zero or more AG-UI events. Unmapped Chronos events (e.g. edge transitions, raw model-call notifications) translate to nothing.

Jump to

Keyboard shortcuts

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