Skip to content

Commit 548e77a

Browse files
badri-singhalswaroopvarma1
authored andcommitted
Refactor Clairvoyance
1 parent 2032b76 commit 548e77a

24 files changed

Lines changed: 79 additions & 274 deletions

File tree

README.md

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,52 @@
1-
# Breeze Automatic
1+
# Clairvoyance
22

3-
Breeze Automatic is a sophisticated server designed to power advanced conversational AI experiences, built around a **Pipecat-based Voice Agent** for robust, real-time voice assistants.
3+
Clairvoyance is a powerful, multi-agent conversational AI platform designed to support sophisticated, real-time voice and data interactions. It is built on a modular architecture featuring a FastAPI server that manages and orchestrates multiple specialized voice agents.
44

5-
## 1. Core Component: Pipecat Voice Agent
5+
## 1. Core Architecture
66

7-
The application's core is a standalone voice agent built on the Pipecat framework. It's launched as a subprocess by the main FastAPI server and handles the end-to-end voice conversation flow, including:
8-
* Speech-to-Text (STT)
9-
* Language Model (LLM) interaction with dynamic tool use
10-
* Text-to-Speech (TTS)
7+
The platform is built around a few key components:
8+
9+
* **FastAPI Server:** The central application that exposes API endpoints, manages agent lifecycles, and handles incoming requests.
10+
* **Voice Agents:** Specialized, independent agents responsible for handling different conversational workflows. Each agent is built using a robust framework to manage real-time communication.
11+
* **Automatic Agent:** A Pipecat-based agent designed for dynamic data retrieval and analytics conversations. It can operate in `live` mode with real-time data or `test` mode with dummy data.
12+
* **Breeze Buddy Agent:** An agent focused on telephony and workflow-driven conversations, such as order confirmations. It integrates with multiple telephony providers like Twilio and Exotel.
13+
* **Database Integration:** The application uses a database to store configuration, track calls, and manage other persistent data.
14+
* **Docker Support:** The project includes a `Dockerfile` for easy containerization and deployment.
1115

1216
## 2. Key Features
1317

14-
* **Dual-Mode Operation:** Can run in `live` mode with real-time data fetching or `test` mode using dummy data.
15-
* **Dynamic Tool Loading:** The voice agent dynamically loads tools based on the operating mode and provided credentials (e.g., Juspay and Breeze tools are only loaded in `live` mode with valid tokens).
16-
* **Multi-Provider Analytics:** Integrates with both **Juspay** and **Breeze** APIs to fetch a wide range of analytics data, including sales, orders, marketing, and checkout metrics.
17-
* **Personalized Prompts:** The agent's system prompt can be personalized with the user's name for a more engaging experience.
18-
* **Environment-Driven Configuration:** All sensitive keys and settings are managed via environment variables.
19-
* **Modular & Scalable Architecture:** The project is structured for clarity, maintainability, and easy extension with new tools or providers.
18+
* **Multi-Agent Support:** Designed to run multiple, distinct voice agents (`Automatic`, `Breeze Buddy`) within a single platform.
19+
* **Telephony Integration:** The `Breeze Buddy` agent connects with external telephony providers (Twilio, Exotel) to manage real voice calls.
20+
* **Dynamic Tool Loading:** The `Automatic` agent dynamically loads tools based on the operating mode and credentials, allowing it to interact with services like Juspay and Breeze for analytics.
21+
* **Workflow-Driven Conversations:** Agents can follow predefined workflows, such as the order confirmation process in `Breeze Buddy`.
22+
* **Environment-Driven Configuration:** All sensitive keys, API endpoints, and settings are managed via a `.env` file.
23+
* **Modular & Scalable:** The project is structured for maintainability and easy extension with new agents, tools, or services.
2024

2125
## 3. Project Structure
2226

23-
The project is organized into the main FastAPI server (`app/`) and the Pipecat voice agent (`app/agents/voice/automatic/`).
27+
The project is organized into a main FastAPI application (`app/`) with a clear separation of concerns for agents, API routing, database management, and core services.
2428

