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
- func CheckOrder(evs []Event) error
- func CheckOrderJSON(raw []json.RawMessage) error
- func IsTerminal(eventType string) bool
- type Event
- func CustomEvent(name string, value any) Event
- func New(eventType string, fields map[string]any) Event
- func RunErrorEvent(code, message string) Event
- func RunFinishedEvent(threadID, runID, outcome string, usage []Usage) Event
- func RunInterruptedEvent(threadID, runID string, interrupts []Interrupt, usage []Usage) Event
- func RunStartedEvent(threadID, runID string) Event
- func StateSnapshotEvent(snapshot map[string]any) Event
- func SteerEvent(id, text string, delivered bool) Event
- func SteerEventBy(id, text string, delivered bool, author, kind, onBehalfOf string) Event
- func SubagentEvent(value map[string]any) Event
- type Interrupt
- type Usage
Constants ¶
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.
const ( CustomToolOutput = "work.tool_output" CustomSteer = "work.steer" CustomUsage = "work.usage" CustomSubagent = "work.subagent" )
Custom event names.
const ( SubagentStart = "start" SubagentStep = "step" SubagentTool = "tool" SubagentText = "text" SubagentEnd = "end" )
Phases of a work.subagent event.
const ( CodeModelError = "model_error" CodeInterrupted = "interrupted" CodeMaxSteps = "max_steps" CodeInternal = "internal" )
RUN_ERROR codes.
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.
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 ¶
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 ¶
IsTerminal reports whether the event ends a run stream.
Types ¶
type Event ¶
Event is an AG-UI event; "type" is always set, "timestamp" is added by the event log.
func CustomEvent ¶
CustomEvent builds a CUSTOM event.
func RunFinishedEvent ¶
RunFinishedEvent builds RUN_FINISHED with outcome success|cancelled.
func RunInterruptedEvent ¶
RunInterruptedEvent builds RUN_FINISHED with outcome interrupt (the run waits for the user).
func RunStartedEvent ¶
RunStartedEvent builds RUN_STARTED.
func StateSnapshotEvent ¶
StateSnapshotEvent builds STATE_SNAPSHOT.
func SteerEvent ¶
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 ¶
SteerEventBy is SteerEvent with the author of the steer.
func SubagentEvent ¶
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}.
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.