Skip to content

Commit a9c32c4

Browse files
authored
fix: Improve frontend UX & consistent message history (#545)
This PR fixes issue causing different messages to show up on decline ticket before and after page refresh. We now return the actual response from the LLM instead of a hardcoded response in case of LangGraph. This PR also removes unused `config` parameter from graph nodes, and an unused hardcoded booking decline AI message.
1 parent b122892 commit a9c32c4

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

agent/react_graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def agent_should_continue(
115115
# Otherwise, we stop (reply to the user)
116116
return "end"
117117

118-
async def booking_validation_node(state: UserState, config: RunnableConfig):
118+
async def booking_validation_node(state: UserState):
119119
"""
120120
The node representing async function that validate the ticket.
121121
After ticket validation, it will return AIMessage with updated ticket args.
@@ -154,7 +154,7 @@ def booking_should_continue(state: UserState) -> Literal["continue", "agent"]:
154154
# Otherwise, send response back to agent
155155
return "agent"
156156

157-
async def insert_ticket_node(state: UserState, config: RunnableConfig):
157+
async def insert_ticket_node(state: UserState):
158158
"""
159159
Node to update human response to prevent
160160
"""

app.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,16 @@ async def decline_flight(request: Request):
192192
# Note in the history, that the ticket was not booked
193193
# This is helpful in case of reloads so there doesn't seem to be a break in communication.
194194
agent = request.app.state.agent
195-
await agent.user_session_decline_ticket(request.session["uuid"])
195+
response = await agent.user_session_decline_ticket(request.session["uuid"])
196+
response = response["output"]
196197
request.session["history"].append(
197198
{"type": "ai", "data": {"content": "Please confirm if you would like to book."}}
198199
)
199200
request.session["history"].append(
200201
{"type": "human", "data": {"content": "I changed my mind."}}
201202
)
202-
return None
203+
request.session["history"].append({"type": "ai", "data": {"content": response}})
204+
return response
203205

204206

205207
@routes.post("/reset")

static/index.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ div.chat-wrapper div.chat-content div#loader-container span {
363363
#trace {
364364
position: absolute;
365365
width: 400px;
366-
min-height: 200px;
367366
max-height: 400px;
368367
background: #f8f8f8;
369368
padding: 10px;

static/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,14 @@ async function cancelTicket(id) {
262262
'Content-Type': 'application/json'
263263
}
264264
});
265+
logMessage("human", "I changed my mind.")
266+
removeTicketChoices(id);
267+
265268
if (response.ok) {
266-
logMessage("human", "I changed my mind.")
267-
removeTicketChoices(id);
268-
logMessage("ai", 'Booking declined. What else can I help you with?');
269+
logMessage("ai", await response.text());
270+
} else {
271+
console.error(await response.text())
272+
logMessage("ai", "Sorry, something went wrong. 😢")
269273
}
270274
}
271275

static/trace.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ export function create_trace(toolcalls) {
2222
let toolcall = toolcalls[i];
2323
trace += trace_section_title(toolcall.tool_call_id);
2424

25+
if (toolcall.sql) {
2526
trace += trace_header("SQL Executed:");
2627
trace += trace_sql(toolcall.sql);
28+
}
2729
trace += trace_header("Results:");
2830
trace += trace_results(toolcall.results);
2931

0 commit comments

Comments
 (0)