Make a decision from Go
An agent proposes a file operation. Should your program allow it, send it to a person, or escalate? Here the model answers one question about the request, and a policy in your Go code decides.
You need Go 1.27 or later, and a TypeSafe key set as
TYPESAFE_API_KEY.
Create a module
Section titled “Create a module”mkdir gate && cd gatego mod init example.com/gatego get github.com/deepnoodle-ai/decideWrite the program
Section titled “Write the program”Save this as main.go. It is the gate example from decide’s repository:
48 collapsed lines
// Command gate asks what file operation a user requested and gates the// agent's proposed delete with patterns/gate: allow, review, or escalate.package main
import ( "context" "fmt" "log"
"github.com/deepnoodle-ai/decide" "github.com/deepnoodle-ai/decide/patterns/gate")
// policy requires more confidence to delete than to read. Every threshold// is a placeholder; measure your own on labeled traffic.var policy = gate.Asymmetric{ Input: "action", Measure: gate.MeasureConfidence, Floor: 0.6, Options: map[string]gate.OptionBand{ "read_file": {Allow: 0.6, Review: 0.6}, "delete_file": {Allow: 0.85, Review: 0.6}, "none": {Always: gate.Escalate}, },}
func main() { client, err := decide.NewClient() if err != nil { log.Fatal(err) }
req := decide.NewRequest( `User: "Can you clean up the drafts?" Agent proposes: delete_file(path="drafts/final.txt")`) decide.Ask(req, "action", decide.Choice( "Which file operation did the user ask the agent to perform?", decide.Option("read_file", "Read or show the contents of a file"), decide.Option("delete_file", "Delete a file"), decide.Option("none", "Neither, or the proposed call does not match the request"), ))
resp, err := client.SystemOne(context.Background(), req) if err != nil { log.Print(err) // a nil response gates as missing, which escalates } d := policy.Evaluate(gate.FromResponse(resp)) fmt.Printf("%s: %s\n", d.Outcome, d.Reason)}The model chooses read_file, delete_file, or none. none means the
request is unclear, or the proposed operation doesn’t match it.
Read the policy
Section titled “Read the policy”Each answer comes with a confidence from 0 to 1. The policy compares it against a threshold for the chosen option:
| Chosen option | Outcome |
|---|---|
read_file |
allow at 0.60 or more, otherwise escalate |
delete_file |
allow at 0.85 or more, review from 0.60, otherwise escalate |
none |
escalate |
These thresholds are placeholders. Choose yours from labeled examples of your own traffic.
Run it
Section titled “Run it”go run .
Output as text
$ go run . escalate: action chose none, confidence=0.38 -> escalate (below floor 0.6)
The program prints allow, review, or escalate, with the
reason. “Clean up the drafts” is ambiguous, so the model may answer
none.
The program judges the operation and never runs it. Your application decides what each outcome does.
What next
Section titled “What next”decide is Apache 2.0. Made by Deep Noodle, after some very hard thinking.