# Testing Guide: AgentAI Platform

This guide walks you through the steps to test the core functionalities of the AI Voice Agent platform, from initial configuration to live CRM synchronization.

## 1. Prerequisites (API Keys)
To make the application "alive," you need to add the following keys to your `.env` files (located in the root, `services/api`, and `services/call-engine`):

*   **OpenAI API Key:** Powers the AI's intelligence and summarization.
*   **Deepgram API Key:** Handles real-time Speech-to-Text (STT).
*   **ElevenLabs API Key:** Provides the high-quality synthetic voice (TTS).
*   **Twilio Credentials:** Required for the phone number and SIP handling.

---

## 2. Testing Core Functionality (Phase-by-Phase)

### **Phase A: The Voice Engine (Real-time Test)**
1.  **Configure Twilio:** In your Twilio Console, point your Voice Webhook URL to:
    `http://<your-server-ip>:3000/twilio/voice`
2.  **Make a Call:** Dial your Twilio phone number from your mobile.
3.  **Interact:** Talk to the agent. Test its latency and understanding.
4.  **Handoff Test:** Ask for a "Manager" or "Technical Support" to see if the Multi-Agent routing (L1 to L2) triggers correctly.

### **Phase B: Admin Dashboard & Call Logs**
1.  Open the Dashboard: `http://localhost:5173/admin`
2.  Navigate to **Call Logs**.
3.  **Verify:** You should see your recent call listed. 
4.  **Details:** Click the log to see the full transcript, the sentiment (Positive/Neutral/Frustrated), and the AI-generated summary.

### **Phase D: CRM Integration (Simulator Mode)**
1.  **Verify Mode:** Ensure `CRM_MODE=simulator` is set in `services/api/.env`.
2.  **Test Connection:** 
    *   In the Dashboard, go to **CRM Settings**.
    *   Click **Test Connection** for any CRM (HubSpot/Salesforce).
    *   The Simulator will respond with a successful "Mock Connection" status.
3.  **End-to-End Sync:**
    *   Complete a call (or simulate one via the internal API).
    *   The `CrmSimulatorService` will automatically log a "Simulated Interaction" in the database.
    *   Check the **Activity Feed** in the Dashboard to see the simulated CRM sync event.

### **Phase E: Knowledge Base (RAG)**
1.  Go to **Knowledge Base** in the Dashboard.
2.  **Upload:** Upload a PDF (e.g., a sample company FAQ).
3.  **Wait:** Ensure the status turns to "Ready" (Vectorized).
4.  **Call Again:** Ask the AI agent a specific question found only in that PDF. It should now answer using that context.

---

## 3. CRM Integration (Live Mode)
When you are ready to go live:

1.  **Switch Mode:** Change `CRM_MODE=live` in `services/api/.env`.
2.  **Input:** Enter your real HubSpot or Salesforce API Key in the Dashboard.
3.  **Perform a Call:** Complete a short call with the AI.
4.  **Check CRM:** 
    *   Log into your HubSpot/Salesforce account.
    *   Look for a new "Call Note" or "Ticket" associated with your phone number.
    *   It should contain the AI summary and the sentiment tags.

---

## 4. Troubleshooting
*   **No response from AI?** Check your `call-engine` logs for OpenAI or Deepgram authentication errors.
*   **Dashboard empty?** Ensure the `laravel-api` and `mysql` containers are running.
*   **CRM not syncing?** Check the `laravel-api` logs for Guzzle/Connection exceptions.

---

**Happy Testing!** If you encounter any "Invalid Key" errors, the new **Service Health Monitor** on the Dashboard will help you identify which service is failing.
