liveclassify

package
v0.9.52 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IntentSteer         = "steer"
	IntentStatus        = "status"
	IntentNewSession    = "new_session"
	IntentSwitchSession = "switch_session"
	IntentSteerNow      = "steer_now"
	IntentSide          = "side"

	IntentQuestionID          = "intent"
	AlsoRequestQuestionID     = "also_request"
	UnambiguousStopQuestionID = "unambiguous_stop"

	IntentQuestionInstructions  = "" /* 175-byte string literal not displayed */
	AlsoRequestInstructions     = "" /* 175-byte string literal not displayed */
	UnambiguousStopInstructions = "Is this an unambiguous request to stop or cancel the currently running task now?"

	// MaxMessageRunes keeps pathological recognition tokens and skipped long
	// requests from producing unbounded diagnostic rows.
	MaxMessageRunes = 4096
	// MaxTranscriptRunes keeps the recent spoken context useful without allowing a
	// long call to make every classification request grow without bound.
	MaxTranscriptRunes = 4096
	// MaxRecentSessionTitles is enough context for references to the visible recent
	// directory while keeping the state independent of the size of the session DB.
	MaxRecentSessionTitles = 12
	// MaxSessionTitleRunes bounds each title copied into classification state.
	MaxSessionTitleRunes = 160
)

Variables

View Source
var ErrInvalidAnswer = errors.New("invalid live classify answer")

ErrInvalidAnswer identifies a response that arrived but did not satisfy the classifier's answer contract. Callers may safely record this category without persisting the provider's response body.

Functions

func Gate

func Gate(decision Decision, cfg GateConfig) string

Gate returns the label Phase 1 may act on. Unsupported future labels, low-confidence decisions, and mixed navigate-and-work requests all fail open to steer so the original utterance reaches the bound session unchanged.

func MarshalState

func MarshalState(state State) ([]byte, error)

MarshalState applies the state bounds and returns the exact JSON sent to the classification provider and, when enabled, the decision log.

func Questions

func Questions() map[string]typesafe.Question

Questions returns a fresh map because callers and HTTP test servers may retain or mutate request values.

Types

type Classifier

type Classifier struct {
	Client Client
	Model  string
}

Classifier performs one stateless TypeSafe classification.

func (*Classifier) Classify

func (c *Classifier) Classify(ctx context.Context, state State) (Decision, error)

Classify sends the bounded state and validates all answers needed by both Phase 1 and the Phase 2 decision-log measurements.

type Client

type Client interface {
	Classify(context.Context, typesafe.Request) (*typesafe.Response, error)
}

Client is the subset of typesafe.Client used by the live classifier.

type Decision

type Decision struct {
	Intent           string             `json:"intent"`
	Probabilities    map[string]float64 `json:"probabilities"`
	AlsoRequest      float64            `json:"also_request"`
	UnambiguousStop  float64            `json:"unambiguous_stop"`
	Model            string             `json:"model,omitempty"`
	InputTokens      *int               `json:"input_tokens,omitempty"`
	OutputTokens     *int               `json:"output_tokens,omitempty"`
	BoundedStateJSON json.RawMessage    `json:"-"`
}

Decision is the validated classifier output used by Gate.

type DecisionRecord

type DecisionRecord struct {
	ID              int64              `json:"id"`
	CreatedAt       time.Time          `json:"created_at"`
	LiveID          string             `json:"live_id"`
	BoundSession    string             `json:"bound_session"`
	StateJSON       json.RawMessage    `json:"state,omitempty"`
	Probabilities   map[string]float64 `json:"probabilities"`
	GatedLabel      string             `json:"gated_label"`
	ActedLabel      string             `json:"acted_label"`
	ResolverOutcome string             `json:"resolver_outcome,omitempty"`
	Latency         time.Duration      `json:"latency"`
	Error           string             `json:"error,omitempty"`
}

DecisionRecord is one privacy-sensitive live classification audit row.

type DecisionStore

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

DecisionStore persists live routing diagnostics independently of transcripts. Writes are accepted through a bounded queue so diagnostics can never hold the serial live routing worker open.

func OpenDecisionStore

func OpenDecisionStore(path string) (*DecisionStore, error)

OpenDecisionStore opens and initializes the live diagnostics database.

func OpenDecisionStoreReadOnly

func OpenDecisionStoreReadOnly(path string) (*DecisionStore, error)

OpenDecisionStoreReadOnly opens an existing diagnostics database without creating the file, its directory, or its schema.

func (*DecisionStore) Close

func (s *DecisionStore) Close() error

Close drains queued writes for a bounded period and then closes the database.

func (*DecisionStore) Dropped

func (s *DecisionStore) Dropped() uint64

Dropped reports how many records could not enter the bounded writer queue.

func (*DecisionStore) Enqueue

func (s *DecisionStore) Enqueue(record DecisionRecord) bool

Enqueue hands a decision to the diagnostics writer without waiting for disk. It returns false when the bounded queue is full or the store is closing.

func (*DecisionStore) List

func (s *DecisionStore) List(ctx context.Context, since time.Time, limit int) ([]DecisionRecord, error)

List returns newest decisions at or after since. A zero time lists all rows.

type GateConfig

type GateConfig struct {
	Status        float64
	NewSession    float64
	SwitchSession float64
	SteerNow      float64
	Side          float64
}

GateConfig contains the confidence thresholds used by the pure Phase 1 gate.

type State

type State struct {
	Message             string   `json:"message"`
	TranscriptDelta     string   `json:"transcript_delta"`
	ActiveRun           bool     `json:"active_run"`
	ActiveTool          string   `json:"active_tool"`
	CurrentSessionTitle string   `json:"current_session_title"`
	RecentSessionTitles []string `json:"recent_session_titles"`
}

State is the bounded, transport-independent context classified for one live delegation.

func (State) Bounded

func (s State) Bounded() State

Bounded returns a copy safe to persist and send to the classifier.

Jump to

Keyboard shortcuts

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