intent

package
v0.53.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package intent is the vocabulary of a Slack reply's second reading (spec SI3, SI4): the closed nine intents, the schema check that turns a model's answer into one of them or into unknown, and the span rule that lets the model choose what to quote but never write it. It does no I/O: the one model call is model.go's, and who may be classified is the broker's.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalid is a gateway reply that is not the shape the call asks for, or too large.
	ErrInvalid = errors.New("classifier_invalid")
	// ErrUnavailable is a gateway that could not be reached, refused, or could not authenticate us.
	ErrUnavailable = errors.New("classifier_unavailable")
	// ErrTimeout is the call outliving its deadline.
	ErrTimeout = errors.New("classifier_timeout")
)

The sentinels the caller maps to its closed outcomes: ErrTimeout to `timeout`, ErrInvalid to `invalid_output`, ErrUnavailable to `error`. Each carries its detail after the colon; the detail never holds the reply.

All is the nine, in the order the schema lists them.

View Source
var Phases = []string{"queued", "running", "waiting-you", "waiting-other", "waiting-pr", "waiting", "done", "failed", "stopped", "unknown"}

Phases is the closed list of words a thread's phase may be sent as (SI3): the kinds of summary.StatusLine, which the App reads from the one room_summary it makes, and "unknown" for a room whose status that summary cannot name. The classifier reads no room; the broker refuses any other word, so a caller cannot smuggle text in through the phase.

Functions

func Parse

func Parse(raw []byte, reply string, minConfidence float64) (Result, Outcome)

Parse reads the model's raw answer against reply. Anything that is not the closed shape, names an intent outside the nine or carries a confidence outside 0 to 1 is Unknown with OutcomeInvalidOutput; a confidence under minConfidence is Unknown with OutcomeLowConfidence. Steer and amend keep the span of reply the model quoted (Span), every other intent drops its text.

func Span

func Span(reply, text string) string

Span is what a steer or an amend acts on: text if it is a contiguous span of reply once case and whitespace are folded, returned as the reply spelled it; otherwise, an empty text included, the whole reply. The model chooses what to quote and never writes it (SI4).

func TextHash

func TextHash(text string) string

TextHash is the value the confirm binds to: "sha256:" and the hex of the span's SHA-256.

func ValidPhase

func ValidPhase(p string) bool

ValidPhase reports whether p is one of Phases.

Types

type Intent

type Intent string

Intent is one of the nine labels a reply can carry.

const (
	Status  Intent = "status"
	Needs   Intent = "needs"
	Changes Intent = "changes"
	PR      Intent = "pr"
	Steer   Intent = "steer"
	Amend   Intent = "amend"
	Stop    Intent = "stop"
	Retry   Intent = "retry"
	Unknown Intent = "unknown"
)

The closed vocabulary. A model answer outside it is Unknown with OutcomeInvalidOutput.

func (Intent) Valid

func (i Intent) Valid() bool

Valid reports whether i is one of the nine.

func (Intent) Write

func (i Intent) Write() bool

Write reports whether the intent acts on a task once confirmed: stop, retry, steer and amend. The rest are reads or nothing.

type Model

type Model struct {
	// URL is the gateway's base route (`human.slackIntents.url`); the call is appended to it.
	URL string
	// Alias is the one model alias the classifier may name.
	Alias string
	// KeyFile holds the `classifier` client's key, read at use so a rotation needs no restart.
	KeyFile string
	// Deadline bounds the call. Zero means five seconds.
	Deadline time.Duration
	// HC is the audited egress client (`httpx.New`). A nil client makes no call.
	HC *http.Client
}

Model is the one bounded `chat/completions` call: the gateway's route, the pinned alias, the key file read at use, the audited egress client and a deadline. It holds no state and shares nothing with the planner's client but httpx: a planner change must not move the classifier.

func (Model) Classify

func (m Model) Classify(ctx context.Context, reply, phase string) ([]byte, Usage, error)

Classify makes the one call: the reply and the thread's phase as one JSON user message, no history, one attempt. It returns the model's answer as raw bytes for Parse, which decides what it means; an answer outside the closed shape is Parse's `invalid_output`, not an error here.

type Outcome

type Outcome string

Outcome is how a classification ended, as maku_intent_classify_total{outcome} counts it.

const (
	OutcomeOK            Outcome = "ok"
	OutcomeLowConfidence Outcome = "low_confidence"
	OutcomeInvalidOutput Outcome = "invalid_output"
	OutcomeTimeout       Outcome = "timeout"
	OutcomeCapped        Outcome = "capped"
	OutcomeError         Outcome = "error"
)

The outcomes Parse decides; the caller adds timeout, capped and error.

type Result

type Result struct {
	Intent     Intent
	Text       string
	Confidence float64
}

Result is a classification: the label, the span of the reply it acts on (steer and amend only) and the model's confidence.

type Usage

type Usage struct {
	Model            string
	PromptTokens     int
	CompletionTokens int
}

Usage is what the call cost, from the reply's own `usage`: a reply without it is refused, since the spend of the App's `classifier` client has to be attributable.

Jump to

Keyboard shortcuts

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