event

package
v0.95.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package event provides lifecycle event streaming for agent runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Type           Type
	Message        any
	ToolCall       any
	ToolResult     any
	ToolResults    any
	Messages       any
	TextDelta      string
	ReasoningDelta string
	Update         string
	// DurationMs is elapsed milliseconds for completed phases (turn, tool, thinking).
	DurationMs int64
	// Step is the 1-based agent turn index when Type is TypeTurnEnd.
	Step int
	Err  error
}

Event is a structured lifecycle notification for UI and harness consumers.

type Handler

type Handler func(Event) error

Handler processes agent lifecycle events sequentially.

type Result

type Result struct {
	Messages []any
	Err      error
}

Result is the final outcome of an agent run delivered through the stream.

type Stream

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

Stream multiplexes agent lifecycle events to subscribers and exposes the final result.

func NewStream

func NewStream(buffer int) *Stream

NewStream creates a buffered event stream for an agent run.

func (*Stream) Await

func (s *Stream) Await(ctx context.Context) (Result, error)

Await blocks until the stream ends and returns the final result. Multiple callers may Await the same stream; each receives an identical copy.

func (*Stream) End

func (s *Stream) End(messages []any, err error)

End closes the stream with the final message list and optional error.

func (*Stream) Events

func (s *Stream) Events() <-chan Event

Events exposes the read-only event channel.

func (*Stream) Push

func (s *Stream) Push(ctx context.Context, ev Event) error

Push emits an event to subscribers and the events channel.

func (*Stream) Subscribe

func (s *Stream) Subscribe(handler Handler)

Subscribe registers a handler invoked sequentially for each emitted event.

type Type

type Type string

Type identifies lifecycle events emitted by the agent loop.

const (
	TypeAgentStart          Type = "agent_start"
	TypeTurnStart           Type = "turn_start"
	TypeMessageStart        Type = "message_start"
	TypeMessageUpdate       Type = "message_update"
	TypeMessageEnd          Type = "message_end"
	TypeToolExecutionStart  Type = "tool_execution_start"
	TypeToolExecutionUpdate Type = "tool_execution_update"
	TypeToolExecutionEnd    Type = "tool_execution_end"
	TypeTurnEnd             Type = "turn_end"
	TypeAgentEnd            Type = "agent_end"
)

Jump to

Keyboard shortcuts

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