77 lines
2.5 KiB
Go
77 lines
2.5 KiB
Go
// confidence checks that the evidence an agent read supports the diagnosis
|
|
// behind the action it proposes. A System One judge reads the diagnosis, what
|
|
// the agent read and the action, and answers with a level and the gap it found.
|
|
// The guard is advisory, its verdicts recorded and no ceiling set, until the
|
|
// eval result shipped in this package shows the judge model passing its
|
|
// threshold. An action no agent proposed has no diagnosis, so it is not judged.
|
|
//
|
|
// Settings: judge_base_url and judge_model name the System One endpoint and
|
|
// model, and are required. eval_max_age_days is how long a passing eval stays
|
|
// trusted (default 90).
|
|
// Secret: judge_api_key, optional.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
_ "embed"
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/samcharles93/archipelago/guards/confidence/internal/judge"
|
|
"github.com/samcharles93/archipelago/sdk/guard"
|
|
"github.com/samcharles93/archipelago/sdk/judgegate"
|
|
)
|
|
|
|
//go:embed eval_result.json
|
|
var recordedEval []byte
|
|
|
|
type confidence struct {
|
|
judge *judge.Judge
|
|
// advised says why the guard is advisory, empty when it counts.
|
|
advised string
|
|
}
|
|
|
|
func build(cfg guard.Config) (guard.Guard, error) {
|
|
return newConfidence(cfg, recordedEval, time.Now)
|
|
}
|
|
|
|
func newConfidence(cfg guard.Config, evalJSON []byte, now func() time.Time) (*confidence, error) {
|
|
client, ok := judgegate.Client(cfg)
|
|
if !ok {
|
|
return nil, errors.New("judge_base_url and judge_model are required")
|
|
}
|
|
maxAge, err := judgegate.MaxAge(cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
j, err := judge.New(client)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &confidence{judge: j, advised: judgegate.AdvisoryReason(evalJSON, client.Model, now(), maxAge)}, nil
|
|
}
|
|
|
|
// Describe is advisory until the recorded eval passes: the whole guard is a
|
|
// model's opinion, so there is nothing else to count.
|
|
func (c *confidence) Describe() guard.Description {
|
|
return guard.Description{Name: "confidence", Version: "1.0.0", Advisory: c.advised != ""}
|
|
}
|
|
|
|
func (c *confidence) Judge(ctx context.Context, a guard.Action) (guard.Verdict, error) {
|
|
tc, ok := judge.CaseOf(a)
|
|
if !ok {
|
|
return guard.Verdict{Ceiling: guard.ActQuietly, BlindSpots: []string{"no agent diagnosis came with this action, so there was nothing to check"}}, nil
|
|
}
|
|
out, err := c.judge.Assess(ctx, tc)
|
|
if err != nil {
|
|
return guard.Verdict{}, err
|
|
}
|
|
v := out.Verdict()
|
|
if c.advised != "" {
|
|
v.BlindSpots = append(v.BlindSpots, "advisory, so it sets no ceiling: "+c.advised)
|
|
}
|
|
return v, nil
|
|
}
|
|
|
|
func main() { guard.Serve(build) }
|