AI agents
Building with AI agents in production: briefs, tools, budgets, review gates and accountability.
Run AI agents like queue workers: briefs, budgets and stop reasons
How I run AI coding agents like queue workers: written briefs, narrow tools, hard budgets, idempotent writes, typed stop reasons and review gates.
Snippets
Bounded AI agent loop with step, token, time and error budgets
Check every budget before each step, share one AbortSignal with the model call and the tools, and end with a typed out_of_budget that names the limit.
Map Claude stop_reason to a typed agent loop outcome
Map stop_reason in the adapter to done, blocked or out_of_budget, resume on pause_turn, and throw on anything unexpected rather than reporting success.
Derive idempotency keys for AI agent tool calls
Hash the task id, tool name and canonical arguments in the harness, and pass the key to the system that owns the side effect, not only to a local ledger.