2529
```
2630
.
2731
├── app/
28-
│ ├── main.py # FastAPI app, agent endpoint, and subprocess management
29-
│ ├── api/ # API clients for Juspay, Breeze, etc.
30-
│ │ ├── juspay_metrics.py
31-
│ │ └── breeze_metrics.py
32-
│ └── agents/voice/automatic/ # Pipecat Voice Agent
33-
│ ├── __init__.py # Main agent logic, pipeline definition
34-
│ ├── prompts.py # System prompts for the agent
35-
│ └── tools/ # Tool definitions for the agent
36-
│ ├── __init__.py # Dynamic tool initializer
37-
│ ├── system/ # System tools (e.g., get_current_time)
38-
│ ├── dummy/ # Dummy tools for test mode
39-
│ ├── juspay/ # Real-time Juspay analytics tools
40-
│ └── breeze/ # Real-time Breeze analytics tools
41-
├── static/
42-
│ └── client.html # HTML client for testing
43-
├── requirements.txt
32+
│ ├── main.py # Main FastAPI application entry point
33+
│ ├── agents/
34+
│ │ └── voice/
35+
│ │ ├── automatic/ # Pipecat-based analytics agent
36+
│ │ └── breeze_buddy/ # Telephony and workflow agent
37+
│ ├── api/
38+
│ │ └── routers/ # FastAPI routers for different endpoints
39+
│ ├── core/
40+
│ │ └── config.py # Configuration and environment variable management
41+
│ ├── database/
42+
│ │ ├── accessor/ # Database access logic
43+
│ │ └── queries/ # SQL queries
44+
│ ├── scripts/
45+
│ │ └── create_tables.py # Script to initialize database tables
46+
│ └── services/
47+
│ └── langfuse/ # Integration with Langfuse for tracing
48+
├── Dockerfile # Docker configuration for containerization
49+
├── requirements.txt # Python dependencies
4450
└── run.py # Script to run the server
4551
```
4652

@@ -49,44 +55,44 @@ The project is organized into the main FastAPI server (`app/`) and the Pipecat v
4955
### Prerequisites
5056

5157
* Python 3.8+
52-
* Access to Azure OpenAI and Daily.co APIs with valid keys.
58+
* Database (e.g., PostgreSQL)
59+
* Access to required third-party APIs (e.g., Azure OpenAI, Daily.co, Twilio/Exotel) with valid keys.
5360

5461
### Installation Steps
5562

5663
1. **Clone the repository.**
57-
2. **Create and activate a virtual environment.**
64+
2. **Create and activate a virtual environment:**
65+
```bash
66+
python -m venv venv
67+
source venv/bin/activate
68+
```
5869
3. **Install dependencies:**
5970
```bash
6071
pip install -r requirements.txt
6172
```
6273
4. **Set up Environment Variables:**
63-
Create a `.env` file in the project root with the following variables:
64-
* `DAILY_API_KEY`: **Required**.
65-
* `AZURE_OPENAI_API_KEY`: **Required**.
66-
* `AZURE_OPENAI_ENDPOINT`: **Required**.
67-
* `GOOGLE_CREDENTIALS_JSON`: **Required**. Path to your Google Cloud credentials JSON file.
68-
* `GEMINI_API_KEY`: **Required** for the Gemini Live Proxy.
74+
Create a `.env` file in the project root by copying `.env.example` and filling in the required values for the database, API keys, and other configurations.
75+
5. **Initialize the Database:**
76+
Run the script to create the necessary tables in your database.
77+
```bash
78+
python -m app.scripts.create_tables
79+
```
6980

7081
## 5. Running the Server
7182

72-
Execute the `run.py` script:
83+
Execute the `run.py` script to start the FastAPI server:
7384
```bash
7485
python run.py
7586
```
7687
The server will start on `http://0.0.0.0:8000` by default.
7788

78-
## 6. How It Works: The Voice Agent Flow
79-
80-
1. A client sends a POST request to the `/agent/voice/automatic` endpoint on the FastAPI server.
81-
2. The payload includes the `mode` (`live` or `test`) and various tokens/IDs (`eulerToken`, `breezeToken`, `shopId`, etc.).
82-
3. The server creates a new Daily.co video room for the voice session.
83-
4. It then launches the Pipecat voice agent as a **new subprocess**, passing the mode, tokens, and shop details as command-line arguments.
84-
5. Inside the agent's `__init__.py`, the `initialize_tools` function is called.
85-
6. This function checks the `mode` and the presence of tokens to decide which toolsets to load:
86-
* **System tools** are always loaded.
87-
* In `test` mode, **dummy tools** are loaded.
88-
* In `live` mode, if tokens are present, the corresponding **real-time Juspay and Breeze tools** are loaded.
89-
7. The agent's system prompt is personalized with the user's name if provided.
90-
8. The agent connects to the Daily room and begins the conversation, now equipped with the appropriate set of tools for the session.
91-
92-
This architecture allows for clean separation of concerns and enables the creation of highly contextual and capable voice assistants.
89+
## 6. How It Works
90+
91+
1. The FastAPI server starts and initializes the API routers.
92+
2. When a request is made to an agent-specific endpoint (e.g., `/breeze-buddy/make-call`), the corresponding router handles it.
93+
3. The router logic invokes the appropriate agent manager or service (e.g., `CallsManager` for `Breeze Buddy`).
94+
4. The agent manager orchestrates the workflow, which may involve:
95+
* Interacting with a database to fetch configuration.
96+
* Making calls to external services (e.g., starting a call via Twilio).
97+
* Launching an agent as a subprocess to handle the real-time conversation.
98+
5. The voice agent connects to the communication service (like Daily.co or a direct telephony stream) and manages the STT -> LLM -> TTS pipeline, using its specialized tools to complete its task.

