Skip to content

Conversation

@ngoiyaeric
Copy link
Collaborator

@ngoiyaeric ngoiyaeric commented Aug 25, 2025

User description

This commit addresses an issue where the system would not generate a response if a query did not trigger any tool usage while useSpecificAPI was enabled.

The fix involves two changes:

  1. The while loop condition in app/actions.tsx has been modified to remove the dependency on toolOutputs.length. This ensures that the application waits for a response (answer) to be generated, regardless of whether tools are used.
  2. The system prompt for the researcher agent in lib/agents/researcher.tsx has been enhanced to explicitly instruct the AI to provide a direct answer when no tools are necessary.

PR Type

Bug fix


Description

  • Fix response generation when no tools are used

  • Remove tool dependency from loop condition

  • Add explicit instruction for direct answers


Diagram Walkthrough

flowchart LR
  A["Query Input"] --> B["Check Tool Usage"]
  B --> C["Modified Loop Condition"]
  C --> D["Generate Response"]
  E["Enhanced System Prompt"] --> D
  D --> F["Response Output"]
Loading

File Walkthrough

Relevant files
Bug fix
actions.tsx
Remove tool dependency from loop condition                             

app/actions.tsx

  • Modified while loop condition to remove toolOutputs.length === 0
    dependency
  • Ensures response generation regardless of tool usage
+1/-1     
researcher.tsx
Add direct answer instruction to system prompt                     

lib/agents/researcher.tsx

  • Added instruction to provide direct answers when tools aren't needed
  • Enhanced system prompt for better handling of non-tool queries
+1/-0     

Summary by CodeRabbit

  • New Features

    • Added support for a dynamic system prompt to tailor the assistant’s behavior per request.
    • Improved default assistant behavior: provides direct answers when tools aren’t needed, cites tool-derived sources, and matches the user’s language.
  • Bug Fixes

    • Improved submission flow to ensure responses continue until a complete answer is produced, reducing instances of partial or stalled replies.

This commit addresses an issue where the system would not generate a response if a query did not trigger any tool usage while `useSpecificAPI` was enabled.

The fix involves two changes:

1.  The `while` loop condition in `app/actions.tsx` has been modified to remove the dependency on `toolOutputs.length`. This ensures that the application waits for a response (`answer`) to be generated, regardless of whether tools are used.
2.  The system prompt for the `researcher` agent in `lib/agents/researcher.tsx` has been enhanced to explicitly instruct the AI to provide a direct answer when no tools are necessary.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@vercel
Copy link
Contributor

vercel bot commented Aug 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
qcx Ready Ready Preview Comment Aug 25, 2025 0:46am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 25, 2025

Walkthrough

Updates adjust the submit loop condition in app/actions.tsx to wait solely for an answer. The researcher agent now accepts a dynamic system prompt, removes the mcp parameter, and prefers the provided prompt over the default. Tool acquisition aligns with the signature change. No other public APIs changed.

Changes

Cohort / File(s) Change Summary
Submit loop condition update
app/actions.tsx
While-loop now continues until answer.length === 0 (removes dependency on toolOutputs.length), leaving tool handling logic unchanged. No exported/public signature changes.
Researcher API and prompt selection
lib/agents/researcher.tsx
Function signature changed: added dynamicSystemPrompt: string, removed mcp. System prompt now selects dynamicSystemPrompt if provided; otherwise uses default. Default prompt expanded with guidance for non-tool answers, citation, and language matching. Internal getTools updated to reflect removal of mcp.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant A as submit()
  participant R as researcher()
  participant T as Tools
  participant M as Model
  participant UI as uiStream/streamText

  U->>A: Trigger submit
  rect rgba(200,230,255,0.3)
    note right of A: Loop until answer is produced<br/>(condition: answer.length === 0)
    A->>R: researcher(dynamicSystemPrompt, uiStream, streamText, messages, useSpecificModel?)
    R->>R: Select systemToUse = dynamicSystemPrompt or default
    alt Tools required
      R->>T: getTools() (no mcp)
      T-->>R: tool handles
      R->>M: Stream with tools + systemToUse
    else Direct answer
      R->>M: Stream with systemToUse (no tools)
    end
    M-->>R: Tokens / tool calls
    R-->>A: Streamed content and tool outputs
  end
  A->>UI: Update streamed UI
  UI-->>U: Rendered answer
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Review effort 3/5

