interactive · 12 min
A Production-Shaped Handler
Objective: compose the course — a stateless handle(request) that
checks a budget, guards the action, decides an action, and returns a
structured result. In mock mode the decision comes from policy; in real
mode the same line calls your model instead — the rest of handle is
identical in both modes.
Mock is the default and free. Switch the Model toggle above to Real (your key) to run this same code on your own OpenAI-compatible model.
policy is the Foundations MockLLM seam; handle is stateless —
inputs in, structured result out, with budget, guardrail, and trace
applied. In mock mode handle calls policy; switching to real mode
routes that single decide line through your model while every other
step — budget check, guard, structured result — stays identical. The
guard still enforces ALLOWED in both modes, so a real model returning
an out-of-policy action is still blocked.
Best practice: the request handler is pure orchestration of the patterns you already built — keep it stateless and return structured results, never raw model text.
Next: Going Further