Task3 customer simulator agent - #1
Conversation
New standalone module (models, persona/scenario config, state engine, LLM turn generation, API endpoints, log export, demo script, 16 pytest tests). Task 2 (RAG pipeline, chat, documents, support) untouched except a 2-line router registration in main.py.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
🟡 Changes recommended
The demo script currently exports logs for all completed sessions (not just those created in the run), and there are portability/reliability issues in the new docs/tests that should be corrected before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Implements Task 3 “Customer Simulator Agent” in the backend, adding configurable personas/scenarios, an emotional state engine, turn-by-turn customer response generation, and FastAPI endpoints to run simulator sessions and retrieve histories.
Changes:
- Added simulator domain libraries (personas, scenarios, state engine) and an LLM-backed turn generator with fallback behavior.
- Introduced new FastAPI
/simulatorendpoints for starting sessions, sending turns, and retrieving conversation history. - Added demo/log-export scripts plus a dedicated pytest suite for unit + integration coverage.
File summaries
| File | Description |
|---|---|
| RAG-Pipeline-backend/tests/test_simulator.py | Adds unit + API integration tests for simulator state/services/endpoints. |
| RAG-Pipeline-backend/TASK3_DELIVERABLES.md | Documents Task 3 requirements-to-implementation mapping and run commands. |
| RAG-Pipeline-backend/scripts/export_simulator_logs.py | Exports simulator sessions to JSON log files. |
| RAG-Pipeline-backend/scripts/demo_simulator_conversations.py | Runs standalone demo conversations and triggers log export. |
| RAG-Pipeline-backend/scripts/create_simulator_table.py | Creates simulator DB tables via SQLAlchemy metadata. |
| RAG-Pipeline-backend/app/services/simulator_state.py | Implements emotional state initialization and update rules. |
| RAG-Pipeline-backend/app/services/simulator_service.py | Builds prompts, calls Gemini generation, cleans output, updates state. |
| RAG-Pipeline-backend/app/services/scenario_service.py | Defines scenario templates and brief generation/validation. |
| RAG-Pipeline-backend/app/services/persona_service.py | Defines persona templates and brief generation/validation. |
| RAG-Pipeline-backend/app/models/simulator.py | Adds SQLAlchemy models for scenarios/sessions/conversations/messages. |
| RAG-Pipeline-backend/app/main.py | Registers the new simulator router. |
| RAG-Pipeline-backend/app/api/simulator.py | Implements /simulator endpoints and DB interactions. |
| RAG-Pipeline-backend/.gitignore | Ignores generated simulator logs and test DB artifacts. |
Review details
Suppressed comments (3)
RAG-Pipeline-backend/TASK3_DELIVERABLES.md:17
- These links also use local
file:///paths. Switching to repo-relative links keeps the doc usable in GitHub and in non-Windows environments.
| **Sample Conversation Logs** | [`logs/simulator/*.json`](file:///c:/Users/shrushti/Customer-Support-Assistant/RAG-Pipeline-backend/logs/simulator), generated via [`scripts/demo_simulator_conversations.py`](file:///c:/Users/shrushti/Customer-Support-Assistant/RAG-Pipeline-backend/scripts/demo_simulator_conversations.py) |
| **Test Cases Covering Customer Behaviors** | [`tests/test_simulator.py`](file:///c:/Users/shrushti/Customer-Support-Assistant/RAG-Pipeline-backend/tests/test_simulator.py) (16 automated tests via `pytest tests/test_simulator.py -v`) |
RAG-Pipeline-backend/scripts/demo_simulator_conversations.py:285
- This exports logs for all previously completed sessions in the database, not just the sessions created in this demo run. That can produce unexpected extra log files and make the output count inaccurate. Export only
completed_session_idscollected during this run.
exported_files = export_all_completed_sessions(output_dir="logs/simulator")
RAG-Pipeline-backend/tests/test_simulator.py:43
- Using a fixed
test_simulator.dbin the working directory can collide across parallel pytest workers and can leave artifacts behind if tests abort. Prefer a unique temp-file location and build the SQLite URL from the absolute path.
TEST_DB_FILE = "test_simulator.db"
TEST_DATABASE_URL = f"sqlite:///./{TEST_DB_FILE}"
- Files reviewed: 13/13 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| from app.services.simulator_service import generate_customer_turn | ||
| from app.services.simulator_state import initial_state | ||
| from app.services.scenario_service import SCENARIOS | ||
| from scripts.export_simulator_logs import export_all_completed_sessions |
| | **Customer Simulator Agent** | [`app/services/simulator_service.py`](file:///c:/Users/shrushti/Customer-Support-Assistant/RAG-Pipeline-backend/app/services/simulator_service.py) | | ||
| | **Persona and Scenario Configuration** | [`app/services/persona_service.py`](file:///c:/Users/shrushti/Customer-Support-Assistant/RAG-Pipeline-backend/app/services/persona_service.py) (6 personas) & [`app/services/scenario_service.py`](file:///c:/Users/shrushti/Customer-Support-Assistant/RAG-Pipeline-backend/app/services/scenario_service.py) (5 scenarios) | | ||
| | **Emotion / State Management** | [`app/services/simulator_state.py`](file:///c:/Users/shrushti/Customer-Support-Assistant/RAG-Pipeline-backend/app/services/simulator_state.py) (`initial_state`, `update_state`, `is_resolved`, `is_escalated`) | | ||
| | **Turn-by-Turn Response Generation** | `generate_customer_turn()` in [`app/services/simulator_service.py`](file:///c:/Users/shrushti/Customer-Support-Assistant/RAG-Pipeline-backend/app/services/simulator_service.py) | | ||
| | **API Integration** | [`app/api/simulator.py`](file:///c:/Users/shrushti/Customer-Support-Assistant/RAG-Pipeline-backend/app/api/simulator.py) (`POST /simulator/start`, `POST /simulator/message`, `GET /simulator/{session_id}/history`) | |
| from app.services.simulator_state import ( | ||
| initial_state, | ||
| update_state, | ||
| is_resolved, | ||
| is_escalated, | ||
| ) |
| import os | ||
| import sys | ||
| from unittest.mock import MagicMock | ||
| import pytest |
Summary of Changes
Implements Task 3: Customer Simulator Agent as a standalone module for agent training and realistic scenario simulations.
Deliverables Included:
calm,confused,frustrated,angry,impatient,polite) inpersona_service.pyscenario_service.pysimulator_state.pysimulator_service.pyPOST /simulator/start,POST /simulator/message,GET /simulator/{session_id}/history) inapp/api/simulator.pytests/test_simulator.pyTASK3_DELIVERABLES.mdTask 2 Integrity:
All existing Task 2 endpoints, document upload/versioning logic, search, and live support routes have been regression-tested and remain completely unaffected.