Concepts
Rules Engine
The FORG Rules Engine evaluates policy rules against incoming signals in real time, before the tool call completes from the developer's perspective. Rules can notify, block, or allow AI calls based on configurable conditions.
Rule anatomy
{
"id": "rule_7c3d1a2b",
"name": "Monthly per-user cap",
"enabled": true,
"scope": "user", // user | team | project | session | org
"window": "month", // 1h | 1d | 7d | month | session | all-time
"condition": {
"cost_usd": { "gt": 100 }
},
"action": "block", // block | notify | allow
"notify_channels": [], // email | slack | webhook
"notify_users": [] // list of emails (for notify action)
}Evaluation model
When a signal arrives at the Rule Engine, the following happens for each enabled rule:
- Accumulate— The engine computes the running total for the rule's scope and window (e.g., total cost for this user this month).
- Evaluate condition — The accumulated value is compared against the rule condition threshold.
- Apply action — If the condition is met, the action fires. Multiple rules can match a single signal; the most restrictive action wins (block beats notify).
Condition operators
| Operator | Meaning | Example |
|---|---|---|
gt | Greater than | { "cost_usd": { "gt": 50 } } |
gte | Greater than or equal | { "tokens_in": { "gte": 100000 } } |
lt | Less than | { "latency_ms": { "lt": 100 } } |
lte | Less than or equal | — |
eq | Equal | { "model": { "eq": "gpt-4o" } } |
in | In list | { "model": { "in": ["gpt-4o", "claude-opus-4-5"] } } |
not_in | Not in list | — |
Compound conditions
Multiple field conditions in a single rule are AND-ed. For OR logic, create multiple rules:
// Match: high-cost model AND large context
{
"condition": {
"model": { "in": ["claude-opus-4-5", "gpt-4o"] },
"tokens_in": { "gt": 50000 }
}
}Evaluation windows
| Window | Description |
|---|---|
1h | Rolling 60-minute window |
1d | Rolling 24-hour window (not calendar day) |
7d | Rolling 7-day window |
month | Calendar month, resets at midnight on the 1st |
session | Current developer session |
all-time | Cumulative since org creation |
Performance
Rule evaluation adds less than 5ms to the signal processing path in the 99th percentile. The rule engine runs in the Cloudflare Workers edge runtime, co-located with the ingestion endpoint, minimizing round-trip latency.
© 2026 UpgradIQ, Inc.Edit this page on GitHub