EnergiQ AI EV Assistant
An end-to-end OpenAI-powered AI agent developed for the EnergiQ platform to address electric vehicle and charging inquiries for 7,000 users. Built with FastAPI and LangChain, it utilizes a custom database function-calling framework, a high-recall RAG pipeline, and real-time voice chat capabilities.
Problem Statement
Electric vehicle owners and platform users face difficulty navigating fragmented charging session data, transaction histories, and complex EV specs. Standard dashboards require multiple clicks, while generic chatbots lack secure access to user databases and suffer from hallucinations when asked technical questions about chargers and connector types.
Solution
Built a voice-enabled, agentic AI assistant integrated into the EnergiQ platform. Implemented a function-calling framework that securely queries the PostgreSQL backend database to retrieve user-specific metrics, alongside a Retrieval-Augmented Generation (RAG) system using internal documentation for EV inquiries. Wrapped the system in a low-latency FastAPI /voice endpoint using OpenAI's Whisper and TTS APIs.
Architecture
The assistant functions as a core service in a FastAPI backend, orchestrating user requests, database queries via SQLAlchemy, document indexing with LangChain RAG, and voice interfaces with OpenAI Whisper and TTS APIs.
Key Features
- ▸End-to-end OpenAI-powered AI agent supporting multi-turn conversations
- ▸SQL-based function calling framework for real-time user charging metrics
- ▸RAG pipeline indexing documentation on EV specs, chargers, and platform FAQs
- ▸Unified voice chat endpoint (/voice) for full-duplex speech interaction
- ▸Context injection including user details and dynamic datetime handling
- ▸Provider-level analytics generation from users, sessions, and vehicle metadata
Challenges
- ⚡Designing a robust function-calling router to accurately determine when to query the database versus looking up documentation.
- ⚡Minimizing end-to-end latency for speech-to-text-to-speech loops to ensure conversational flow.
- ⚡Preventing database injection and securing user privacy by filtering context and constraining SQL outputs.
Results & Metrics
Targeted and tested for 7,000 active electric vehicle platform users
Attained F1-score of 0.94 in Intent Accuracy for database function-calling
Achieved Recall@3 = 0.95 in RAG document retrieval for EV queries
Reduced audio inference latency to 78 ms/token for real-time voice chat
Lessons Learned
- 💡Strict prompt constraints and few-shot formatting are key to preventing model deviations during tool selection.
- 💡Pre-processing audio input on the client-side and streaming fragments can further optimize Whisper API response times.
- 💡Abstracting database queries into clean ORM methods ensures security and simplifies function schemas.
Case Study Overview
Case Study: Building the EnergiQ AI EV Assistant
In the rapidly evolving electric vehicle (EV) sector, user experience and data accessibility are critical. Drivers need quick answers about their charging status, transaction histories, and energy consumption, while also seeking instant support for technical charging issues.
The EnergiQ AI EV Assistant was built to solve these needs by delivering a voice-enabled, conversational agent integrated directly into the EnergiQ platform.
System Architecture & Workflow
The assistant functions as a highly integrated service within the FastAPI backend of the EnergiQ platform. It orchestrates user input processing, database interaction, document retrieval, and speech synthesis:
Request & Processing Flow
- User Input: The user interacts with the system via voice (audio payload) or text.
- Audio Transcription: If audio is received, the FastAPI backend routes it to OpenAI's Whisper-1 model for speech-to-text transcription.
- Intent Routing: The LLM analyzes the query to determine the intent and required context.
- Data Retrieval:
- Database Queries: If requesting metrics, the agent executes Python tools via SQL function-calling against the PostgreSQL database.
- Knowledge Queries: If asking general EV questions, the agent queries the vector database for document chunks using the RAG pipeline.
- Response Generation: The agent constructs a final grounded response.
- Voice Synthesis: If voice mode is active, the text is synthesized into audio using OpenAI's TTS-1 and streamed back to the user.
Core Engineering Implementations
1. Intent Routing & Function Calling Framework
To securely interface the agent with the user database, we established a robust function-calling mechanism using OpenAI’s tool definitions.
- Database Integration: The agent is equipped with specific tools such as:
getMonthlySpending(userId, year, month): Calculates the monthly charging costs.getAvgSessionStats(userId): Returns average duration and energy charged.getNearestStations(latitude, longitude, radius): Finds charging stations dynamically.
- Security & Constraints: To prevent unauthorized access, user context (e.g.,
userId) is injected on the backend server side and is not exposed to client-side input parameters. - Performance: Evaluation on sample queries yielded an Intent Accuracy F1-score of 0.94, ensuring users get correct information without wrong database queries.
2. High-Recall RAG (Retrieval-Augmented Generation) Pipeline
For general knowledge inquiries (e.g., "What is the difference between a CCS and a CHAdeMO connector?"), we implemented a LangChain-powered RAG pipeline:
- Document Processing: Internal documentation, platform FAQs, and EV specs were chunked and embedded using OpenAI's text embeddings.
- Contextual Retrieval: During runtime, a custom retriever fetches relevant document chunks. The prompt is dynamically populated with these chunks to ground the LLM's answers.
- Metrics: The retrieval configuration was fine-tuned to achieve a Recall@3 of 0.95, virtually eliminating hallucinations for platform-related FAQs.
3. Latency-Optimized Voice Chat Endpoint
A core feature of the assistant is the low-latency /voice endpoint, allowing full speech-to-speech interaction.
- Speech-to-Text: Incoming WAV/MP3 files are routed to OpenAI's
whisper-1engine. - Text-to-Speech: The generated textual response is synthesized into natural-sounding speech using OpenAI's
tts-1model. - Inference Optimization: By optimizing payload sizes, connection reuse, and response stream formatting, the end-to-end token generation latency was minimized to 78 ms/token, enabling an interactive voice conversational flow.
Deployment & Scale
The backend is written in FastAPI, using SQLAlchemy ORM for PostgreSQL queries, and deployed on Railway. The service is configured to handle scaling loads targeting 7,000 active users across the EnergiQ EV management platform.
Technologies
Gallery



Links
Related Projects
CareFlow AI Clinical Assistant
An end-to-end multi-modal clinical copilot platform integrating Arabic ASR, MedGemma VLM, MedSAM 2.0 segmentation, and BGE-M3 RAG to automate patient history taking and clinical decision support.