diff --git a/autogpt_platform/backend/backend/api/features/chat/response_model.py b/autogpt_platform/backend/backend/api/features/chat/response_model.py index e04218ea87..07849d02da 100644 --- a/autogpt_platform/backend/backend/api/features/chat/response_model.py +++ b/autogpt_platform/backend/backend/api/features/chat/response_model.py @@ -138,6 +138,7 @@ class StreamToolOutputAvailable(StreamBaseResponse): def to_sse(self) -> str: """Convert to SSE format, excluding non-spec fields.""" import json + data = { "type": self.type.value, "toolCallId": self.toolCallId, @@ -145,6 +146,7 @@ class StreamToolOutputAvailable(StreamBaseResponse): } return f"data: {json.dumps(data)}\n\n" + # ========== Other ========== diff --git a/autogpt_platform/backend/backend/api/features/chat/routes.py b/autogpt_platform/backend/backend/api/features/chat/routes.py index 2cb17ae397..9b021c0601 100644 --- a/autogpt_platform/backend/backend/api/features/chat/routes.py +++ b/autogpt_platform/backend/backend/api/features/chat/routes.py @@ -37,7 +37,6 @@ from .tools.models import ( OperationInProgressResponse, OperationPendingResponse, OperationStartedResponse, - ResponseType, SetupRequirementsResponse, UnderstandingUpdatedResponse, ) diff --git a/autogpt_platform/backend/backend/api/features/chat/service.py b/autogpt_platform/backend/backend/api/features/chat/service.py index b64487bd15..501721fc41 100644 --- a/autogpt_platform/backend/backend/api/features/chat/service.py +++ b/autogpt_platform/backend/backend/api/features/chat/service.py @@ -351,7 +351,9 @@ async def stream_chat_completion( retry_count: int = 0, session: ChatSession | None = None, context: dict[str, str] | None = None, # {url: str, content: str} - _continuation_message_id: str | None = None, # Internal: reuse message ID for tool call continuations + _continuation_message_id: ( + str | None + ) = None, # Internal: reuse message ID for tool call continuations ) -> AsyncGenerator[StreamBaseResponse, None]: """Main entry point for streaming chat completions with database handling. @@ -480,13 +482,10 @@ async def stream_chat_completion( # Generate unique IDs for AI SDK protocol import uuid as uuid_module - # Reuse message ID for continuations (tool call follow-ups) to avoid duplicate messages is_continuation = _continuation_message_id is not None message_id = _continuation_message_id or str(uuid_module.uuid4()) text_block_id = str(uuid_module.uuid4()) - # Only yield message start for the initial call, not for continuations - # This prevents the AI SDK from creating duplicate message objects if not is_continuation: yield StreamStart(messageId=message_id)