eval

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 16 Imported by: 1 module, 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 eval is Verdict's evaluator: it turns a parsed DMN model into a prepared program and then executes decisions, decision services and boxed expressions against caller inputs, recording a trace as it goes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// FEEL is the expression evaluator. Required.
	FEEL *feel.Evaluator
	// Bridge answers agentDecision nodes. Nil means agent decisions fail, which
	// their failure policy then handles.
	Bridge agent.Bridge

	// TraceMode selects how much of an evaluation is recorded.
	TraceMode trace.Mode
	// RedactPaths name bindings whose values are replaced in the trace.
	RedactPaths []string

	// Strict makes the loader reject models whose static analysis reports
	// error-severity findings, and makes ambiguous hit policies fatal.
	Strict bool

	// DefaultMaxLatency bounds an agent decision that declares no policy of its
	// own. Zero means unbounded, which is almost never what a caller wants; the
	// engine's own default is applied before Config reaches here.
	DefaultMaxLatency time.Duration

	// Parallel evaluates independent decisions in the same dependency layer
	// concurrently.
	Parallel bool

	// Memoize caches the value of referentially transparent nodes on the hash of
	// their inputs, within a single evaluation. Agent decisions are never
	// memoised.
	Memoize bool

	// MaxDepth bounds recursive decision-service invocation.
	MaxDepth int

	// Clock supplies timestamps. Nil means time.Now.
	Clock func() time.Time

	// NodeEvaluators overrides the built-in handling of a boxed-expression kind.
	NodeEvaluators map[model.Kind]NodeEvaluator
}

Config is everything the evaluator needs that is not the model itself.

type Context

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

Context is the state one node evaluation sees: the Go context, the visible names, the trace writer for the node, and the shared diagnostic sink.

A Context is derived, never mutated in place by a child: entering a nested scope produces a new Context whose vars map shadows the parent's. That is what makes concurrent evaluation of independent decisions safe without a lock around the variable map.

func (*Context) Derive

func (ec *Context) Derive(bindings map[string]any) *Context

Derive returns a Context with additional bindings layered over this one. Passing a nil or empty map returns the receiver unchanged.

func (*Context) Diagnose

func (ec *Context) Diagnose(d diag.Diagnostic)

Diagnose lets a custom NodeEvaluator contribute a diagnostic.

func (*Context) FEEL

func (ec *Context) FEEL() *feel.Evaluator

FEEL returns the expression evaluator, so a custom NodeEvaluator can compile and evaluate expressions with the same dialect and function libraries.

func (*Context) Go

func (ec *Context) Go() context.Context

Go returns the evaluation's context.Context.

func (*Context) Trace

func (ec *Context) Trace() trace.Writer

Trace returns the writer for the node being evaluated.

func (*Context) Vars

func (ec *Context) Vars() map[string]any

Vars returns the names visible at this node. The map must not be mutated; use Derive to add bindings.

type Matcher

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

Matcher exposes a prepared decision table's rule-matching machinery to the static analyser.

Analysis runs the *same* unary tests through the *same* evaluator that evaluation uses, rather than reimplementing DMN's matching rules over the table's source text. That is what keeps the gap and overlap report honest: it cannot drift from what the engine will actually do at runtime.

func (*Matcher) Admits

func (m *Matcher) Admits(clause int, value any) (admits, decidable bool)

Admits reports whether a value is inside the domain an input clause declares through its allowed-value list, and whether there was a decidable list to ask.

The analyser probes each boundary and the points either side of it, which for a range-valued list means probing just outside the declared domain. A value the modeller has said cannot occur is not a gap, so those probes are dropped rather than reported — otherwise a table that covers its whole declared domain could never be gap-free, and --strict would be unusable.

func (*Matcher) Compile

func (m *Matcher) Compile(text string) (*feel.Expr, error)

Compile parses an expression with the program's dialect, so the analyser can interpret a declared inputValues list with the same grammar the table uses.

func (*Matcher) EvalStatic

func (m *Matcher) EvalStatic(x *feel.Expr) (any, bool)

EvalStatic evaluates an expression with no model variables in scope. It returns ok=false when the expression depends on runtime data, which is the analyser's signal that it cannot decide the question statically.

