mod_ai_intent

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 24 Imported by: ? 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

Index

Constants

View Source
const (
	DefaultTimeoutMs            = 300
	DefaultMaxStateChars        = 2000
	DefaultCacheSize            = 10000
	DefaultCacheTTLSeconds      = 1800
	DefaultExplicitIntentHeader = "X-AI-Intent"
	DefaultFailureThreshold     = 5
	DefaultProbeIntervalMs      = 5000
)

default values for optional configuration items

View Source
const (
	QuestionTypeChoice = bfe_basic.IntentQTypeChoice
	QuestionTypeScore  = bfe_basic.IntentQTypeScore
)

question types (kept in sync with bfe_basic.IntentQType*)

View Source
const (
	DefaultMinConfidence = 0.6
)
View Source
const ModAiIntent = "mod_ai_intent"

Variables

This section is empty.

Functions

func ConfModAiIntentCheck

func ConfModAiIntentCheck(cfg *ConfModAiIntent, confRoot string) error

func ExtractLastUserMessage

func ExtractLastUserMessage(body []byte, protocol string) (string, error)

ExtractLastUserMessage extracts the last user message from an AI request body of the given protocol (openai / anthropic / gemini). Unknown protocols are parsed tolerantly in openai format.

Types

type ConfModAiIntent

type ConfModAiIntent struct {
	Basic struct {
		DecisionServiceAddr  string // decision service address (System One protocol)
		QuestionsPath        string // path for intent questions data file
		TimeoutMs            int    // per classification timeout (ms)
		MaxStateChars        int    // rune truncation length of the classified text
		CacheSize            int    // max entries of in-process LRU cache
		CacheTTLSeconds      int    // TTL of cache entries (s)
		ExplicitIntentHeader string // request header for explicit intent declaration
	}
	Breaker struct {
		FailureThreshold int // consecutive failures before breaker opens
		ProbeIntervalMs  int // probe interval while breaker is open (ms)
	}
	Log struct {
		OpenDebug bool
	}
}

func ConfLoad

func ConfLoad(filePath string, confRoot string) (*ConfModAiIntent, error)

func (*ConfModAiIntent) Check

func (cfg *ConfModAiIntent) Check(confRoot string) error

type DecisionClient

type DecisionClient interface {
	// Classify returns the answers by question name and the backend
	// version string. Any error (timeout, 5xx, malformed response) is
	// reported to the caller, which degrades to unknown answers.
	Classify(ctx context.Context, state string, qs *IntentQuestions) (map[string]*bfe_basic.IntentAnswer, string, error)
}

DecisionClient classifies a state text against the configured questions via the System One protocol.

func NewDecisionClient

func NewDecisionClient(addr string, timeoutMs int) DecisionClient

type IntentCache

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

IntentCache is a process-wide LRU cache with TTL for classification results. Self-implemented (map + list), no third-party dependency.

func NewIntentCache

func NewIntentCache(capacity int, ttl time.Duration) *IntentCache

func (*IntentCache) Enabled

func (c *IntentCache) Enabled() bool

Enabled reports whether the cache stores anything.

func (*IntentCache) Get

func (c *IntentCache) Get(key string) *bfe_basic.AiIntent

func (*IntentCache) Len

func (c *IntentCache) Len() int

Len returns the current number of live entries (expired ones excluded).

func (*IntentCache) Set

func (c *IntentCache) Set(key string, v *bfe_basic.AiIntent)

type IntentQuestion

type IntentQuestion struct {
	Name          string
	Type          string
	Instructions  string
	Criteria      map[string]string // choice: option name -> description
	LevelNames    []string          // score: level names, ordered low to high
	LevelDescs    []string          // score: level descriptions, ordered low to high
	MinConfidence float64           // per-question gate, noConfidenceOverride to inherit
}

IntentQuestion is the runtime representation of a question.

func (*IntentQuestion) HasOption

