-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquality-gated-execution.ts
More file actions
50 lines (44 loc) · 1.57 KB
/
quality-gated-execution.ts
File metadata and controls
50 lines (44 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Quality-gated execution — only run if the capability meets your bar.
*
* Strale assigns every capability a quality score (SQS, 0-100).
* Your agent can set a minimum threshold with `min_sqs`.
* If the capability's current score is below your threshold,
* the request is rejected — your agent never gets bad data.
*
* Use case: Production agents that need reliable data
*
* Requires: STRALE_API_KEY environment variable
* Install: npm install straleio
* Run: STRALE_API_KEY=sk_live_... npx tsx agent-patterns/quality-gated-execution.ts
*/
import { Strale } from "straleio";
const strale = new Strale({ apiKey: process.env.STRALE_API_KEY! });
async function qualityGatedCheck(email: string) {
try {
const result = await strale.do("email-validate", {
email,
min_sqs: 80,
max_price_cents: 10,
});
console.log(`Quality gate passed (SQS: ${result.sqs?.score})`);
console.log(`Result: ${JSON.stringify(result.output)}`);
return result.output;
} catch (error: any) {
if (error.message?.includes("min_sqs")) {
console.log(`Quality gate blocked execution (SQS below threshold)`);
console.log(`Falling back to manual review queue...`);
return null;
}
throw error;
}
}
qualityGatedCheck("test@example.com");
// Why this matters for production agents:
//
// Without min_sqs:
// agent calls API -> gets data -> trusts it blindly -> bad decisions
//
// With min_sqs:
// agent calls Strale -> quality check passes? -> get data -> trust it
// -> quality check fails? -> fallback -> no bad data