func (*Matcher) InputCount

func (m *Matcher) InputCount() int

InputCount reports how many input clauses the table has.

func (*Matcher) InputValues

func (m *Matcher) InputValues(clause int) string

InputValues returns the compiled allowed-value list of an input clause, which the analyser uses as that clause's domain when the modeller declared one.

func (*Matcher) Match

func (m *Matcher) Match(values []any) ([]int, error)

Match reports which rules match a point in the table's input space, in rule order. Values are FEEL values parallel to the input clauses.

func (*Matcher) OutputExprs

func (m *Matcher) OutputExprs(rule int) []*feel.Expr

OutputExprs returns a rule's compiled output expressions.

func (*Matcher) RuleCount

func (m *Matcher) RuleCount() int

RuleCount reports how many rules the table has.

func (*Matcher) Test

func (m *Matcher) Test(rule, clause int) *feel.UnaryTest

Test returns the compiled unary test at (rule, clause), or nil for "-".

type NodeEvaluator

type NodeEvaluator interface {
	// Evaluate produces the expression's value. The scope holds every name
	// currently visible, already converted to FEEL values.
	Evaluate(ec *Context, expr model.Expression) (any, error)
}

NodeEvaluator evaluates one boxed-expression kind. Registering an evaluator for a kind replaces the built-in handling for that kind, which is the extension point behind the engine's WithNodeEvaluator option.

type NodeEvaluatorFunc

type NodeEvaluatorFunc func(ec *Context, expr model.Expression) (any, error)

NodeEvaluatorFunc adapts a function to NodeEvaluator.

func (NodeEvaluatorFunc) Evaluate

func (f NodeEvaluatorFunc) Evaluate(ec *Context, expr model.Expression) (any, error)

Evaluate implements NodeEvaluator.

type Program

type Program struct {
	Defs  *model.Definitions
	Graph *model.Graph
	// contains filtered or unexported fields
}

Program is a model prepared for evaluation: the DRG indexed, every expression compiled, every prompt template parsed.

Preparation is where a model's expression errors surface. Doing it once at load time rather than on first evaluation means a model that will fail is rejected at deploy, not at 3am.

func Prepare

func Prepare(defs *model.Definitions, cfg Config) (*Program, []diag.Diagnostic, error)

Prepare compiles a parsed model. It returns the program together with any diagnostics; an error means the model cannot be evaluated at all — a cyclic DRG, or, in strict mode, any error-severity diagnostic.

func (*Program) Config

func (p *Program) Config() Config

Config exposes the program's evaluation configuration.

func (*Program) Diagnostics

func (p *Program) Diagnostics() []diag.Diagnostic

Diagnostics returns the preparation diagnostics.

func (*Program) Evaluate

func (p *Program) Evaluate(ctx context.Context, req Request) (*Result, error)

Evaluate runs a request against the program.

func (*Program) Matcher

func (p *Program) Matcher(t *model.DecisionTable) (*Matcher, bool)

Matcher builds a matcher for a prepared decision table.

func (*Program) TopLevelDecisions

func (p *Program) TopLevelDecisions() []string

TopLevelDecisions lists the decisions no other decision requires — the natural outputs of the model, and the default entry point.

type Request

type Request struct {
	// Decisions names the decisions to evaluate, by ID or name. Empty means
	// every decision that nothing else in the model depends on — the DRG's
	// top-level outputs.
	Decisions []string
	// Service names a decision service to evaluate instead of Decisions.
	Service string
	// Inputs are the caller-supplied values, keyed by input-data name.
	Inputs map[string]any
}

Request selects what to evaluate.

type Result

type Result struct {
	// Outputs are the values of the evaluated entry points, keyed by decision
	// output name.
	Outputs map[string]any
	// Trace is the execution record. Nil when tracing is off.
	Trace *trace.Trace
	// Diagnostics are the model's load-time diagnostics plus anything the
	// evaluation itself reported.
	Diagnostics []diag.Diagnostic
	// Duration is the wall time of the evaluation.
	Duration time.Duration
}

Result is the outcome of one evaluation.

Jump to

Keyboard shortcuts

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