Help us shape the future of Go! Take the 2026 Go Developer Survey

event

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package event is the vocabulary of a running loop: every event type and payload. It is a leaf (it imports nothing from loop), so the public API and every internal package can share it without an import cycle.

Index

Constants

View Source
const (
	ReflectOnIteration = "on_iteration"
	ReflectOnFinish    = "on_finish"
)

Reflection modes, as ReflectionData.Mode reports them.

Variables

This section is empty.

Functions

This section is empty.

Types

type AwaitingInputData

type AwaitingInputData struct {
	Question string   `json:"question"`
	Options  []string `json:"options,omitempty"`
	Payload  any      `json:"payload,omitempty"`
}

AwaitingInputData is the payload a pause handler emits with AwaitingInput. Payload carries anything else the caller's UI needs.

func (AwaitingInputData) Type

func (AwaitingInputData) Type() Type

type Data

type Data interface {
	Type() Type
}

Data is an event payload. Each payload names its own Type, so a payload can never be sent under another type's label.

type DoneData

type DoneData struct {
	Reason       DoneReason `json:"reason"`
	Iterations   int        `json:"iterations"`
	FinalContent string     `json:"final_content,omitempty"`
	// Error is the fatal error message when Reason is ReasonError.
	Error string `json:"error,omitempty"`
	// Awaiting is set when Reason is ReasonAwaitingHuman.
	Awaiting *AwaitingInputData `json:"awaiting,omitempty"`
	// DroppedEvents counts intermediate events dropped because the event
	// channel was full.
	DroppedEvents int             `json:"dropped_events,omitempty"`
	LLMUsage      LLMUsageSummary `json:"llm_usage"`
}

DoneData is the payload of Done, emitted exactly once per run.

func (DoneData) Type

func (DoneData) Type() Type

type DoneReason

type DoneReason string

DoneReason says why the loop ended.

const (
	// ReasonFinished is normal completion.
	ReasonFinished DoneReason = "finished"
	// ReasonStopped means a stop signal or a cancelled wait ended the run.
	ReasonStopped DoneReason = "stopped"
	// ReasonMaxIterations means the iteration cap was reached.
	ReasonMaxIterations DoneReason = "max_iterations"
	// ReasonTimeout means TotalTimeout passed or the context was cancelled.
	ReasonTimeout DoneReason = "timeout"
	// ReasonError means a fatal error ended the run.
	ReasonError DoneReason = "error"
	// ReasonAwaitingHuman means a pause handler ended the run to wait for a
	// person; the caller resumes later with a new loop.
	ReasonAwaitingHuman DoneReason = "awaiting_human"
)

type ErrorData

type ErrorData struct {
	Error string `json:"error"`
	Fatal bool   `json:"fatal"`
}

ErrorData is the payload of Error.

func (ErrorData) Type

func (ErrorData) Type() Type

type Event

type Event struct {
	Type      Type      `json:"type"`
	Data      Data      `json:"data"`
	Iteration int       `json:"iteration"`
	Timestamp time.Time `json:"timestamp"`
}

Event is one update from a running loop. Type always equals Data.Type(); it is kept for JSON readers, which cannot see the payload's Go type.

func New

func New(data Data, iteration int) Event

New builds the event for data, labelled with data's own Type.

type LLMTurnData

type LLMTurnData struct {
	TurnIndex              int     `json:"turn_index"`
	InputTokens            int     `json:"input_tokens"`
	OutputTokens           int     `json:"output_tokens"`
	CostAmount             float64 `json:"cost_amount"`
	Provider               string  `json:"provider,omitempty"`
	Model                  string  `json:"model,omitempty"`
	DurationMs             int64   `json:"duration_ms"`
	RequestMessagesJSON    []byte  `json:"request_messages_json,omitempty"`
	ResponseKind           string  `json:"response_kind"`
	AssistantContent       string  `json:"assistant_content,omitempty"`
	AssistantToolCallsJSON []byte  `json:"assistant_tool_calls_json,omitempty"`
	MaxIterations          int     `json:"max_iterations,omitempty"`
	StopCondition          string  `json:"stop_condition,omitempty"`
}

LLMTurnData is the payload of LLMTurn.

func (LLMTurnData) Type

func (LLMTurnData) Type() Type

type LLMUsageSummary

type LLMUsageSummary struct {
	InputTokens  int    `json:"input_tokens"`
	OutputTokens int    `json:"output_tokens"`
	TotalTokens  int    `json:"total_tokens"`
	Model        string `json:"model,omitempty"`
}

LLMUsageSummary totals token use over a run. TotalTokens is input plus output, plus any totals a provider reported without a split.

type ProgressData

type ProgressData struct {
	Message string `json:"message"`
	Step    string `json:"step,omitempty"`
}

ProgressData is the payload of Progress.

func (ProgressData) Type

func (ProgressData) Type() Type

type ReflectionData

type ReflectionData struct {
	Mode       string  `json:"mode"`
	Verdict    string  `json:"verdict"`
	Reason     string  `json:"reason"`
	Hint       string  `json:"hint,omitempty"`
	Confidence float64 `json:"confidence"`
}

ReflectionData is the payload of Reflection: one judge's verdict.

func (ReflectionData) Type

func (ReflectionData) Type() Type

type ResponseData

type ResponseData struct {
	Content string `json:"content"`
}

ResponseData is the payload of Response.

func (ResponseData) Type

func (ResponseData) Type() Type

type ThinkingData

type ThinkingData struct {
	Message string `json:"message"`
}

ThinkingData is the payload of Thinking.

func (ThinkingData) Type

func (ThinkingData) Type() Type

type ToolCallData

type ToolCallData struct {
	ToolCallID string `json:"tool_call_id"`
	Name       string `json:"name"`
	Arguments  string `json:"arguments"`
}

ToolCallData is the payload of ToolCall.

func (ToolCallData) Type

func (ToolCallData) Type() Type

type ToolResultData

type ToolResultData struct {
	ToolCallID string `json:"tool_call_id"`
	Name       string `json:"name"`
	Result     string `json:"result"`
	Error      string `json:"error,omitempty"`
	DurationMs int64  `json:"duration_ms,omitempty"`
}

ToolResultData is the payload of ToolResult.

func (ToolResultData) Type

func (ToolResultData) Type() Type

type Type

type Type string

Type classifies an event.

const (
	// Thinking is emitted before each model call.
	Thinking Type = "thinking"
	// ToolCall is emitted when the model asks for a tool, before it runs.
	ToolCall Type = "tool_call"
	// ToolResult is emitted when a tool finishes, with its result or error.
	ToolResult Type = "tool_result"
	// Response is emitted when the model replies with text and no tool call.
	Response Type = "response"
	// Reflection is emitted for the optional self-review reply.
	Reflection Type = "reflection"
	// Progress is a human-readable status message.
	Progress Type = "progress"
	// Error reports a failure. ErrorData.Fatal says whether the loop stopped.
	Error Type = "error"
	// Done is the last event. DoneData.Reason says why the loop ended.
	Done Type = "done"
	// LLMTurn is the audit record of one model call that led to tool calls.
	LLMTurn Type = "llm_turn"
	// AwaitingInput is emitted by a pause handler waiting for a reply. The
	// loop has not ended.
	AwaitingInput Type = "awaiting_input"
)

Jump to

Keyboard shortcuts

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