A WebSocket-powered AI agent that provides accurate and competitive pricing quotes based on data from a Notion pricing database. This agent leverages OpenAI's GPT-4o model and integrates with external APIs to deliver real-time pricing information.
- Real-time WebSocket Communication: Interactive chat interface with instant responses
- Notion Integration: Fetches pricing data from Notion database
- Currency Conversion: Supports multi-currency quotes using live exchange rates
- Web Search Capabilities: Can research market rates and industry standards
- Session Management: Maintains conversation context across multiple interactions
- API Security: Protected endpoints with API key authentication
The system consists of two main components:
- WebSocket Agent (main.py): Core AI agent with FastAPI WebSocket server
- Streamlit Frontend (frontend.py): Optional web interface for testing
The agent is built using the openai-agents library and provides:
- Intelligent Pricing: Analyzes client requirements and suggests appropriate rates
- Tool Integration: Uses function tools for external data fetching
- Conversation Memory: Maintains context throughout the chat session
- Error Handling: Robust error management and user feedback
- Python 3.13+
- OpenAI API key
- Notion API access (optional)
- Exchange rate API key (optional)
- Clone the repository:
git clone <repository-url>
cd quotation-agent- Install dependencies:
pip install -r requirements.txt- Configure environment variables in .env:
OPENAI_API_KEY=your_openai_api_key
API_KEY=your_api_security_key
NOTION_API_KEY=your_notion_api_key
NOTION_PAGE_ID=your_notion_page_id
EXCHANGE_RATE_API_KEY=your_exchange_rate_api_key- Run the WebSocket server:
uvicorn main:app --host 0.0.0.0 --port 8000Connect to the WebSocket endpoint:
ws://localhost:8000/ws/chat
Send messages as JSON with the following structure:
{
"session_id": "unique-session-id",
"message": "I need a quote for my project requirements",
"user_id": "user123",
"timestamp": "2024-01-01T10:00:00Z",
"message_type": "chat"
}Receive responses in the following format:
{
"session_id": "unique-session-id",
"message": "Based on your requirements...",
"sender": "agent",
"timestamp": "2024-01-01T10:00:01Z",
"message_type": "response",
"success": true,
"error": null
}- Send
"/clear"or setmessage_type: "clear"to reset conversation history
The agent has access to several function tools:
- Function:
get_pricing_from_notion - Purpose: Fetches current pricing information from Notion database
- Integration: Uses Notion API to retrieve structured pricing data
- Function:
currency_conversion - Purpose: Converts prices between different currencies
- API: Uses exchangerate-api.com for live exchange rates
- Tool:
WebSearchTool() - Purpose: Researches market rates and industry standards
- Usage: Helps provide competitive pricing context
GET /
Returns API status (requires API key authentication)
POST /clear-chat
Clears the global conversation history
The project includes a Dockerfile for containerized deployment:
# Build the image
docker build -t quotation-agent .
# Run the container
docker run -p 8000:8000 --env-file .env quotation-agent{
"session_id": "session123",
"message": "I need a quote for my project requirements",
"message_type": "chat"
}{
"session_id": "session123",
"message": "What would this cost in USD?",
"message_type": "chat"
}{
"session_id": "session123",
"message": "Can you break down the pricing for each deliverable?",
"message_type": "chat"
}An optional Streamlit frontend is provided for testing:
streamlit run frontend.pyAccess the web interface at http://localhost:8501
The agent works with pricing data from pricing.txt as its source of information. This document contains structured pricing information that the agent uses to generate accurate quotes.
Key configuration options in main.py:
- Model: GPT-4o for optimal reasoning
- Session Management: UUID-based session tracking
- Error Handling: Comprehensive exception management
- API Security: Header-based authentication
- Fork the repository
- Create a feature branch
- Make your changes
- Test with the WebSocket API
- Submit a pull request
This project is licensed under the MIT License.
Built with β€οΈ by Tom Shaw