Poem

I twitch my whiskers, tap-tap—compile!
A prompt hops in, dynamic style.
No mcp, just clearer trails,
Loops now wait till answer sails.
Carrot-shaped cursors blink in delight—
Tools or not, we get it right.
Thump-thump, ship tonight! 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7f95c58 and 0add2cd.

📒 Files selected for processing (2)
  • app/actions.tsx (1 hunks)
  • lib/agents/researcher.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
lib/agents/researcher.tsx (3)
lib/agents/writer.tsx (1)
  • writer (7-48)
components/settings/components/settings.tsx (1)
  • fetchPrompt (81-86)
lib/actions/chat.ts (2)
  • getSystemPrompt (239-254)
  • saveSystemPrompt (218-237)
🔇 Additional comments (3)
app/actions.tsx (1)

178-195: No additional streamText.done() required
The writer function in lib/agents/writer.tsx already invokes streamText.done() before returning (see line 45), so the stream is finalized internally. The extra finalization after calling writer(...) is redundant—please disregard that suggestion.

Likely an incorrect or invalid review comment.

lib/agents/researcher.tsx (2)

46-48: Good: explicit guidance to answer directly when tools aren’t needed

This aligns with the PR goal and reduces “no-response” cases. Nice.


14-21: All public API changes verified and call sites updated

I’ve confirmed that:

  • The researcher function signature in lib/agents/researcher.tsx now takes dynamicSystemPrompt first and no longer accepts mcp.
  • All invocations of researcher (e.g. in app/actions.tsx at line 147) have removed the mcp argument and pass the correct parameters.
  • The researcher export in lib/agents/index.tsx properly surfaces the updated signature.
  • The getTools function in lib/agents/tools/index.tsx no longer has an mcp parameter, and its sole call site in lib/agents/researcher.tsx has been adjusted accordingly.

There are no residual mcp references or mismatched call signatures.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-no-tool-response

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@qodo-code-review
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Infinite Loop

The loop condition under useSpecificAPI now depends solely on answer.length === 0, with no error or timeout escape. If answer is never set (e.g., due to upstream failure), the loop could spin indefinitely. Ensure there's a break condition on error/timeouts or set answer on terminal states.

  useSpecificAPI
    ? answer.length === 0
    : answer.length === 0 && !errorOccurred
) {
Behavior Change

Removing toolOutputs.length === 0 from the condition changes flow: the loop may continue even after tool results are ready unless answer is set. Verify downstream logic guarantees answer gets populated once tools finish, or consider awaiting tool completion explicitly.

  useSpecificAPI
    ? answer.length === 0
    : answer.length === 0 && !errorOccurred
) {
Prompt Ambiguity

The new instruction to provide direct answers when tools aren't needed may cause the agent to skip tools that should be mandatory (e.g., for freshness or geospatial queries). Consider clarifying precedence: mandatory tool usage rules should override the "direct answer" guidance.

When tools are not needed, provide direct, helpful answers based on your knowledge.
Always aim to directly address the user's question. If using information from a tool (like web search), cite the source URL.
Match the language of your response to the user's language.`;

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Aug 25, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Prevent infinite loop in generation

This condition can cause an infinite loop when useSpecificAPI is true and only
tools are called, since answer may never be set. Reintroduce a break condition
based on toolOutputs and also guard on !errorOccurred to exit on failures. This
prevents unbounded iterations when no textual answer is produced.

app/actions.tsx [140-144]

 while (
   useSpecificAPI
-    ? answer.length === 0
+    ? toolOutputs.length === 0 && !errorOccurred
     : answer.length === 0 && !errorOccurred
 ) {

[Suggestion processed]

Suggestion importance[1-10]: 10

__

Why: The suggestion correctly identifies that the PR change introduces a potential infinite loop when useSpecificAPI is true, as answer may never be populated if only tools are used. This is a critical bug, and the proposed fix is correct.

High
  • More

@ngoiyaeric ngoiyaeric merged commit 7173318 into main Aug 25, 2025
3 of 5 checks passed
@ngoiyaeric ngoiyaeric deleted the fix-no-tool-response branch September 10, 2025 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants