detect

package
v1.4.15 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package detect contains the detect-kind AI agent: cheap, tool-free, single-call classification of unknown / spiking log patterns. It is the production AIAgent the worker consumes; the router also exposes it to admin endpoints under task kind core.AITaskDetect.

Detect MUST stay tool-free. Tool wiring is reserved for the analyze-kind agent — letting detect call tools would turn every noisy log line into a multi-step LLM workflow.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPrompt

func BuildPrompt(r core.AgentResult, source, service string, samples []string) (system, user string)

BuildPrompt builds the (system, user) messages for a single AgentResult. Pure function: no I/O, no time. Easy to golden-test.

func ParseFinding

func ParseFinding(raw string) (*core.AIFinding, error)

ParseFinding accepts the model's reply and returns an AIFinding. Tolerates the most common deviations: leading/trailing prose, ```json fences, prepended "Here is the JSON:" preamble.

func PromptOrder

func PromptOrder() []string

PromptOrder returns the canonical fragment order so the admin endpoint can echo the list back to the UI alongside the assembled prompt.

func SystemPrompt

func SystemPrompt() string

SystemPrompt returns the assembled system prompt sent on every detect call. Exposed so the admin API can render it for operators.

Types

type Agent

type Agent struct {

	// SampleFn picks the lines forwarded to the model from an
	// AgentResult. Defaults to "first up to 3 non-empty messages".
	// Exposed so callers can swap in a redaction-aware extractor.
	SampleFn func(core.AgentResult) []string
	// contains filtered or unexported fields
}

Agent is the detect-kind AIAgent. It binds the resolved per-task config, the Eino chat model, and a sample extractor.

func New

func New(ctx context.Context, cfg config.AgentAIConfig, opts Options) (*Agent, error)

New constructs a detect Agent. cfg must already be resolved for the detect task (see config.AgentAIConfig.Resolve).

func (*Agent) ChatModel

func (a *Agent) ChatModel() model.BaseChatModel

ChatModel exposes the underlying Eino model. Only used by the tool-free guard test in agent_test.go. It returns the currently-built model from the holder (built eagerly in New); it never triggers a rebuild.

func (*Agent) Kind

func (a *Agent) Kind() core.AITaskKind

Kind implements core.AIAgent.

func (*Agent) Name

func (a *Agent) Name() string

Name implements core.AIAgent.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, task core.AITask) (*core.AICallResult, error)

Run implements core.AIAgent. It rejects any task that is not a DetectTask; the router enforces kind routing but we double-check.

type Options

type Options struct {
	// HTTPClient overrides the default *http.Client. Optional.
	HTTPClient *http.Client
	// BaseURL overrides the chat/completions endpoint. Tests use this
	// to point at an httptest server; production leaves it empty.
	BaseURL string
	// Timeout caps each chat call. Defaults to 30s.
	Timeout time.Duration
	// AuthKeyFunc is an OPTIONAL per-request Authorization override passed
	// straight to the chat model's transport. Nil (the OSS default) leaves
	// the YAML-keyed header untouched.
	AuthKeyFunc func(ctx context.Context) (key string, ok bool)

	// Runtime folds optional runtime overrides (provider / enabled / key
	// state) into the model holder's rebuild signature. The zero value (the
	// OSS default) pins the configured provider and builds the model once.
	Runtime einowrap.RuntimeAI
}

Options is the constructor-side bag for test plumbing. Production callers pass a zero Options{} and let the agent dial OpenAI directly.

Jump to

Keyboard shortcuts

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