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:
- 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.
- 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.
- 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
- Variables
- type Client
- func (client *Client) Close() error
- func (client *Client) Decide(ctx context.Context, decision interaction.Decision) (_ interaction.Outcome, resultErr error)
- func (client *Client) DecisionTimeout() time.Duration
- func (client *Client) Generate(ctx context.Context, prompt, evidence string, maxTokens int) (_ string, resultErr error)
- func (client *Client) Metrics() Metrics
- func (client *Client) Name() string
- type Config
- type Metrics
Constants ¶
const DefaultBaseURL = "http://127.0.0.1:8000/v1"
DefaultBaseURL is the conventional local OpenAI-compatible location.
Variables ¶
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 (*Client) Close ¶
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 ¶
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.
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.