A beginner-friendly guide to keeping an AI agent on the rails once it can take real actions: enforce the rules that matter in code with prerequisite gates, hand cases to humans with structure they can act on, and validate the handoff before it is sent.
AI agents are no longer just chatbots that answer questions.
An AI agent is a software system that uses a language model to decide what to do, then takes actions through connected tools. A language model, often shortened to LLM, is the AI system that reads text and generates responses or decisions. When an agent is connected to business systems, it might look up a customer, issue a refund, update an address, send an email, query a database, or escalate a case to a human.
That power creates a practical problem: if the agent is allowed to take real actions, how do we make sure it follows the correct workflow every time the workflow matters? A customer-support agent should verify a customer's identity before issuing a refund. A coding agent should not touch a production database unless explicitly allowed. A sales chatbot should not invent prices. These are not style preferences. They are business rules.
The common lesson from recent public incidents is simple, but easy to underestimate: important rules should not live only in the agent's instructions. They need to be enforced by the surrounding software.
Here is the whole thing working before we take it apart. Watch a support agent handle two tickets: one it can refund on its own, and one it must hand to a human. The customer's chat is on the left; the agent loop is on the right.
- model reply no tool stop_reason: end_turn
Two windows, one system. The customer's browser on the left, the agent loop on the right. Every ticket verifies the customer first, then acts: within the limit it refunds on its own; over it, the money rule forces a structured handoff to a human. This is the enforcement and handoff the rest of this project builds, end to end.
Design note: the back end resets per message, so you can see how many tools each turn needs — zero for “hi” and “thanks” (stop_reason: end_turn), several for the refund. The first tool is always get_customer: identity is verified before any order is touched, the prerequisite gate. The money rule is an in-code guard, not a tool (a core lesson), and the escalation branch is tinted rose. Use Refund / Escalate to switch tickets; Pause/Play works throughout; reduced-motion shows the finished conversation and waits for Play.
Sign in to view this build.
Create a free account to access the full build walkthrough on kevinsomany.com.
No account yet? Sign up free and come back here.