observation

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package observation defines host-facing runtime observation DTOs.

The event package exposes presentation-neutral runtime facts, and those facts may still be too low-level for a host UI or API response. Package observation projects selected engine events and narrow observation DTOs into stable, UI-neutral status records that a host can render without parsing assistant text, exposing prompt-cache storage records, or depending on internal test UI types.

Observation values are not raw debug records. They intentionally omit provider payloads, model deltas, reasoning, tool arguments, tool results, and local paths. Hosts that need raw local inspection should build that capability as an explicit privileged surface and continue to pass public sinks through event.Sanitize.

Index

Constants

View Source
const (
	CompactionStatusRunning   = "running"
	CompactionStatusCompacted = "compacted"
	CompactionStatusFailed    = "failed"
)
View Source
const (
	ContextPhaseProjectedRequest = "projected_request"
	ContextPhaseProviderUsage    = "provider_usage"
)

Variables

This section is empty.

Functions

func RequestID

func RequestID(runID string, step int) string

func SortContextStatuses

func SortContextStatuses(statuses []ContextStatus)

Types

type CompactionEvent

type CompactionEvent struct {
	RunID                   string                        `json:"run_id,omitempty"`
	SessionID               string                        `json:"session_id,omitempty"`
	TurnID                  string                        `json:"turn_id,omitempty"`
	Step                    int                           `json:"step,omitempty"`
	Phase                   string                        `json:"phase"`
	Status                  string                        `json:"status"`
	Trigger                 string                        `json:"trigger,omitempty"`
	Reason                  string                        `json:"reason,omitempty"`
	CompactionID            string                        `json:"compaction_id,omitempty"`
	CompactionGeneration    int                           `json:"compaction_generation,omitempty"`
	CompactionWindowID      string                        `json:"compaction_window_id,omitempty"`
	CompactedThroughEntryID string                        `json:"compacted_through_entry_id,omitempty"`
	TokensBefore            int64                         `json:"tokens_before,omitempty"`
	TokensAfterEstimate     int64                         `json:"tokens_after_estimate,omitempty"`
	BeforePressure          contextpolicy.ContextPressure `json:"before_pressure,omitempty"`
	ContextBefore           contextpolicy.Usage           `json:"context_before,omitempty"`
	ContextAfter            contextpolicy.Usage           `json:"context_after,omitempty"`
	Error                   string                        `json:"error,omitempty"`
	ObservedAt              time.Time                     `json:"observed_at"`
}

func CompactionEventFromEngineEvent

func CompactionEventFromEngineEvent(ev event.Event) (CompactionEvent, bool)

func CompactionEventsFromEngineEvents

func CompactionEventsFromEngineEvents(events []event.Event) []CompactionEvent

type ContextStatus

type ContextStatus struct {
	RunID                string                        `json:"run_id,omitempty"`
	SessionID            string                        `json:"session_id,omitempty"`
	TurnID               string                        `json:"turn_id,omitempty"`
	Step                 int                           `json:"step,omitempty"`
	RequestID            string                        `json:"request_id,omitempty"`
	LogicalRequestID     string                        `json:"logical_request_id,omitempty"`
	Attempt              int                           `json:"attempt,omitempty"`
	Phase                string                        `json:"phase"`
	Provider             string                        `json:"provider,omitempty"`
	Model                string                        `json:"model,omitempty"`
	ObservedAt           time.Time                     `json:"observed_at"`
	Usage                provider.Usage                `json:"usage,omitempty"`
	RequestEstimate      contextpolicy.RequestEstimate `json:"request_estimate,omitempty"`
	ContextPressure      contextpolicy.ContextPressure `json:"context_pressure,omitempty"`
	UsedRatio            float64                       `json:"used_ratio,omitempty"`
	ThresholdRatio       float64                       `json:"threshold_ratio,omitempty"`
	Status               string                        `json:"status"`
	CompactionGeneration int                           `json:"compaction_generation,omitempty"`
	CompactionWindowID   string                        `json:"compaction_window_id,omitempty"`
}

func ContextStatusFromProviderUsage

func ContextStatusFromProviderUsage(usage ProviderUsageObservation) (ContextStatus, bool)

func ContextStatusFromProviderUsageEvent

func ContextStatusFromProviderUsageEvent(ev event.Event) (ContextStatus, bool)

func ContextStatusFromRequest

func ContextStatusFromRequest(req RequestObservation) ContextStatus

func ContextStatusesFromObservations

func ContextStatusesFromObservations(requests []RequestObservation, usages []ProviderUsageObservation, events []event.Event) []ContextStatus

func ContextStatusesFromRequests

func ContextStatusesFromRequests(requests []RequestObservation, events []event.Event) []ContextStatus

func (ContextStatus) PhaseOrder

func (s ContextStatus) PhaseOrder() int

type ProviderUsageObservation

type ProviderUsageObservation struct {
	RunID                string                        `json:"run_id,omitempty"`
	SessionID            string                        `json:"session_id,omitempty"`
	TurnID               string                        `json:"turn_id,omitempty"`
	Step                 int                           `json:"step,omitempty"`
	RequestID            string                        `json:"request_id,omitempty"`
	LogicalRequestID     string                        `json:"logical_request_id,omitempty"`
	Attempt              int                           `json:"attempt,omitempty"`
	Provider             string                        `json:"provider,omitempty"`
	Model                string                        `json:"model,omitempty"`
	ObservedAt           time.Time                     `json:"observed_at"`
	Usage                provider.Usage                `json:"usage,omitempty"`
	RequestEstimate      contextpolicy.RequestEstimate `json:"request_estimate,omitempty"`
	ContextPressure      contextpolicy.ContextPressure `json:"context_pressure,omitempty"`
	CompactionGeneration int                           `json:"compaction_generation,omitempty"`
	CompactionWindowID   string                        `json:"compaction_window_id,omitempty"`
}

type RequestObservation

type RequestObservation struct {
	RunID                string                        `json:"run_id,omitempty"`
	SessionID            string                        `json:"session_id,omitempty"`
	TurnID               string                        `json:"turn_id,omitempty"`
	Step                 int                           `json:"step"`
	RequestID            string                        `json:"request_id,omitempty"`
	LogicalRequestID     string                        `json:"logical_request_id,omitempty"`
	Attempt              int                           `json:"attempt,omitempty"`
	Provider             string                        `json:"provider"`
	Model                string                        `json:"model"`
	ObservedAt           time.Time                     `json:"observed_at"`
	RequestEstimate      contextpolicy.RequestEstimate `json:"request_estimate,omitempty"`
	ProjectedPressure    contextpolicy.ContextPressure `json:"projected_context_pressure,omitempty"`
	CompactionGeneration int                           `json:"compaction_generation,omitempty"`
	CompactionWindowID   string                        `json:"compaction_window_id,omitempty"`
}

Jump to

Keyboard shortcuts

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