policymodel

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 18 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 policymodel serves the small, constrained decisions the interaction plane makes about a live conversation.

Three constraints define what a policy model is allowed to be, and all three are enforced here rather than asked for in a prompt:

  1. Enumerated output, never free generation. The client sends the permitted answers and rejects anything that is not one of them. A policy model cannot become a third cognition provider because it has no way to say anything that is not on the list.
  2. No tool authority, ever. This client cannot send tool definitions and cannot parse tool calls, so a policy model sits outside the proposal/execute split by construction.
  3. Decision-time information only. What a decision may see is assembled by the caller and passed as a value; this package has no handle on the trajectory or on perception, so it cannot reach for hindsight.

Sizing is measured rather than assumed. The starting point is a state-of-the-art model in the ~3B class; whether that is adequate for these judgements is a question the measurement program answers before the choice is fixed.

Index

Constants

View Source
const DefaultBaseURL = "http://127.0.0.1:8000/v1"

DefaultBaseURL is the conventional local OpenAI-compatible location.

Variables

View Source
var ErrClientClosed = errors.New("policy model client is closed")

ErrClientClosed is returned when a caller tries to start policy work after the independently owned client has left its lifecycle. Close waits for work that already acquired the client, so no request can outlive a completed Close call.

Functions

This section is empty.

Types

type Client

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

Client is one policy-model endpoint.

func New

func New(config Config) (*Client, error)

New validates the configuration.

func (*Client) Close

func (client *Client) Close() error

Close releases idle HTTP connections and permanently refuses new policy work. It is safe to call more than once. A caller that closes concurrently with an in-flight request waits for that request's bounded context to finish before the transport is released.

func (*Client) Decide

func (client *Client) Decide(ctx context.Context, decision interaction.Decision) (_ interaction.Outcome, resultErr error)

Decide answers one enumerated question.

func (*Client) DecisionTimeout

func (client *Client) DecisionTimeout() time.Duration

DecisionTimeout is the live deadline retained in architecture evidence.

func (*Client) Generate

func (client *Client) Generate(ctx context.Context, prompt, evidence string, maxTokens int) (_ string, resultErr error)

Generate asks for a short free-form answer rather than an enumerated one.

Most decisions here are a choice among options, which is what makes them cheap and checkable. One is not: noticing that somebody has set a policy out loud has to come back with the policy, and no enumeration can contain it.

It runs off the critical path, so the budget is generous where Decide's is bounded to the exact enumerated vocabulary - what it produces is read once per turn rather than five times a second.

func (*Client) Metrics

func (client *Client) Metrics() Metrics

Metrics reports how the policy model is behaving. Refusals matter: a model that keeps answering off the list is a model that is too small for the job, which is exactly what the sizing question needs to be able to see.

func (*Client) Name

func (client *Client) Name() string

Name identifies the model in reports.

type Config

type Config struct {
	BaseURL string
	Model   string
	APIKey  string
	// Timeout bounds one decision. It is short by default: a decision about a
	// live conversation that arrives late is worthless, and waiting for it is
	// worse than falling back to the rule.
	Timeout time.Duration
	// GuidedChoice asks a current vLLM-compatible server to constrain decoding
	// to the enumerated options through its structured_outputs.choice request
	// contract. The client's own validation remains authoritative even when a
	// provider returns malformed output.
	GuidedChoice bool
	// Governor admits decisions against a shared compute budget. A policy
	// model competes for the same GPU as everything else, so it belongs under
	// the same governor rather than beside it.
	Governor *admission.Governor
	// Class is the admission class. It defaults to interactive: above
	// speculative preparation, below the foreground continuation.
	Class      admission.Class
	HTTPClient *http.Client
	// Reasoning is how this endpoint is told not to think.
	//
	// A policy model's contract is one enumerated choice from a short prompt,
	// so reasoning is definitionally not part of it - and a reasoning model
	// asked anyway spends the whole budget on the reasoning. Qwen3 answers
	// "<think>" and stops, having chosen nothing, and constrained decoding
	// does not help because the thinking block precedes the constraint.
	//
	// The switch is spelled differently by every vendor, which is why this is
	// declared rather than assumed. An instruct model needs no switch at all
	// and should be given ReasoningControlNone; a model whose thinking cannot
	// be turned off should not be used here.
	Reasoning openaicompat.ReasoningControl
}

Config configures the client.

type Metrics

type Metrics struct {
	Decisions   uint64  `json:"decisions"`
	Refusals    uint64  `json:"refusals"`
	Timeouts    uint64  `json:"timeouts"`
	MeanLatency float64 `json:"mean_latency_ms"`
}

Metrics is operational telemetry with no conversation content in it.

Jump to

Keyboard shortcuts

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