Plan: Merge driver checks & add trip modify/delete tools
TL;DR: Merge check_driver_info and check_driver_trips into a single check_driver_dashboard tool that returns driver profile, registered vehicles, and upcoming trips. Add update_driver_trip and delete_driver_trip tools (prefer soft-cancel) with schemas, handlers, DB methods, indexing calls, and tests.
Steps
Update schemas (
app/ai/tool_schemas.py):- Add
_CHECK_DRIVER_DASHBOARDforcheck_driver_dashboard(no parameters). - Add
_UPDATE_DRIVER_TRIPand_DELETE_DRIVER_TRIPforupdate_driver_tripanddelete_driver_trip. - Replace
check_driver_infoandcheck_driver_tripsentries in_TOOLS_BY_MODE["driver"]withcheck_driver_dashboard, and add the two new tool names to the driver mode list.
- Add
Implement merged handler (
app/tools/handlers.py):- Add
check_driver_dashboard(self, arguments)that:- Resolves driver by phone (existing helper), fetches registered vehicles and upcoming trips (reuse
list_driver_trips), and returns a structured JSON payload combining profile, vehicles, and trips summaries.
- Resolves driver by phone (existing helper), fetches registered vehicles and upcoming trips (reuse
- Place the method next to existing
check_driver_info/check_driver_tripslogic and remove or keep old helpers as internal functions if useful.
- Add
Implement update/delete handlers (
app/tools/handlers.py):update_driver_trip(self, arguments):- Validate
trip_idand driver ownership (get_driver_by_phone+get_trip_by_id). - Accept only allowed fields:
departure,destination,departure_date,departure_time,vehicle_type,available_seats,total_seats,price. - Call repository
update_driver_trip(trip_id, updates)and reindex the trip. - Return the updated trip record.
- Validate
delete_driver_trip(self, arguments):- Validate ownership.
- Prefer soft-cancel: call repository
cancel_driver_trip(trip_id)that setsstatus = "cancelled". - Remove/unindex from vector index and return cancelled trip.
Add DB methods (
app/database/supabase.py):async def update_driver_trip(self, trip_id: str, updates: dict) -> dict— update allowed columns and return the updated row.async def cancel_driver_trip(self, trip_id: str) -> dict— setstatustocancelled(soft delete) and return updated row.- Follow existing style/patterns used by
create_driver_tripandget_trip_by_id.
Indexing updates (
app/services/trip_indexing.py):- Add
async def unindex_trip(trip_id: str)ordelete_from_index(trip_id)to remove vectors. - Ensure
update_driver_tripcallsindex_tripafter DB update andcancel_driver_tripcallsunindex_trip.
- Add
Registration / wiring:
- No registry code changes required:
conversation_service._tool_registry()registers tools from_TOOLS_BY_MODEautomatically once names are updated.
- No registry code changes required:
Tests:
- Update
tests/conftest.pyFakeRepository to implementupdate_driver_tripandcancel_driver_tripbehaviors. - Replace or update tests that call
check_driver_info/check_driver_tripsto assert the mergedcheck_driver_dashboardbehavior intests/test_tools.py. - Add tests for
update_driver_tripanddelete_driver_tripmirroring existing handler test patterns.
- Update
Docs & prompts:
- Update
prompts/system_driver.mdto document the merged tool and the new modify/delete tools so the model calls them appropriately.
- Update
Verification
- Run unit tests:
pytest -qand ensure all tests pass (focus ontests/test_tools.py). - Run targeted tests:
pytest -q tests/test_tools.py::test_check_driver_dashboardand new tests for update/delete. - Manual local sanity: call the tool handlers via the existing orchestrator test harness in
tests/test_ai_orchestrator.py. - Verify indexing: after update, trip appears in index with new values; after cancel, it's unindexed.
Decisions & assumptions
- Use soft-cancel (
status = "cancelled") instead of hard delete to preserve audit/history and avoid breaking references. - Require driver ownership verification before allowing update/delete.
- Limit updatable fields to the set listed above; price/seats allowed, but payments/refunds are out of scope.
Further considerations
- Notifications: consider notifying booked passengers when a trip is modified/cancelled (out of scope for this change).
- Concurrency: consider optimistic locking/versioning if concurrent edits are possible.
- Permissions & audit logs: ensure handlers record who made the change (phone/driver id) for traceability.