analyze

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: 24 Imported by: 0

Documentation

Overview

Package analyze contains the analyze-kind AI agent: operator- triggered, tool-using, single-incident investigation. The agent runs only via the admin endpoint `POST /api/admin/incidents/:id/analyze` and writes its output to the analyses storage blob — it never fans out to notification channels (that contract is enforced by the import-graph guard test).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildUserPrompt

func BuildUserPrompt(s core.AnalyzeIncidentSnapshot) string

BuildUserPrompt renders the snapshot as the first user message sent to the model. The tool catalog is attached via Eino's ToolInfo schema, not in the user message.

func ParseFinding

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

ParseFinding decodes the model's final assistant message into an AIFinding. Like the detect parser it tolerates leading prose and code fences. Analyze-specific fields (root_cause_hypotheses, evidence, related_pattern_ids, next_steps) are passed through because AIFinding already declares them.

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 analyze call. Exposed so the admin API can render it for operators.

Types

type Agent

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

Agent is the analyze-kind AIAgent. The investigation loop, tool fan-out, and per-call audit all run on Eino's pre-built ReAct agent (flow/agent/react). The struct binds the resolved per-task config, the ReAct agent (which already owns the tool-calling chat model plus a compose.ToolsNode — sequential by default, concurrent when analyze.parallel_tools is set), and an in-memory registry of the read-only tools (kept for introspection / allow-list assertions).

The struct deliberately has NO Emitter / Notifier / Sender / Dispatcher field. The import-graph guard test in agent_test.go asserts this so future edits cannot silently turn analyze into a notification path.

func New

func New(ctx context.Context, cfg config.AgentAIConfig, tools []core.AnalyzeTool, opts Options) (*Agent, error)

New constructs an analyze Agent. cfg must already be resolved for the analyze task (see config.AgentAIConfig.Resolve). Every tool in the supplied list is registered with the agent.

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. Rejects any non-AnalyzeTask.

type Options

type Options struct {
	HTTPClient *http.Client
	BaseURL    string
	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 agent once.
	// Ignored when ChatModel is set (a fixed override is never rebuilt).
	Runtime einowrap.RuntimeAI

	// ChatModel overrides the Eino tool-calling chat model. When
	// non-nil the agent skips dialing OpenAI; tests pass a fake. The
	// ReAct agent binds tools onto it via WithTools.
	ChatModel model.ToolCallingChatModel

	// ToolTimeout caps a single tool dispatch. Zero applies the built-in
	// defaultToolTimeout; a negative value disables the per-tool cap.
	ToolTimeout time.Duration

	// ParallelTools runs multiple tool calls emitted in one model turn
	// concurrently. False (the default) dispatches them sequentially.
	ParallelTools bool
}

Options is the constructor-side bag for test plumbing.

Directories

Path Synopsis
Package tools holds the read-only tool catalog exposed to the analyze-kind AI agent.
Package tools holds the read-only tool catalog exposed to the analyze-kind AI agent.

Jump to

Keyboard shortcuts

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