# AI Agents Overview

> Automate customer conversations with intelligent AI-powered agents

## AI Agents Overview

AI Agents allow you to automate customer conversations using large language models. When a customer sends a message to your sender, the agent can respond intelligently, answer questions from your knowledge base, and execute actions via webhooks.

## When to Use AI Agents

AI Agents are ideal for:

| Use Case | Description |
|----------|-------------|
| **Customer Support** | Answer common questions, troubleshoot issues, and escalate complex cases |
| **Lead Qualification** | Collect contact information and qualify leads through conversation |
| **Appointment Booking** | Guide customers through scheduling via conversational flows |
| **FAQ Answering** | Provide instant answers using your knowledge base documents |
| **Order Status** | Look up orders and provide updates via webhook integrations |

## Supported Providers

Configure your agent with any of these LLM providers:

| Provider | Models | Notes |
|----------|--------|-------|
| **OpenAI** | gpt-4o, gpt-4o-mini, gpt-4-turbo | Most popular, great general-purpose |
| **Anthropic** | claude-3-5-sonnet, claude-3-5-haiku | Excellent reasoning capabilities |
| **Google** | gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite | Cost-effective for high volume |
| **Mistral** | mistral-large, mistral-small | European data residency option |
| **Zavu** | Managed models | No API key needed, billed to your account |

> **Info:**
> Using the **Zavu** provider means we handle the LLM API calls for you. Costs are charged directly to your Zavu balance at pass-through rates with no markup.

## Quick Start

Here's how to create an AI agent for a sender:

```typescript
import Zavudev from "@zavudev/sdk";

const zavu = new Zavudev({
  apiKey: process.env["ZAVUDEV_API_KEY"],
});

// Create an agent for your sender
const { agent } = await zavu.senders.agent.create("sender_abc123", {
  name: "Acme Support",
  provider: "openai",
  model: "gpt-4o-mini",
  systemPrompt: `You are a helpful customer support agent for Acme Corp.
Be friendly and concise. If you don't know the answer, say so.
For billing questions, ask the customer to email billing@acme.com.`,
  temperature: 0.7,
  contextWindowMessages: 10,
  triggerOnChannels: ["sms", "whatsapp"],
});

console.log("Agent created:", agent.id);
```

```bash
curl -X POST https://api.zavu.dev/v1/senders/sender_abc123/agent \
  -H "Authorization: Bearer $ZAVUDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Acme Support",
    "provider": "openai",
    "model": "gpt-4o-mini",
    "systemPrompt": "You are a helpful customer support agent for Acme Corp.\nBe friendly and concise. If you dont know the answer, say so.\nFor billing questions, ask the customer to email billing@acme.com.",
    "temperature": 0.7,
    "contextWindowMessages": 10,
    "triggerOnChannels": ["sms", "whatsapp"]
  }'
```

The agent is created disabled. Switch it on with `PATCH /v1/senders/{senderId}/agent`
and `{"enabled": true}` once it is configured; see [Setup](https://www.zavu.dev/docs/guides/ai-agents/setup).

## Agent Architecture

When a message arrives, the agent processes it through this flow:

```
                    Inbound Message
                          |
                          v
                  +---------------+
                  | Agent Enabled?|
                  +---------------+
                    |           |
                   No          Yes
                    |           |
                    v           v
              +---------+  +-----------------+
              | Webhook |  | Check Flow State|
              |  Only   |  +-----------------+
              +---------+       |         |
                          Has Active   No Active
                             Flow        Flow
                               |           |
                               v           v
                         +---------+  +-----------+
                         | Execute |  | Match Flow|
                         |   Step  |  |  Triggers |
                         +---------+  +-----------+
                               |           |
                               |      No Match
                               |           |
                               v           v
                         +---------+  +-----------+
                         |  Send   |  | Query KB  |
                         |Response |  | + LLM Call|
                         +---------+  +-----------+
                                           |
                                           v
                                     +-----------+
                                     |   Send    |
                                     |  Response |
                                     +-----------+
```

### Key Components

  - **LLM Configuration**: Choose your AI provider and model. Configure system prompts, temperature, and context window size.
  - **Conversational Flows**: Create structured conversation paths for lead capture, booking, and multi-step processes.
  - **Webhook Tools**: Let the AI execute actions by calling your webhooks (check orders, create tickets, etc.).
  - **Knowledge Base**: Upload documents and FAQs. The agent uses RAG to find relevant context when answering.

## Pricing

AI Agent costs are **pass-through** with no Zavu markup. You pay exactly what the providers charge:

| Provider | Model | Input Cost | Output Cost | ~Cost per Message |
|----------|-------|------------|-------------|-------------------|
| OpenAI | gpt-5.6-luna | $0.20/1M tokens | $1.20/1M tokens | ~$0.0004 |
| OpenAI | gpt-4o-mini | $0.15/1M tokens | $0.60/1M tokens | ~$0.0002 |
| OpenAI | gpt-4o | $2.50/1M tokens | $10/1M tokens | ~$0.004 |
| Anthropic | claude-3-5-haiku | $0.80/1M tokens | $4/1M tokens | ~$0.0014 |
| Anthropic | claude-3-5-sonnet | $3/1M tokens | $15/1M tokens | ~$0.005 |
| Google | gemini-2.5-flash-lite | $0.10/1M tokens | $0.40/1M tokens | ~$0.0002 |
| Google | gemini-2.5-flash | $0.30/1M tokens | $2.50/1M tokens | ~$0.0007 |

`~Cost per Message` assumes roughly 1,000 input and 150 output tokens. Provider
prices move: the agent's model picker in the dashboard lists the catalog
currently in force, and is what billing charges against.

> **Tip:**
> New agents on the **Zavu** provider start on **gpt-5.6-luna** (`openai/gpt-5.6-luna`). **gpt-4o-mini** and **gemini-2.5-flash-lite** cost less per token. Reserve larger models for complex reasoning tasks.

## Next Steps

  - [Setup Guide](https://www.zavu.dev/docs/guides/ai-agents/setup): Configure your first AI Agent step-by-step
  - [Conversational Flows](https://www.zavu.dev/docs/guides/ai-agents/flows): Build structured conversation paths
  - [Webhook Tools](https://www.zavu.dev/docs/guides/ai-agents/tools): Add custom actions via webhooks
  - [Knowledge Base](https://www.zavu.dev/docs/guides/ai-agents/knowledge-base): Set up RAG with your documents
