stream

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package stream provides event streaming for real-time observability.

Index

Constants

View Source
const (
	EventNodeStart      = "node_start"
	EventNodeEnd        = "node_end"
	EventEdgeTransition = "edge_transition"
	EventToolCall       = "tool_call"
	EventToolResult     = "tool_result"
	EventModelCall      = "model_call"
	EventModelResponse  = "model_response"
	EventCheckpoint     = "checkpoint"
	EventInterrupt      = "interrupt"
	EventCompleted      = "completed"
	EventError          = "error"
	EventCustom         = "custom"
)

Standard event types published during graph and agent execution.

Variables

This section is empty.

Functions

func Emit added in v0.3.0

func Emit(ctx context.Context, eventType string, data any)

Emit sends a custom event from within a node function or tool handler. It is a no-op if no emitter is attached to the context.

func WithEmitter added in v0.3.0

func WithEmitter(ctx context.Context, ch chan<- Event) context.Context

WithEmitter adds an event emitter channel to the context, allowing node functions and tool handlers to emit custom events during execution.

Types

type Broker

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

Broker manages SSE subscribers.

func NewBroker

func NewBroker() *Broker

NewBroker creates a new event broker.

func (*Broker) Publish

func (b *Broker) Publish(evt Event)

Publish sends an event to all subscribers.

func (*Broker) SSEHandler

func (b *Broker) SSEHandler(subscriptionID string) http.HandlerFunc

SSEHandler returns an HTTP handler that streams events to the client.

func (*Broker) Subscribe

func (b *Broker) Subscribe(id string) <-chan Event

Subscribe creates a new subscription channel.

func (*Broker) Unsubscribe

func (b *Broker) Unsubscribe(id string)

Unsubscribe removes a subscription.

type Event

type Event struct {
	Type string `json:"type"`
	Data any    `json:"data"`
}

Event is a server-sent event.

type StreamConfig added in v0.3.0

type StreamConfig struct {
	Mode StreamMode
}

StreamConfig holds configuration for how events are filtered and delivered.

func DefaultStreamConfig added in v0.3.0

func DefaultStreamConfig() StreamConfig

DefaultStreamConfig returns a config that streams all events (debug mode).

func (StreamConfig) ShouldInclude added in v0.3.0

func (c StreamConfig) ShouldInclude(eventType string) bool

ShouldInclude returns true if the given event type passes the mode's filter. ModeDebug includes all events.

type StreamMode added in v0.3.0

type StreamMode string

StreamMode defines which events are included in a stream subscription.

const (
	// ModeValues streams full state after each node execution.
	ModeValues StreamMode = "values"
	// ModeUpdates streams only changed state keys after each node.
	ModeUpdates StreamMode = "updates"
	// ModeCustom streams only user-emitted custom events.
	ModeCustom StreamMode = "custom"
	// ModeMessages streams LLM token-level events (model_call, model_response).
	ModeMessages StreamMode = "messages"
	// ModeDebug streams all internal execution details.
	ModeDebug StreamMode = "debug"
)

Jump to

Keyboard shortcuts

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