Documentation
¶
Overview ¶
Package autoapprove provides an AI-powered evaluator for tool approval decisions. Instead of showing the manual confirmation overlay, it sends the action and reason to a Haiku-class model and returns the model's approve/deny decision along with a short rationale.
The evaluator makes a single-turn API call with no tool use. The model responds with a JSON object containing "approved" (bool) and "rationale" (string). Malformed responses are treated as denials so that a parsing failure never silently permits a dangerous action.
Index ¶
- func Evaluate(ctx context.Context, apiKey, systemPrompt, command, reason string, ...) (bool, string, error)
- func EvaluateWithGenerationOptions(ctx context.Context, apiKey, systemPrompt, command, reason string, ...) (approved bool, rationale string, err error)
- func WithTelemetry(ctx context.Context, correlation Correlation, observe Observer) context.Context
- type Correlation
- type EvaluationError
- type Observer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Evaluate ¶
func Evaluate(ctx context.Context, apiKey, systemPrompt, command, reason string, evaluatorModel model.ID, opts ...client.Option) (bool, string, error)
Evaluate sends the action subject (command or URL) and reason to the configured evaluator model and returns its approval decision. systemPrompt is the evaluator instructions for the action category (supplied by the requesting tool's approval descriptor). evaluatorModel selects which model performs the evaluation; callers should default it to a Haiku-class model since these calls are small and elicit a short, structured response, so a larger model adds no benefit. Returns (false, rationale, nil) on a clean denial; (false, "", err) on an API or parse error so the caller can treat any error as a denial with logging. opts configures additional transport options (e.g. client.WithProviderPreferences).
func EvaluateWithGenerationOptions ¶ added in v0.6.0
func EvaluateWithGenerationOptions(ctx context.Context, apiKey, systemPrompt, command, reason string, evaluatorModel model.ID, gen model.GenerationOptions, opts ...client.Option) (approved bool, rationale string, err error)
EvaluateWithGenerationOptions evaluates with the configured reasoning intent.
Types ¶
type Correlation ¶ added in v0.6.0
type Correlation struct {
EvaluationID string `json:"evaluation_id"`
SessionID string `json:"session_id"`
ToolName string `json:"tool_name"`
Variant string `json:"variant,omitempty"`
Subagent bool `json:"subagent"`
AgentID string `json:"agent_id,omitempty"`
}
Correlation is copied into each event; it never changes shared logger state.
type EvaluationError ¶ added in v0.6.0
type EvaluationError struct {
Category string
Attempts int
RequestedModel model.ID
ServedModel model.ID
Completion *client.CompletionMetadata
Routing *client.Routing
Transport *client.TransportDiagnostics
// contains filtered or unexported fields
}
EvaluationError reports a failed evaluation without retaining sensitive text.
func (*EvaluationError) Error ¶ added in v0.6.0
func (e *EvaluationError) Error() string
func (*EvaluationError) Unwrap ¶ added in v0.6.0
func (e *EvaluationError) Unwrap() error
type Observer ¶ added in v0.6.0
Observer receives only allowlisted facts, never request or response text.
Source Files
¶
- autoapprove.go
- classification.go
- recovery.go
- telemetry.go