fix(c-a2ui): seed booking form origin/dest from prompt to ensure happy path#467
Merged
Conversation
…y path
The welcome chips ("I want to fly LAX to JFK", "I want to fly SFO to
SEA") trigger build_form, but on a fresh first turn the form's
data_model carries blank defaults — and the LLM occasionally extracts
the wrong values from the prompt (commonly sets both origin AND dest
to LAX, which finds zero flights because the in-memory _FLIGHTS dataset
has no same-airport routes).
Add a deterministic regex pre-pass: `_seed_airports_from_messages`
walks the message history for the most recent human prompt and
extracts an (origin, dest) airport pair when the prompt explicitly
names one ("LAX to JFK" / "lax → jfk" / "SFO -> SEA"). build_form
uses those values to seed the form's data_model whenever there's no
prior bookingSubmit context to draw from. The LLM still authors the
spec but the field defaults are now correct.
Guard rails:
- Only matches IATA codes that appear in AIRPORT_CODES — never seeds
an airport the form's dropdown can't render
- Same-origin/dest pairs (LAX → LAX) are skipped (no flights match)
- Only inspects human-role messages; action-message JSON and AI
surfaces are filtered out
- Prior-context path is unchanged: a Modify-search after a real submit
still prefills from the submitted values, not the original prompt
Verified end-to-end via real-LLM smoke:
HumanMessage('I want to fly LAX to JFK')
→ form data_model = {origin: LAX, dest: JFK, ...}
→ bookingSubmit with LAX/JFK
→ results surface contains UA123 (the LAX→JFK flight in _FLIGHTS)
Plus 11 unit cases for the seed helper: chip prompts, arrow notation,
case-insensitive, same-airport guard, unknown airports, AI-message
filter, action-JSON filter, most-recent-wins.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The welcome chips ('I want to fly LAX to JFK', 'I want to fly SFO to SEA') trigger build_form, but on a fresh first turn the form's data_model carries blank defaults — and the LLM occasionally extracts the wrong values from the prompt (commonly sets both origin AND dest to LAX, which finds zero flights because the in-memory _FLIGHTS dataset has no same-airport routes).
Result: user clicks a chip → sees a form → clicks Search → empty results bubble. Failure path is the default path.
Fix
Deterministic regex pre-pass
_seed_airports_from_messageswalks the message history for the most recent human prompt and extracts an (origin, dest) IATA pair when the prompt explicitly names one ('LAX to JFK' / 'lax → jfk' / 'SFO -> SEA'). build_form seeds the form's data_model with those values whenever there's no prior bookingSubmit context to draw from.The LLM still authors the spec; only the field default values get pre-filled deterministically.
Guard rails
AIRPORT_CODES— never seeds an airport the form's dropdown can't renderFiles
cockpit/chat/a2ui/python/src/graph.py—_seed_airports_from_messageshelper + one-line call inbuild_formTest plan
→and->), case-insensitive, same-airport guard, unknown airports, AI-message filter, action-JSON filter, most-recent-winsnpx nx run cockpit-chat-a2ui-python:build— green🤖 Generated with Claude Code