app/agents/voice/automatic/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@
1313
from pipecat.pipeline.pipeline import Pipeline
1414
from pipecat.pipeline.runner import PipelineRunner
1515
from pipecat.pipeline.task import PipelineParams, PipelineTask
16-
from app.agents.voice.automatic.services.llm_wrapper import LLMServiceWrapper
16+
from app.agents.voice.automatic.features.llm_wrapper import LLMServiceWrapper
1717
from pipecat.services.azure.llm import AzureLLMService
18-
from pipecat.transcriptions.language import Language
1918
from pipecat.frames.frames import TTSSpeakFrame, BotSpeakingFrame, LLMFullResponseEndFrame, EmulateUserStartedSpeakingFrame, EmulateUserStoppedSpeakingFrame
2019
from pipecat.transports.daily.transport import DailyParams, DailyTransport
2120
from pipecat.processors.frameworks.rtvi import RTVIConfig, RTVIProcessor
2221
from pipecat.services.google.rtvi import GoogleRTVIObserver
23-
from app.services.mem0.memory import ImprovedMem0MemoryService
22+
from app.agents.voice.automatic.services.mem0.memory import ImprovedMem0MemoryService
2423

2524
from app.core import config
2625
from app.agents.voice.automatic.utils.session_context import create_session_context, set_current_session_id

app/agents/voice/automatic/services/charts/chart_tools.py renamed to app/agents/voice/automatic/features/charts/chart_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from datetime import datetime
88

99
from app.core.logger import logger
10-
from app.agents.voice.automatic.services.charts.types.ui_components import UIComponentEvent
11-
from app.agents.voice.automatic.services.charts.utils.highlight_parser import HighlightTagParser
10+
from app.agents.voice.automatic.features.charts.types.ui_components import UIComponentEvent
11+
from app.agents.voice.automatic.features.charts.utils.highlight_parser import HighlightTagParser
1212
from app.agents.voice.automatic.utils.session_context import get_current_session_id
13+
from app.agents.voice.automatic.features.charts.session_storage import get_session_storage
1314

1415
# Color constants matching MCP implementation
1516
DEFAULT_COLORS = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b']
@@ -30,7 +31,6 @@ def get_pending_ui_components(session_id: str) -> List[UIComponentEvent]:
3031
Called by WebSocket handler to get components to emit.
3132
"""
3233
try:
33-
from app.agents.voice.automatic.services.charts.session_storage import get_session_storage
3434
storage = get_session_storage()
3535
return storage.get_pending_ui_components(session_id)
3636
except Exception as e:

app/agents/voice/automatic/services/charts/conversation.py renamed to app/agents/voice/automatic/features/charts/conversation.py

File renamed without changes.

app/agents/voice/automatic/services/charts/highlight_filter.py renamed to app/agents/voice/automatic/features/charts/highlight_filter.py

File renamed without changes.

app/agents/voice/automatic/services/charts/mcp/utils.py renamed to app/agents/voice/automatic/features/charts/mcp/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Dict, Any
22
from app.core.logger import logger
33

4-
from app.agents.voice.automatic.services.charts.chart_tools import _register_pending_chart_emission
4+
from app.agents.voice.automatic.features.charts.chart_tools import _register_pending_chart_emission
55

66

77
async def _store_ui_components_from_mcp(self, ui_components: list[Dict[str, Any]]) -> None:

app/agents/voice/automatic/services/charts/rtvi/rtvi.py renamed to app/agents/voice/automatic/features/charts/rtvi/rtvi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pipecat.processors.frameworks.rtvi import RTVIProcessor, RTVIServerMessageFrame
22

33
from app.core.logger import logger
4-
from app.agents.voice.automatic.services.charts.chart_tools import get_pending_chart_emissions
4+
from app.agents.voice.automatic.features.charts.chart_tools import get_pending_chart_emissions
55

66
async def emit_chart_components(rtvi: RTVIProcessor, function_name: str, session_id: str) -> None:
77
"""Emit chart components via RTVI frames after function calls."""

app/agents/voice/automatic/services/charts/session_storage.py renamed to app/agents/voice/automatic/features/charts/session_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
from typing import Dict, List, Any
7-
from app.agents.voice.automatic.services.charts.types.ui_components import UIComponentEvent
7+
from app.agents.voice.automatic.features.charts.types.ui_components import UIComponentEvent
88

99

1010
class SessionStorage:

app/agents/voice/automatic/services/charts/types/ui_components.py renamed to app/agents/voice/automatic/features/charts/types/ui_components.py

File renamed without changes.

app/agents/voice/automatic/services/charts/utils/highlight_parser.py renamed to app/agents/voice/automatic/features/charts/utils/highlight_parser.py

File renamed without changes.

0 commit comments

Comments
 (0)