Quick overview
This workflow monitors Gmail emails labeled MARKETING and uses FirstHelm to enforce a budget guardrail before generating marketing copy with OpenAI, then emails approved results back to the requester, logs spend to Google Sheets, and notifies approvers in Slack when human approval is required.
How it works
- Triggers every 5 minutes when a new Gmail message arrives with the MARKETING label.
- Logs the requested run to FirstHelm and calls FirstHelm’s constraint evaluation endpoint with an estimated cost to get an allowed, needs_approval, or blocked verdict.
- If the verdict is allowed, it generates the marketing email copy with OpenAI and calculates token usage and an estimated cost for auditing.
- Logs the completed run (cost and tokens) to FirstHelm, emails the generated copy to the original requester via Gmail, and appends a spend record to a Google Sheets spreadsheet.
- If the verdict is needs_approval, it creates an approval request in FirstHelm, posts a Slack message to #ai-budget-approvals, waits, and then re-checks the budget gate in FirstHelm.
- If the run is blocked (initially or after re-check), it posts a Slack notification and logs the blocked decision to FirstHelm without calling the OpenAI model.
Setup
- Create a FirstHelm agent, configure spend constraints, and replace YOUR_AGENT_ID and YOUR_FIRSTHELM_API_KEY in all FirstHelm HTTP requests.
- Connect Gmail credentials, create/apply a MARKETING label, and ensure the trigger monitors that label.
- Add Slack credentials and set (or create) the #ai-budget-approvals channel used for approval and block notifications.
- Add Google Sheets credentials and replace YOUR_SPREADSHEET_ID (and ensure a sheet named “Spend” exists) for spend logging.
- Add OpenAI credentials for the OpenAI node and adjust the model/prompt if you want different copy output or cost assumptions.
Additional info
Preferred listing title: Block expensive AI agent runs with a budget guardrail via FirstHelm