Skip to content

Replace [DEEP RESEARCH] content tag with explicit mode and research_iteration fields#552

Open
GdoongMathew wants to merge 2 commits into
AsyncFuncAI:mainfrom
GdoongMathew:refactor/mode
Open

Replace [DEEP RESEARCH] content tag with explicit mode and research_iteration fields#552
GdoongMathew wants to merge 2 commits into
AsyncFuncAI:mainfrom
GdoongMathew:refactor/mode

Conversation

@GdoongMathew

@GdoongMathew GdoongMathew commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

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

  • ChatMessage gains mode: Literal["normal", "deep_research"] (default to "normal")
  • ChatCompletionRequest gains research_iteration: int (defaults to 1, ge=1).
  • simple_chat.py / websocket_wiki.py:
    • The active mode is now read directly from the last message (last_message.mode), which is guaranteed to be the user's current turn — no more scanning/stripping the [DEEP RESEARCH] tag.
    • The deep research iteration is now taken from request.research_iteration instead of counting assistant turns, so a brand-new deep research question always restarts at iteration 1 regardless of prior history.

Frontend

  • ChatMessage / Message interfaces gain an optional mode field
  • ChatCompletionRequest gains an optional research_iteration field.
  • Ask.tsx now sets mode: deep_research instead of prefixing content with the tag, and sends research_iteration explicitly (1 on initial submit, the incremented value on auto-continue).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread api/simple_chat.py Outdated
Comment on lines +126 to +131
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed in 3e41900

Comment thread api/websocket_wiki.py Outdated
Comment on lines +129 to +134
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed in 3e41900

@GdoongMathew
GdoongMathew marked this pull request as draft July 20, 2026 09:18
@GdoongMathew
GdoongMathew marked this pull request as ready for review July 20, 2026 09:45
@GdoongMathew GdoongMathew changed the title Add mode field to determine deep_research mode or normal conversation mode Replace [DEEP RESEARCH] content tag with explicit mode and research_iteration fields Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant