signals

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package signals is the unified, graph-attached signal model - the single row type that every observability dimension lands on.

AgentProvenance observes sandboxed agent execution along two pillars over one causality graph - behavior and quality/security - plus cost as a cross-cutting dimension that feeds both. Historically each dimension had its own storage silo (risk_signals, baseline_deviations, cost_samples, and a Python-only EvalSignal export). This package collapses them into one `signals` table keyed to the same graph, so consumers (collectors, evaluators, policies, audit) build against one contract instead of N silos.

Index

Constants

View Source
const SchemaVersion = "agentprovenance.signals/v1"

SchemaVersion identifies the unified signal wire format. It is the versioned contract external collectors, evaluators, policies, and auditors build against. Bump it only with a documented migration.

Variables

This section is empty.

Functions

func Backfill

func Backfill(db *sql.DB) (int, error)

Backfill projects every legacy silo into the unified model and returns the total number of rows projected. Safe to run repeatedly (idempotent).

func Counts

func Counts(db *sql.DB, runID string) (map[Dimension]int, error)

Counts returns the number of signals per dimension for a run.

func ProjectBaselineDeviations

func ProjectBaselineDeviations(db *sql.DB) (int, error)

ProjectBaselineDeviations projects the baseline silo into the unified model. Deviations are security signals (deviation-from-expected-norm).

func ProjectCostSamples

func ProjectCostSamples(db *sql.DB) (int, error)

ProjectCostSamples projects the system-side resource-attribution rows (cost_samples) into the unified model under the Cost dimension. This is the only cost that rides the correlation graph; app-side token/$ cost is deliberately out of scope.

func ProjectRiskSignals

func ProjectRiskSignals(db *sql.DB) (int, error)

ProjectRiskSignals projects the security silo (risk_signals) into the unified model under the Security dimension.

func Record

func Record(db *sql.DB, s Signal) (string, error)

Record validates and persists a single signal. It fills in id, confidence, created_at, and JSON defaults when unset. Records projected from a legacy silo (SourceTable+SourceID set) are idempotent: re-projecting the same source row is a no-op rather than a duplicate.

func RecordCounting

func RecordCounting(db *sql.DB, s Signal) (bool, error)

RecordCounting persists a signal and reports whether a new row was inserted (false when an idempotent projection/import hit an existing source row).

func ValidateSet

func ValidateSet(set SignalSet) error

ValidateSet checks a SignalSet envelope: schema version, count/counts consistency, and every signal.

func ValidateSignal

func ValidateSignal(s Signal) error

ValidateSignal checks a single signal against the contract invariants.

Types

type Dimension

type Dimension string

Dimension is the observability lens a signal belongs to.

const (
	// Behavior is the factual substrate (what happened, who caused it).
	Behavior Dimension = "behavior"
	// Cost is the cross-cutting resource/economic dimension (not a peer pillar).
	Cost Dimension = "cost"
	// Quality scores task success / reward.
	Quality Dimension = "quality"
	// Security scores safety-policy / baseline deviation.
	Security Dimension = "security"
)

func (Dimension) Valid

func (d Dimension) Valid() bool

Valid reports whether d is one of the four known dimensions.

type Filter

type Filter struct {
	RunID        string
	Dimension    Dimension
	GraphRefKind string
	GraphRefID   string
	ProcessID    string
}

Filter narrows a Query. Empty fields are ignored.

type Signal

type Signal struct {
	ID                string    `json:"id"`
	Dimension         Dimension `json:"dimension"`
	Type              string    `json:"type"`
	GraphRefKind      string    `json:"graph_ref_kind"`
	GraphRefID        string    `json:"graph_ref_id"`
	RunID             string    `json:"run_id"`
	SessionID         string    `json:"session_id,omitempty"`
	ToolCallID        string    `json:"tool_call_id,omitempty"`
	ProcessID         string    `json:"process_id,omitempty"`
	EventID           string    `json:"event_id,omitempty"`
	ObjectRef         string    `json:"object_ref,omitempty"`
	Severity          string    `json:"severity,omitempty"` // security/risk only
	Label             string    `json:"label,omitempty"`    // categorical tag (e.g. quality pass/reject)
	Value             float64   `json:"value"`
	Reference         string    `json:"reference,omitempty"`
	Confidence        float64   `json:"confidence"`
	RecommendedAction string    `json:"recommended_action,omitempty"`
	ProducedBy        string    `json:"produced_by"`
	EvidenceRefs      string    `json:"evidence_refs"` // JSON array; defaults to "[]"
	Payload           string    `json:"payload"`       // JSON object; defaults to "{}"
	SourceTable       string    `json:"source_table,omitempty"`
	SourceID          string    `json:"source_id,omitempty"`
	CreatedAt         string    `json:"created_at"`
}

Signal is one graph-attached observation. The graph reference fields locate the node/edge this signal annotates; the scoring fields carry the judgment. JSON tags define the stable wire form; keep them and SchemaVersion in sync.

func Query

func Query(db *sql.DB, f Filter) ([]Signal, error)

Query returns signals matching the filter, newest first.

type SignalSet

type SignalSet struct {
	SchemaVersion string         `json:"schema_version"`
	RunID         string         `json:"run_id"`
	Count         int            `json:"count"`
	Counts        map[string]int `json:"counts"`
	Signals       []Signal       `json:"signals"`
}

SignalSet is the versioned export envelope for a run's signals - the unit a downstream consumer ingests. Counts is the per-dimension breakdown so an RL reward shaper or a security reviewer can see the shape at a glance.

func Export

func Export(db *sql.DB, runID string) (SignalSet, error)

Export returns the versioned signal set for a run (all dimensions).

func ValidateWireBytes

func ValidateWireBytes(data []byte) (SignalSet, error)

ValidateWireBytes decodes and validates a SignalSet from its JSON wire form. This is the entry point an external consumer uses to confirm a payload conforms to agentprovenance.signals/v1 before trusting it.

Jump to

Keyboard shortcuts

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