Replace [DEEP RESEARCH] content tag with explicit mode and research_iteration fields#552
Replace [DEEP RESEARCH] content tag with explicit mode and research_iteration fields#552GdoongMathew wants to merge 2 commits into
mode and research_iteration fields#552Conversation
…al conversation mode.
There was a problem hiding this comment.
Code Review
This pull request replaces the string-based [DEEP RESEARCH] tag detection with a structured mode field ("normal" or "deep_research") on chat messages across both backend and frontend files. However, there is a bug in the reverse traversal logic used to count the deep research streak in api/simple_chat.py and api/websocket_wiki.py. If a conversation contains a previous turn in normal mode, the loop will incorrectly increment the streak count before reaching the user message that should break the loop. Suggestions have been provided to traverse the messages chronologically to correctly track and reset the streak.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| current_streak = 0 | ||
| for msg in reversed(request.messages): | ||
| if msg.role == "user" and msg.mode != "deep_research": | ||
| break | ||
| if msg.role == "assistant": | ||
| current_streak += 1 |
There was a problem hiding this comment.
There is a bug in the reverse traversal logic when counting the deep research streak. If the conversation contains a previous turn in 'normal' mode (e.g., User (normal) -> Assistant -> User (deep_research)), the loop will encounter the previous assistant message and increment current_streak before it reaches the previous user message to break the loop. This incorrectly inflates the iteration count.
To fix this, we can traverse the messages chronologically (forward) and track the active mode, resetting the streak if we exit deep research.
| current_streak = 0 | |
| for msg in reversed(request.messages): | |
| if msg.role == "user" and msg.mode != "deep_research": | |
| break | |
| if msg.role == "assistant": | |
| current_streak += 1 | |
| current_streak = 0 | |
| in_deep_research = False | |
| for msg in request.messages: | |
| if msg.role == "user": | |
| in_deep_research = msg.mode == "deep_research" | |
| if not in_deep_research: | |
| current_streak = 0 | |
| elif msg.role == "assistant" and in_deep_research: | |
| current_streak += 1 |
| current_streak = 0 | ||
| for msg in reversed(request.messages): | ||
| if msg.role == "user" and msg.mode != "deep_research": | ||
| break | ||
| if msg.role == "assistant": | ||
| current_streak += 1 |
There was a problem hiding this comment.
There is a bug in the reverse traversal logic when counting the deep research streak. If the conversation contains a previous turn in 'normal' mode (e.g., User (normal) -> Assistant -> User (deep_research)), the loop will encounter the previous assistant message and increment current_streak before it reaches the previous user message to break the loop. This incorrectly inflates the iteration count.
To fix this, we can traverse the messages chronologically (forward) and track the active mode, resetting the streak if we exit deep research.
| current_streak = 0 | |
| for msg in reversed(request.messages): | |
| if msg.role == "user" and msg.mode != "deep_research": | |
| break | |
| if msg.role == "assistant": | |
| current_streak += 1 | |
| current_streak = 0 | |
| in_deep_research = False | |
| for msg in request.messages: | |
| if msg.role == "user": | |
| in_deep_research = msg.mode == "deep_research" | |
| if not in_deep_research: | |
| current_streak = 0 | |
| elif msg.role == "assistant" and in_deep_research: | |
| current_streak += 1 |
mode field to determine deep_research mode or normal conversation modemode and research_iteration fields
Summary
Deep Research mode and its iteration count were previously inferred from message content — a [DEEP RESEARCH] string was prepended to the message, and the backend counted messages to derive the iteration. This replaces both with explicit, typed request fields, removing all string-parsing and message-counting heuristics.
Backend
ChatMessagegainsmode: Literal["normal", "deep_research"](default to"normal")ChatCompletionRequestgainsresearch_iteration: int (defaults to 1, ge=1).simple_chat.py/websocket_wiki.py:request.research_iterationinstead of counting assistant turns, so a brand-new deep research question always restarts at iteration 1 regardless of prior history.Frontend
ChatMessage/Messageinterfaces gain an optionalmodefieldChatCompletionRequestgains an optionalresearch_iterationfield.Ask.tsxnow sets mode:deep_researchinstead of prefixing content with the tag, and sendsresearch_iterationexplicitly (1 on initial submit, the incremented value on auto-continue).