diff --git a/examples/customer-support/backend/app/airline_state.py b/examples/customer-support/backend/app/airline_state.py index eaa83287..9f9d9656 100644 --- a/examples/customer-support/backend/app/airline_state.py +++ b/examples/customer-support/backend/app/airline_state.py @@ -120,10 +120,12 @@ def change_seat(self, thread_id: str, flight_number: str, seat: str) -> str: ) return f"Seat updated to {segment.seat} on flight {segment.flight_number}." - def cancel_trip(self, thread_id: str) -> str: + def cancel_trip(self, thread_id: str, flight_number: str) -> str: profile = self.get_profile(thread_id) - for segment in profile.segments: - segment.cancel() + segment = self._find_segment(profile, flight_number) + if segment is None: + raise ValueError(f"Flight {flight_number} is not on the customer's itinerary.") + segment.cancel() profile.log("Trip cancelled at customer request.", kind="warning") return "The reservation has been cancelled. Refund processing will begin immediately." diff --git a/examples/customer-support/backend/app/support_agent.py b/examples/customer-support/backend/app/support_agent.py index b8ac0f4c..47e5b8e2 100644 --- a/examples/customer-support/backend/app/support_agent.py +++ b/examples/customer-support/backend/app/support_agent.py @@ -29,7 +29,7 @@ Available tools: - change_seat(flight_number: str, seat: str) – move the passenger to a new seat. -- cancel_trip() – cancel the upcoming reservation and note the refund. +- cancel_trip(flight_number: str) – cancel the upcoming reservation and note the refund. - add_checked_bag() – add one checked bag to the itinerary. - meal_preference_list() – show meal options so the traveller can pick their preference. Invoke this tool when the user requests to set or change their meal preference or option. @@ -63,8 +63,11 @@ async def change_seat( @function_tool( description_override="Cancel the traveller's upcoming trip and note the refund.", ) - async def cancel_trip(ctx: RunContextWrapper[AgentContext]) -> Dict[str, str]: - message = state_manager.cancel_trip(_thread_id(ctx)) + async def cancel_trip(ctx: RunContextWrapper[AgentContext], flight_number: str) -> Dict[str, str]: + try: + message = state_manager.cancel_trip(_thread_id(ctx), flight_number) + except ValueError as exc: # translate user errors + raise ValueError(str(exc)) from exc return {"result": message} @function_tool(