Pi extension · codemode · Clef
Your agent writes one codemode script. The script asks Clef a typed question about every item and gets a probability for each allowed answer. The frontier model reads only the result. Every call goes through your own AI Gateway with your own scoped token.
returned to the frontier model
How it works
The script calls any Pi tool or MCP server, for example 250 Linear issues.
models.classify sends one typed request per item. Pi runs four at a time.
odds checks each answer: labels must be known, the choice must be the argmax, probabilities must sum to 1, and scores must be in range. Any other answer fails closed.
Plain JavaScript filters and sorts the results. Only the result returns to the frontier model.
const clef = await models.getModelOfType('classifier', 'odds', 'clef');
const { issues } = await tools.mcp__linear__list_issues({ state: 'open', limit: 250 });
const judged = await Promise.all(issues.map(async (issue) => {
const r = await models.classify(clef, {
state: issue,
questions: {
frustration: { type: 'choice', instructions: 'Tone of the writer only.',
criteria: { none: 'Calm', mild: 'Irritated', high: 'Angry' } },
urgent: { type: 'bool', instructions: 'Needs an engineer today?',
criteria: { true: 'Yes', false: 'No' } },
},
});
return { issue, ...r.answers };
}));
return judged
.filter((j) => j.urgent.probability > 0.8)
.map((j) => `${j.issue.id} ${j.issue.title}`);Auth
Install
Create a Cloudflare API token with AI Gateway: Run and Workers AI: Read on the account that owns the gateway. Turn on authentication for the gateway. Turn on codemode in Pi with "defaultTools": ["+codemode"].
pi install git:github.com/acoyfellow/odds
mkdir -p ~/.config/odds && chmod 700 ~/.config/odds
cat > ~/.config/odds/config.json <<'EOF'
{ "accountId": "<gateway-account-id>", "gateway": "default" }
EOF
chmod 600 ~/.config/odds/config.json
security add-generic-password -a "$USER" -s odds-gateway -w