Artificial Intelligence

Superpowered Sales Motions with Custom AI Agents

Managing leads manually — checking the list, assigning reps, drafting outreach — eats up a lot of time. In this guide, you'll learn how to build a custom AI agent inside Xano that handles all of that automatically, using Google Gemini as the model host. The result is a human-in-the-loop workflow where your team only needs to review and click send.

Setting Up Your Environment

Before building the agent, you'll need a Google Gemini API key. Head to your Xano instance settings, open the Environment Variables card, and add your key there. Storing it as an environment variable (like GOOGLE_AI) lets you reference it securely throughout your workspace using Xano's {{$environment.GOOGLE_AI}} template syntax.

Understanding the Data Structure

This project uses three database tables. Your leads table holds pre-qualified leads pulled from a CSV or external API. The process leads table stores the matched rep, the lead reference, the drafted email content, and a sent status flag. Your reps table contains each sales representative's name, email, and — most importantly — their skills, which the agent uses to determine the best match.

Building the AI Agent

Navigate to the AI tab in Xano and create a new agent called something like "Rep Matching Agent." You'll configure two key prompts:

  • System prompt: This is your agent's directive. Define its role, tone, available tools, and behavioral rules — like including a greeting with the lead's name but omitting a sign-off.
  • User prompt: This is where you pass in the actual lead data at runtime using template syntax and $args, which are arguments supplied from your calling workflow.

Set your model to Gemini 2.5 Flash, keep the temperature low (around 0.2) for deterministic output, and set max steps to five.

Creating the AI Tools

Agents become powerful when paired with tools. You'll build two:

get_reps — This tool queries all records from the reps table and returns their names and skills. The agent uses this data to intelligently select the best rep for each lead. No inputs are needed; it simply fetches and returns the list.

create_match — This tool accepts a lead ID, a rep ID, and an email body. It marks the lead as processed, retrieves the rep's name, uses Xano's template engine to append a proper sign-off to the email body, and then creates or updates a record in the process leads table using an "add or edit" function to handle duplicates gracefully.

Once both tools are built and published, connect them to your agent.

Running the Agent from an Endpoint

Create an API endpoint that queries unprocessed leads (where processed = false), limits results using pagination, and loops through each lead using a For Each function. Inside the loop, call your Rep Matching Agent and pass in the lead's data as arguments.

When you run the endpoint, the agent processes each lead, picks the best rep based on skills, drafts a personalized email, and saves everything to your process leads table — ready for a human to review and send.

What You've Built

This workflow demonstrates how agents go beyond static logic. Rather than hardcoding matching rules, you're giving the agent a brain to reason through assignments intelligently. Add more leads, update rep skills, or refine your prompts — the agent adapts without you rewriting business logic every time.

Sign up for Xano

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