Conversation
* fix: use agent.generate() in /api/chat/generate and move providerOptions/prepareStep to agent constructor
The non-streaming /api/chat/generate endpoint was bypassing the ToolLoopAgent
by calling generateText() directly, while providerOptions and prepareStep were
silently ignored when passed at call time to agent.stream()/agent.generate().
Move providerOptions (thinking/reasoning budgets) and prepareStep (tool chain
orchestration) into the ToolLoopAgent constructor in getGeneralAgent.ts so they
apply consistently across all paths: streaming, non-streaming, and email.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: update setupChatRequest JSDoc to reflect current behavior
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* refactor: trim ChatConfig to only used fields (YAGNI)
ChatConfig no longer extends RoutingDecision — now just { agent, messages }.
Removes dead fields (system, model, instructions, tools, experimental_*)
that were silently ignored by agent.generate()/agent.stream(). Fixes
evals to use agent.generate() instead of bypassing the agent via
generateText().
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThis PR refactors the chat request handling by relocating provider configuration and the prepareStep hook from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
This is the final PR Bugbot will review for you during this billing cycle
Your free Bugbot reviews will reset on March 17
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| const { agent } = chatConfig; | ||
|
|
||
| const result = await generateText(chatConfig); | ||
| const result = await agent.generate(chatConfig); |
There was a problem hiding this comment.
Agent passed to its own generate method unnecessarily
Low Severity
agent.generate(chatConfig) passes the entire chatConfig object, which includes the agent itself as a property ({ agent, messages }). This creates a self-referential call where the agent receives a reference to itself in its own options. The sibling call site in callChatFunctionsWithResult.ts correctly destructures and passes only { messages }. The inconsistency between these two patterns makes the code harder to reason about.


Summary
testbranch intomain🤖 Generated with Claude Code
Note
Medium Risk
Changes the core chat execution path and configuration shape, so regressions could affect generation behavior and downstream callers expecting the old
ChatConfigfields.Overview
Shifts chat generation to run through the
ToolLoopAgentinstance instead of callinggenerateTextwith a large config object, updatinghandleChatGenerate(and eval helper) to callagent.generate(...).Moves
providerOptions(thinking/reasoning) andprepareSteptool-chain behavior intogetGeneralAgent’sToolLoopAgentconstruction, and simplifiessetupChatRequest/ChatConfigto return only{ agent, messages }(droppingsystem,tools,providerOptions,experimental_*, etc.). Tests are updated accordingly, including new assertions that agent settings include the baked-inproviderOptionsandprepareStep.Written by Cursor Bugbot for commit c137c78. This will update automatically on new commits. Configure here.
Summary by CodeRabbit