Autogen core api based chatbot for planning trips, booking flights, hotels, car rentals, and providing destination information. The system routes user requests to specialized agents for a streamlined experience.
Router Agent: Determines user intent and routes messages. User Proxy Agent: Manages WebSocket connections between users and agents. Specialized Agents: Handles flights, hotels, car rentals, activities, and destination details. Group Chat Manager: Coordinates responses from multiple agents to provide a comprehensive travel plan.
- User Interaction: The user sends a message via the WebSocket connection managed by the UserProxyAgent.
- Routing: The UserProxyAgent forwards the message to the SemanticRouterAgent.
- Intent Classification: The SemanticRouterAgent analyzes the message to determine the user's intent.
- Agent Selection:
- If the intent maps to a single agent, the message is forwarded directly to that agent.
- If multiple agents are required, the message is sent to the GroupChatManager.
- Task Handling:
- Single Agent: The selected agent processes the request and sends a response back to the UserProxyAgent, which then sends it to the user.
- Group Chat: The GroupChatManager coordinates between multiple agents, collects their responses, and compiles a final plan. This plan is then sent back to the user via the UserProxyAgent.
- Handoff: If an agent cannot handle the request (e.g., the request is too complex), it sends a HandoffMessage back to the SemanticRouterAgent to re-route or escalate the request. #TODO
High level overview of the message flow:
git clone https://github.com/yourusername/travel-chatbot.git
cd travel-chatbot
Ensure you have Python 3.11 or higher installed. Install required packages using pip:
pip install -r requirements.txt
Create a .env
file in the backend
directory with the necessary configuration. Refer to the Configuration section for details.
uvicorn backend.app:app --host 127.0.0.1 --port 8000
Connect to the WebSocket endpoint at ws://127.0.0.1:8000/chat
to start interacting with the chatbot.
The tests
directory contains test cases to validate the functionality of the chatbot.
pytest tests/
The test_chatbot.py
script sends predefined questions to the chatbot and records responses for evaluation.
The project uses several external libraries and services:
- Azure OpenAI: For language understanding and response generation.
- Autogen Core and Extensions: For building agent-based systems.
- FastAPI: For the web server and API endpoints.
- WebSockets: For real-time communication with users.
- aiohttp: For asynchronous HTTP requests.
- Pydantic: For data validation and serialization.
- OpenTelemetry: For tracing and logging.
The application requires several environment variables to be set, which can be placed in a .env
file in the backend
directory:
# Azure OpenAI Configuration
AZURE_OPENAI_DEPLOYMENT_NAME=your-deployment-name
AZURE_OPENAI_API_VERSION=your-api-version
AZURE_OPENAI_ENDPOINT=your-openai-endpoint
AZURE_OPENAI_API_KEY=your-openai-api-key
# Bing Custom Search
BING_CUSTOM_CONFIG_ID=your-bing-config-id
BING_CUSTOM_SEARCH_KEY=your-bing-search-key
backend
: Contains the main application code.agents
: Directory containing all agent implementations.app.py
: Entry point for the FastAPI application.config.py
: Configuration settings and environment variable handling.data_types.py
: Definitions of custom data types and message formats.utils.py
: Utility functions for initializing the agent runtime.
tests
: Contains test scripts and fixtures for automated testing.
This project uses OpenTelemetry for tracing and logging. Traces are sent to local Aspire backend. Instruction on how to use OpenTelemetry with Autogen.
This project uses OpenTelemetry for tracing and logging. Traces are sent to a local Aspire backend. Follow the instructions at this link on how to use OpenTelemetry with Autogen.
A simple frontend is provided in the frontend
directory. It uses NextJs and WebSocket to communicate with the backend.