Tag: open source

  • The Agent Cookbook: 12 Patterns That Keep AI Agents Safe in Production

    Everyone is building agents. Almost nobody ships the safety layer.

    Demos are easy. Production is where agents approve the wrong thing, loop until the invoice arrives, call tools they were never meant to touch, and fail silently at 2 AM. The gap between a demo agent and a production agent is not a better model. It is a set of small, boring, essential patterns around the model.

    So I built them. The Agent Cookbook is an open-source repo of 12 production patterns for agentic AI — each one a small, runnable, copy-paste Python example. No framework. No API keys. Each pattern runs locally in under five minutes.

    Here is the whole cookbook on one page — the 12 patterns do four jobs.

    Diagram: The Agent Cookbook's 12 patterns grouped into four jobs — control what the agent can do, control what it can spend, control what it can say, and prove what it did.

    Job 1: Control what the agent can do

    01 — Human approval gate. The agent proposes; a human disposes. Anything irreversible waits for a yes.
    05 — Tool allowlist. Least privilege for agents: the agent can only call the tools it is explicitly given. Everything else does not exist.
    12 — Kill switch. One flag that stops the agent now — not after the deploy, not after the meeting. Now.

    Job 2: Control what the agent can spend

    02 — Budget cap. A hard ceiling on tokens and cost per run. When the cap is hit, the agent stops, cleanly, with a reason.
    03 — Loop breaker. Agents love loops. This pattern counts, detects the spin, and breaks out before the bill does.
    11 — Model routing & fallback. Cheap model first, strong model when it matters, and a fallback path when the primary model fails.

    Job 3: Control what the agent can say

    04 — Structured output with repair. Demand a schema. When the output does not parse, repair it instead of crashing on it.
    06 — Input/output guardrails. Check what goes in and what comes out. Both directions. Every time.
    07 — Grounded answers. The agent answers from retrieved evidence — and says “I don’t know” when the evidence is not there.

    Job 4: Prove what the agent did

    08 — Eval harness. A small, repeatable test set the agent must pass before any change ships.
    09 — Full trace logging. Every step, tool call, and decision recorded. When someone asks “why did the agent do that?”, you have the receipt.
    10 — Checkpoint & resume. Long runs save state as they go. A crash becomes a pause, not a restart from zero.

    How to use it

    Clone the repo, pick the pattern your agent is missing, and run it — each folder under patterns/ has its own README and a single framework-free Python file:

    github.com/simplyjug/agent-cookbook

    The patterns are deliberately small. Copy one into your codebase, adapt it, and your agent gets a little more production-shaped. Stack all twelve and you have the safety layer most agent projects skip — the layer that decides whether your agent survives its first month in production.

    The repo is MIT licensed. If it saves you from one 2 AM incident, star it so the next engineer finds it — and subscribe below for the deep-dives: I will be taking individual patterns apart, one at a time, here on aiDeeva.

    The Agent Cookbook is maintained by Jugal Shah. Companion reading: The Agentic Architecture Framework — the method these patterns plug into.