func (q *IntentQuestion) HasOption(option string) bool

HasOption reports whether option is a valid option/level name of the question.

type IntentQuestions

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

IntentQuestions is the runtime, immutable snapshot of the questions conf. It is swapped atomically on hot reload, so readers never see a partial conf.

func (*IntentQuestions) OrderedQuestions

func (qs *IntentQuestions) OrderedQuestions() []*IntentQuestion

OrderedQuestions returns questions in file order (stable request assembly).

func (*IntentQuestions) Question

func (qs *IntentQuestions) Question(name string) (*IntentQuestion, bool)

func (*IntentQuestions) SystemOneQuestions

func (qs *IntentQuestions) SystemOneQuestions() map[string]interface{}

SystemOneQuestions assembles the questions field of the decision service request: choice questions carry a name->description criteria map; score questions carry the ordered level descriptions.

func (*IntentQuestions) Threshold

func (qs *IntentQuestions) Threshold(question string) float64

Threshold returns the current effective confidence gate of a question: per-question override, then the global gate. Unconfigured questions get 0, i.e. only the presence of an answer is required.

func (*IntentQuestions) Version

func (qs *IntentQuestions) Version() string

type ModuleAiIntent

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

func NewModuleAiIntent

func NewModuleAiIntent() *ModuleAiIntent

func (*ModuleAiIntent) Init

func (*ModuleAiIntent) Name

func (m *ModuleAiIntent) Name() string

type ModuleAiIntentState

type ModuleAiIntentState struct {
	ReqTotal         *metrics.Counter // total resolve triggered by intent conditions
	ReqResolved      *metrics.Counter // resolves with usable answers (header/cache/model)
	ReqHeader        *metrics.Counter // resolves using explicit intent header entries
	ReqCacheHit      *metrics.Counter // resolves served from in-process cache
	ReqUnknown       *metrics.Counter // resolves degraded to unknown (non-AI request, extract failure)
	ReqErr           *metrics.Counter // resolves failed on decision service (error / breaker open)
	BreakerOpen      *metrics.Counter // times the circuit breaker opened
	QuestionsVersion *metrics.State   // current version of the questions conf
}

type QuestionFile

type QuestionFile struct {
	Name          string            `json:"Name"`
	Type          string            `json:"Type"`
	Instructions  string            `json:"Instructions"`
	Criteria      map[string]string `json:"Criteria"` // choice options: name -> description
	Levels        []QuestionLevel   `json:"Levels"`   // score levels, ordered low to high
	MinConfidence *float64          `json:"MinConfidence"`
}

QuestionFile is the JSON DTO of a single question in intent_questions.data.

type QuestionLevel

type QuestionLevel struct {
	Name        string `json:"Name"`
	Description string `json:"Description"`
}

QuestionLevel is one level of a score question, ordered low to high.

type QuestionsConf

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

QuestionsConf holds the current questions conf snapshot with atomic replacement, plus its source path for hot reload.

func NewQuestionsConf

func NewQuestionsConf(path string) *QuestionsConf

func (*QuestionsConf) Current

func (qc *QuestionsConf) Current() *IntentQuestions

func (*QuestionsConf) Load

func (qc *QuestionsConf) Load(path ...string) error

Load reloads the questions conf from the file (or from path if given, which also becomes the new source path of the conf). The new conf is validated first; a hot reload with an unchanged Version is a no-op.

func (*QuestionsConf) Path

func (qc *QuestionsConf) Path() string

func (*QuestionsConf) Threshold

func (qc *QuestionsConf) Threshold(question string) float64

Threshold returns the current effective confidence gate of a question.

type QuestionsFile

type QuestionsFile struct {
	Version       string         `json:"Version"`
	MinConfidence *float64       `json:"MinConfidence"`
	Questions     []QuestionFile `json:"Questions"`
}

QuestionsFile is the JSON DTO of intent_questions.data.

Jump to

Keyboard shortcuts

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