A new judgement module assesses one concrete action: hard rules refuse before any guard runs; every guard sets a ceiling and the action runs at the lowest; a guard that fails, panics or gives no ceiling holds it at propose and wait; an advisory verdict is recorded and sets no ceiling. Reversibility and Precedent (the fresh-install class default) are the first guards. Every decision is recorded with its verdicts and class, and the run's trail lists them. Agent tools now offer connector actions too: each call is assessed and executed only as decided and only with the judged input, and a held action comes back to the agent as a failed call naming its level and findings. Tools gain Resolve, so an MCP server's declared effect reaches judgement.
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package judgement
|
|
|
|
import "fmt"
|
|
|
|
// Level is how much autonomy an action runs with, from the most (act
|
|
// quietly) to the least (never). A higher value means less autonomy.
|
|
type Level int
|
|
|
|
// The five levels, in order of decreasing autonomy.
|
|
const (
|
|
ActQuietly Level = iota + 1
|
|
ActAndTell
|
|
ProposeAndWait
|
|
Escalate
|
|
Never
|
|
)
|
|
|
|
var levelNames = [...]string{
|
|
ActQuietly: "act_quietly",
|
|
ActAndTell: "act_and_tell",
|
|
ProposeAndWait: "propose_and_wait",
|
|
Escalate: "escalate",
|
|
Never: "never",
|
|
}
|
|
|
|
func (l Level) String() string {
|
|
if l < ActQuietly || l > Never {
|
|
return fmt.Sprintf("level(%d)", int(l))
|
|
}
|
|
return levelNames[l]
|
|
}
|
|
|
|
// MarshalText writes the level's name.
|
|
func (l Level) MarshalText() ([]byte, error) {
|
|
if l < ActQuietly || l > Never {
|
|
return nil, fmt.Errorf("no level %d", int(l))
|
|
}
|
|
return []byte(levelNames[l]), nil
|
|
}
|
|
|
|
// UnmarshalText reads a level's name.
|
|
func (l *Level) UnmarshalText(b []byte) error {
|
|
for i, name := range levelNames {
|
|
if name != "" && name == string(b) {
|
|
*l = Level(i)
|
|
return nil
|
|
}
|
|
}
|
|
return fmt.Errorf("no level named %q", b)
|
|
}
|
|
|
|
// Runs reports whether an action at this level runs without waiting for
|
|
// anyone.
|
|
func (l Level) Runs() bool { return l == ActQuietly || l == ActAndTell }
|
|
|
|
// lowest is the level with the least autonomy among levels.
|
|
func lowest(levels ...Level) Level {
|
|
out := ActQuietly
|
|
for _, l := range levels {
|
|
out = max(out, l)
|
|
}
|
|
return out
|
|
}
|