Artificial Intelligence

Adding Conditional Logic to AI Agents

Building a smart AI agent isn't just about what it can do — it's also about knowing when to limit what it should do. In this guide, you'll learn how to use Xano's trigger system to dynamically restrict agent tools based on real-time user data, creating a more controlled and business-aware chatbot experience.

Setting Up the Agent and Tools

This walkthrough builds on the AI Agent Conversation History template, which you can install directly in Xano. Once installed, you'll have a working chatbot frontend served from an endpoint, along with a set of agent tools — including one for creating appointments. Head to the AI tab, open your agent, and take note of the tools already available to it.

Using Triggers to Control Tool Access

The real power here comes from triggers. Inside your agent's settings, you can add a trigger that runs an account check before the agent responds. In this example, the trigger checks whether the current user has a paid or past-due subscription status.

If the user is past due, the trigger restricts access to the Create Appointment tool entirely. The agent doesn't just ignore the tool — it genuinely loses access to it, so it can't be invoked no matter how the user phrases their request. You can instruct the agent to communicate this limitation naturally, prompting the user to resolve their payment before proceeding.

Seeing It in Action

When a past-due user opens the chatbot and tries to schedule an appointment, the agent will decline — not because of a scripted response, but because the tool simply isn't available to it. You can even ask the agent directly if it has access to the appointment scheduler, and it will confirm that it does not, explaining why.

Once the user's status is updated to paid, the trigger re-evaluates on the next interaction. The agent now has full access to the scheduling tool and can book an appointment — in this case for a specific date and time — which then appears as a new record in your Xano appointments table.

Keeping the Logic Simple but Scalable

The implementation itself is surprisingly concise. You pass the user's ID from the chatbot, look up their status in Xano, and use a conditional check to determine which tools remain available. With just a few statements, you've built a dynamic, data-driven agent that responds differently based on who it's talking to.

Of course, you can make this much more robust — restricting multiple tools, adding tiered access levels, or triggering different behaviors based on any field in your database. This example is just the starting point.

Get Started

Download the AI Agent Conversation History snippet to hit the ground running. With the template installed and triggers configured, you'll have a fully functional, condition-aware chatbot ready to go out of the box.

Sign up for Xano

Join 100,000+ people already building with Xano.
Start today and scale to millions.