trace

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 3 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

Overview

Package trace holds Verdict's execution trace: the record of which decisions fired, what they were given, what they produced, and how they decided.

The trace is a deliverable, not a debug artifact. It is what dashboards visualise, what auditors read, and what the Nexus event bus republishes for live observability, so its shape is a stable, documented JSON contract rather than an internal representation.

Index

Constants

View Source
const (
	AnnHitPolicy    = "hit_policy"
	AnnAggregation  = "aggregation"
	AnnMatchedRules = "matched_rules"
	AnnRuleCount    = "rule_count"
	AnnInputValues  = "input_values"
	AnnDefaulted    = "defaulted"
	AnnSessionRef   = "agent_session_ref"
	AnnPrompt       = "agent_prompt"
	AnnAttempts     = "agent_attempts"
	AnnTokens       = "agent_tokens"
	AnnFallbackUsed = "fallback_used"
	AnnFallbackFrom = "fallback_from"
	AnnCacheHit     = "cache_hit"
	AnnError        = "error"
	AnnRedacted     = "redacted"
	AnnBKM          = "invoked_bkm"
	AnnParameters   = "parameters"
)

Annotation keys used by the engine. They are exported because consumers key off them: a dashboard reads AnnHitPolicy to render a table's decision, and the Nexus bridge reads AnnSessionRef to link a trace node to a session.

View Source
const RedactedMarker = redactedMarker

RedactedMarker is the value substituted for a redacted binding.

Variables

This section is empty.

Functions

This section is empty.

Types

type InputSetter

type InputSetter interface {
	SetInputs(map[string]any)
	SetName(string)
}

InputSetter is implemented by writers that can record node inputs. The agent bridge interface hands out a plain Writer, so this is a narrowing assertion used inside the engine.

type Mode

type Mode string

Mode selects how much of an evaluation is recorded.

const (
	// Off records nothing. Result.Trace is nil.
	Off Mode = "off"
	// Summary records the node graph, timings and outputs, but not the inputs
	// each node received nor per-node annotations beyond the essentials.
	Summary Mode = "summary"
	// Full records everything, including node inputs and hit-policy detail.
	Full Mode = "full"
)

func ParseMode

func ParseMode(s string) (Mode, bool)

ParseMode maps a configuration string onto a Mode, defaulting to Full.

type Node

type Node struct {
	DecisionID   string         `json:"decision_id"`
	DecisionName string         `json:"decision_name,omitempty"`
	NodeKind     string         `json:"node_kind"`
	Inputs       map[string]any `json:"inputs,omitempty"`
	Output       any            `json:"output,omitempty"`
	Children     []*Node        `json:"children,omitempty"`
	Annotations  map[string]any `json:"annotations,omitempty"`
	StartedAt    time.Time      `json:"started_at"`
	Duration     time.Duration  `json:"duration_ns"`

	// Error is set when the node failed. A failed node is still recorded: the
	// trace of a failed evaluation is the most valuable one there is.
	Error string `json:"error,omitempty"`
}

Node is one step of an evaluation. Nodes nest: a decision's node has children for the decisions it required and for any BKM it invoked.

type Recorder

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

Recorder builds a Trace. It is safe for concurrent use so that independent decisions evaluated in parallel can record into the same trace.

func NewRecorder

func NewRecorder(mode Mode, redactPaths []string, clock func() time.Time) *Recorder

NewRecorder builds a recorder. redactPaths name bindings whose values must not appear in the trace; clock supplies timestamps so tests are deterministic.

func (*Recorder) Begin

func (r *Recorder) Begin(decisionID, decisionName, nodeKind string) (Writer, func(any, error))

Begin opens the root node and returns its writer plus a finish function.

func (*Recorder) Mode

func (r *Recorder) Mode() Mode

Mode reports the recorder's mode.

func (*Recorder) Trace

func (r *Recorder) Trace(modelID, modelHash, entry string, startedAt time.Time) *Trace

Trace materialises the recorded trace.

type Trace

type Trace struct {
	ModelID   string        `json:"model_id"`
	ModelHash string        `json:"model_hash,omitempty"`
	Entry     string        `json:"entry,omitempty"`
	Root      *Node         `json:"root"`
	StartedAt time.Time     `json:"started_at"`
	Duration  time.Duration `json:"duration_ns"`
}

Trace is the root of an evaluation record.

func (*Trace) Find

func (t *Trace) Find(decisionID string) *Node

Find returns the first node for a decision ID, or nil.

func (*Trace) MarshalJSON

func (t *Trace) MarshalJSON() ([]byte, error)

MarshalJSON renders the trace as the documented wire shape.

func (*Trace) Walk

func (t *Trace) Walk(fn func(*Node))

Walk visits every node depth-first, parents before children.

type Writer

type Writer interface {
	// Annotate attaches a key to the node currently being recorded.
	Annotate(key string, value any)
	// Child opens a nested node and returns a writer for it. Call the returned
	// finish function when the child completes.
	Child(decisionID, nodeKind string) (Writer, func(output any, err error))
	// Enabled reports whether anything is being recorded, so an expensive
	// annotation can be skipped when tracing is off.
	Enabled() bool
}

Writer is the interface a node evaluator uses to contribute to the trace. It is handed to agent bridges so an agent can record its own reasoning steps without knowing anything about Verdict's internals.

Jump to

Keyboard shortcuts

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