agui

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agui is the event vocabulary a run streams to its front ends: the AG-UI events (run, step, text, reasoning, tool call, interrupt and custom events), the usage record, the error codes, and the checks that a recorded stream is well ordered.

An Event is a JSON object (map[string]any) with a "type". The constructors build the events an agent emits, and CheckOrder verifies a stream: a text message ends before the next tool call starts, and a run ends with exactly one terminal event.

Index

Constants

View Source
const (
	RunStarted              = "RUN_STARTED"
	RunFinished             = "RUN_FINISHED"
	RunError                = "RUN_ERROR"
	StepStarted             = "STEP_STARTED"
	StepFinished            = "STEP_FINISHED"
	ReasoningStart          = "REASONING_START"
	ReasoningEnd            = "REASONING_END"
	ReasoningMessageStart   = "REASONING_MESSAGE_START"
	ReasoningMessageContent = "REASONING_MESSAGE_CONTENT"
	ReasoningMessageEnd     = "REASONING_MESSAGE_END"
	TextMessageStart        = "TEXT_MESSAGE_START"
	TextMessageContent      = "TEXT_MESSAGE_CONTENT"
	TextMessageEnd          = "TEXT_MESSAGE_END"
	ToolCallStart           = "TOOL_CALL_START"
	ToolCallArgs            = "TOOL_CALL_ARGS"
	ToolCallEnd             = "TOOL_CALL_END"
	ToolCallResult          = "TOOL_CALL_RESULT"
	Custom                  = "CUSTOM"
)

Event type names.

View Source
const (
	CustomToolOutput = "work.tool_output"
	CustomSteer      = "work.steer"
	CustomUsage      = "work.usage"
	CustomSubagent   = "work.subagent"
)

Custom event names.

View Source
const (
	SubagentStart = "start"
	SubagentStep  = "step"
	SubagentTool  = "tool"
	SubagentText  = "text"
	SubagentEnd   = "end"
)

Phases of a work.subagent event.

View Source
const (
	CodeModelError  = "model_error"
	CodeInterrupted = "interrupted"
	CodeMaxSteps    = "max_steps"
	CodeInternal    = "internal"
)

RUN_ERROR codes.

View Source
const (
	StateSnapshot = "STATE_SNAPSHOT"

	CustomCompaction = "work.compaction"
	CustomTitle      = "work.title"
	CustomGoal       = "work.goal"
	CustomMemory     = "work.memory"
	CustomApproval   = "work.approval"
)

Harness v2 event types and names.

View Source
const (
	// CodeModelTimeout: the model call (connect, first chunk, or a gap of
	// LLM_STREAM_IDLE_SECONDS between chunks) exceeded its budget after retries.
	CodeModelTimeout = "model_timeout"
	// CodeEmptyAnswer: no text and no tool call twice in a row (after one nudge); refusals count as empty.
	CodeEmptyAnswer = "empty_answer"
	// CodeContentFilter: the provider stopped the answer (finish_reason=content_filter).
	CodeContentFilter = "content_filter"
	// CodeRateLimited: 429 retries exhausted.
	CodeRateLimited = "rate_limited"

	// CustomRetry precedes a new attempt of a model call: {attempt, reason}.
	CustomRetry = "work.retry"
)

Harness v3 §1 (loop & context): RUN_ERROR codes and CUSTOM names.

Variables

This section is empty.

Functions

func CheckOrder

func CheckOrder(evs []Event) error

CheckOrder verifies the AG-UI order of one run's event log, as strict clients (AG-UI HttpAgent's verifier) do: RUN_STARTED first and only once; at most one terminal event (RUN_FINISHED/RUN_ERROR), and nothing after it; every *_START closed by its *_END with the same id (steps, text and reasoning messages, tool calls), content/args only inside an open span, and nothing open at RUN_FINISHED. A log without a terminal event (run in progress) is valid when what it holds is ordered.

func CheckOrderJSON

func CheckOrderJSON(raw []json.RawMessage) error

CheckOrderJSON is CheckOrder over raw event JSON (store.Event.Data, SSE data).

func IsTerminal

func IsTerminal(eventType string) bool

IsTerminal reports whether the event ends a run stream.

Types

type Event

type Event map[string]any

Event is an AG-UI event; "type" is always set, "timestamp" is added by the event log.

func CustomEvent

func CustomEvent(name string, value any) Event

CustomEvent builds a CUSTOM event.

func New

func New(eventType string, fields map[string]any) Event

New builds an event of the given type with the given fields.

func RunErrorEvent

func RunErrorEvent(code, message string) Event

RunErrorEvent builds RUN_ERROR.

func RunFinishedEvent

func RunFinishedEvent(threadID, runID, outcome string, usage []Usage) Event

RunFinishedEvent builds RUN_FINISHED with outcome success|cancelled.

func RunInterruptedEvent

func RunInterruptedEvent(threadID, runID string, interrupts []Interrupt, usage []Usage) Event

RunInterruptedEvent builds RUN_FINISHED with outcome interrupt (the run waits for the user).

func RunStartedEvent

func RunStartedEvent(threadID, runID string) Event

RunStartedEvent builds RUN_STARTED.

func StateSnapshotEvent

func StateSnapshotEvent(snapshot map[string]any) Event

StateSnapshotEvent builds STATE_SNAPSHOT.

func SteerEvent

func SteerEvent(id, text string, delivered bool) Event

SteerEvent announces a steer: delivered=true when the model of this run got it, false when it was kept in the thread for the next run instead.

func SteerEventBy

func SteerEventBy(id, text string, delivered bool, author, kind, onBehalfOf string) Event

SteerEventBy is SteerEvent with the author of the steer.

func SubagentEvent

func SubagentEvent(value map[string]any) Event

SubagentEvent builds the CUSTOM work.subagent event of a tool that runs a sub-agent: value carries toolCallId, phase (SubagentStart…SubagentEnd), agent, step, tool{name,args,result,isError}, text, model and usage{in,out,cached}.

func (Event) Type

func (e Event) Type() string

Type returns the event type.

type Interrupt

type Interrupt struct {
	ID             string         `json:"id"`
	Reason         string         `json:"reason"`
	Message        string         `json:"message"`
	ToolCallID     string         `json:"toolCallId"`
	ResponseSchema map[string]any `json:"responseSchema"`
	// Approval is the pending approval record (reason tool_approval).
	Approval map[string]any `json:"approval,omitempty"`
}

Interrupt is one AG-UI 1.0 interrupt of a RUN_FINISHED{outcome: interrupt}.

type Usage

type Usage struct {
	Model           string `json:"model"`
	InputTokens     int    `json:"inputTokens"`
	OutputTokens    int    `json:"outputTokens"`
	TotalTokens     int    `json:"totalTokens"`
	ReasoningTokens int    `json:"reasoningTokens"`
	// CachedInputTokens are input tokens served from the provider's prompt cache (0 when not reported).
	CachedInputTokens int `json:"cachedInputTokens"`
}

Usage is the per-model token usage reported in RUN_FINISHED.

Jump to

Keyboard shortcuts

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