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 ¶
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.
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 ¶
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" )
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 ¶
NewRecorder builds a recorder. redactPaths name bindings whose values must not appear in the trace; clock supplies timestamps so tests are deterministic.
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) MarshalJSON ¶
MarshalJSON renders the trace as the documented wire shape.
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.