# AgentAI API Documentation

Welcome to the AgentAI Management API. This service handles multi-tenant orchestration, agent configuration, and CRM synchronization.

## Base URL
`http://localhost:8000/api`

## Authentication
All protected routes require a Bearer Token obtained via the login endpoint.
`Authorization: Bearer <your_token>`

---

## Endpoints

### 1. Authentication
*   **POST** `/login`
    *   `email`: User email
    *   `password`: User password
*   **POST** `/logout` (Protected)

### 2. Agents
*   **GET** `/agents` - List all agents for the tenant.
*   **POST** `/agents` - Create a new voice agent.
*   **GET** `/agents/{id}` - Get specific agent details.
*   **PATCH** `/agents/{id}` - Update agent configuration (voice, LLM prompt, etc).

### 3. Call Logs
*   **GET** `/calls` - Retrieve historical call logs.
*   **GET** `/calls/{id}` - Get detailed transcript and sentiment analysis.

### 4. Knowledge Base (RAG)
*   **POST** `/documents/upload` - Upload PDF/Text files for agent training.
*   **GET** `/documents` - List processed documents and vector status.

### 5. CRM Integration
*   **POST** `/crm/connect` - Save API keys for HubSpot/Salesforce.
*   **GET** `/crm/status` - Check connectivity health.

---

## Webhooks
The Call Engine sends a `POST` request to `/api/webhooks/call-ended` upon every disconnection. This triggers:
1.  **Summarization:** OpenAI generates a call summary.
2.  **Sentiment Analysis:** Intent and mood are extracted.
3.  **CRM Sync:** Data is pushed to the connected CRM.
