Documentation
¶
Overview ¶
Package decide provides the `decide` action: it evaluates a state against a registered decision backend and returns structured answers. Backends are registered by the application before the pipeline runs; the .nflow file only names the backend.
Typical use:
{ backend: "http-judge", state: .state, questions: { verdict: { type: "label", labels: ["ok","bad"] } } } -> decide.run
Index ¶
Constants ¶
const ID = "decide"
Variables ¶
var DecideAction = action.New("decide.run", func(ctx context.Context, req Request) (Response, error) { if req.Backend == "" { return Response{}, xerr.BadRequest("decide: backend is required") } if len(req.Questions) == 0 { return Response{}, xerr.BadRequest("decide: questions map is required") } backend, exists := Lookup(req.Backend) if !exists { return Response{}, xerr.NotFound("decide: backend " + req.Backend + " not registered") } wireQuestions := make(map[string]any, len(req.Questions)) for key, question := range req.Questions { wireQuestions[key] = question } result, err := backend.Decide(ctx, req.State, wireQuestions) if err != nil { return Response{}, xerr.Unavailable("decide: backend "+req.Backend+" execution failed", err) } return result, nil }). Description("Evaluates state with a decision backend"). Tag("ai", "decision"). Build()
DecideAction evaluates a state against a registered backend.
Functions ¶
func LoadConfigFile ¶
LoadConfigFile reads a YAML config and registers every declared HTTP backend into the process-wide registry.
Types ¶
type Answer ¶
type Answer struct {
Value any `json:"value"`
Confidence float64 `json:"confidence"`
Label string `json:"label,omitempty"`
Score float64 `json:"score,omitempty"`
}
Answer is one question's resolved value.
type Backend ¶
type Backend interface {
Name() string
Decide(ctx context.Context, state, questions map[string]any) (Result, error)
Close() error
}
Backend is the contract every decision source implements.
func NewHTTPBackend ¶
func NewHTTPBackend(configuration HTTPConfig) (Backend, error)
NewHTTPBackend builds an HTTP decision source. A zero Timeout defaults to 30 seconds.
type FileConfig ¶
type FileConfig struct {
Backends map[string]struct {
Kind string `yaml:"kind"`
Endpoint string `yaml:"endpoint"`
Timeout time.Duration `yaml:"timeout"`
Headers map[string]string `yaml:"headers,omitempty"`
} `yaml:"backends"`
}
FileConfig is the YAML shape accepted by LoadConfigFile.
type HTTPConfig ¶
type HTTPConfig struct {
Name string `yaml:"name"`
Endpoint string `yaml:"endpoint"`
Timeout time.Duration `yaml:"timeout"`
Headers map[string]string `yaml:"headers"`
}
HTTPConfig configures an HTTP-backed decision source.
type Question ¶
type Question struct {
Type string `json:"type"`
Labels []string `json:"labels,omitempty"`
Rubric []string `json:"rubric,omitempty"`
Question string `json:"question,omitempty"`
}
Question describes one decision to make.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is an in-process backend table. It is a plain struct, not a package-level variable, so tests can create isolated instances.
type Request ¶
type Request struct {
Backend string `json:"backend" cli:"backend,b"`
State map[string]any `json:"state,omitempty"`
Questions map[string]Question `json:"questions"`
TimeoutMS int64 `json:"timeout_ms,omitempty"`
}
Request is the decide action's input.