A tool for simulating conversations between an AI assistant and a virtual user for testing and development purposes.
This project allows you to:
- Test AI assistant behavior with a simulated user
- Configure both the AI assistant and simulated user personas
- Run automated conversations to evaluate AI performance
- Track conversations with LangSmith threads for observability
- Save conversation history to JSON files for analysis and review
- Python 3.8+
- OpenAI API key
- LangSmith API key (optional, for thread tracking)
- Clone this repository
git clone https://github.com/yourusername/ai-conversation-simulator.git
cd ai-conversation-simulator
- Install dependencies
Using uv (recommended for faster installation):
# Install uv if you don't have it - https://docs.astral.sh/uv/getting-started/installation/
# Create and activate virtual environment
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
uv pip install -r requirements.txt
Using pip (alternative):
# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
- Create a
.env
file with your API keys
OPENAI_API_KEY=your_openai_api_key
# Optional: For LangSmith thread tracking
LANGSMITH_API_KEY=your_langsmith_api_key
LANGSMITH_PROJECT=your_langsmith_project_name
LANGSMITH_TRACING=true
Run a simulated conversation:
python simulate_conversation.py
The simulation will:
- Create a conversation between your AI assistant and a simulated user
- Continue until the maximum message count or until the user says "FINISHED"
- Save the conversation to a file in the
runs
directory - Create a thread in LangSmith for tracking and analysis
Modify config_simulate_conversation.py
to customize:
SYSTEM_PROMPT
: The system prompt for your AI assistantSYSTEM_MODEL
: The OpenAI model for your AI assistantSIMULATED_USER_PROMPT
: The persona for the simulated userSIMULATED_USER_MODEL
: The OpenAI model for the simulated userMAX_MESSAGES
: Maximum number of messages before ending the conversation
The simulator uses LangGraph to create a conversation flow between:
- Your AI assistant (configurable system prompt and model)
- A simulated user (configurable persona and model)
All conversations are saved to JSON files in the runs
directory with:
- Complete conversation history
- Configuration settings used for the simulation
- Role information (AI assistant vs simulated user)
- Timestamp and unique identifiers
When LangSmith integration is enabled:
- Each conversation is tracked as a thread in LangSmith
- Thread IDs are included in saved files for reference
- You can view detailed conversation analytics in the LangSmith UI
- Go to LangSmith
- Navigate to your project
- Click on the "Threads" tab to see all your conversation threads
- Click on a thread to see the detailed conversation history
You can modify the my_chat_bot
function in simulate_conversation.py
to test different AI assistant implementations.
Contributions are welcome! Please feel free to submit a Pull Request.