From a904db62204bd7f431c16dbc62089d025109d9c0 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Fri, 2 May 2025 13:23:07 -0400 Subject: [PATCH] fix: Agent execution time duration display in streaming mode (#7852) * Update events.py * timer compotation update * clean up * add time elapsed for streaming * [autofix.ci] apply automated fixes * Update events.py * preliminary fix * Update src/backend/base/langflow/schema/message.py Co-authored-by: Gabriel Luiz Freitas Almeida * Update src/backend/base/langflow/schema/message.py Co-authored-by: Gabriel Luiz Freitas Almeida --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida --- src/backend/base/langflow/base/agents/events.py | 3 ++- src/backend/base/langflow/schema/message.py | 2 ++ .../IOModal/components/chatView/chatMessage/chat-message.tsx | 1 - 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/base/agents/events.py b/src/backend/base/langflow/base/agents/events.py index a3846af8a..7fc14eb7c 100644 --- a/src/backend/base/langflow/base/agents/events.py +++ b/src/backend/base/langflow/base/agents/events.py @@ -231,7 +231,8 @@ async def handle_on_chain_stream( agent_message.text += output_text agent_message.properties.state = "partial" agent_message = await send_message_method(message=agent_message) - start_time = perf_counter() + if not agent_message.text: + start_time = perf_counter() return agent_message, start_time diff --git a/src/backend/base/langflow/schema/message.py b/src/backend/base/langflow/schema/message.py index 9519d0d9b..8b276ef5a 100644 --- a/src/backend/base/langflow/schema/message.py +++ b/src/backend/base/langflow/schema/message.py @@ -51,6 +51,7 @@ class Message(Data): properties: Properties = Field(default_factory=Properties) category: Literal["message", "error", "warning", "info"] | None = "message" content_blocks: list[ContentBlock] = Field(default_factory=list) + duration: int | None = None @field_validator("flow_id", mode="before") @classmethod @@ -306,6 +307,7 @@ class MessageResponse(DefaultModel): text: str files: list[str] = [] edit: bool + duration: float | None = None properties: Properties | None = None category: str | None = None diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatMessage/chat-message.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatMessage/chat-message.tsx index cfc62dbc4..6f4538545 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatMessage/chat-message.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatMessage/chat-message.tsx @@ -327,7 +327,6 @@ export default function ChatMessage({ playgroundPage={playgroundPage} contentBlocks={chat.content_blocks} isLoading={ - chatMessage === "" && chat.properties?.state === "partial" && isBuilding && lastMessage