Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,8 @@ async def async_langflow_chat_stream(
yield chunk

# Add the complete assistant response to message history with response_id, timestamp, and function call data
assistant_message = None # 1. Initialize here

if full_response:
assistant_message = {
"role": "assistant",
Expand All @@ -810,10 +812,13 @@ async def async_langflow_chat_stream(
"chunks": collected_chunks, # Store complete chunk data for function calls
"error": error_occurred, # Mark if this was an error response
}

# 2. Safety check before appending
if assistant_message is not None:
# Store usage data if available (from response.completed event)
if usage_data:
assistant_message["response_data"] = {"usage": usage_data}
conversation_state["messages"].append(assistant_message)
if usage_data:
assistant_message["response_data"] = {"usage": usage_data}
conversation_state["messages"].append(assistant_message)

# Store the conversation thread with its response_id
if response_id:
Expand Down
Loading