-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: implement streaming for native tool calls #9542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This adds streaming support for native tool calls (OpenAI-style function calling) in both the Roo Code Cloud (roo.ts) and OpenRouter providers. Changes: - Add tool_call_start, tool_call_delta, and tool_call_end events to ApiStreamChunk - Implement streaming tool call tracking in roo.ts and openrouter.ts providers - Add NativeToolCallParser.processStreamingChunk() for incremental JSON parsing - Add NativeToolCallParser.startStreamingToolCall() and finalizeStreamingToolCall() - Use partial-json-parser to extract partial values from incomplete JSON - Handle streaming tool calls in Task.ts by calling tool.handlePartial() - Update BaseTool to handle partial native tool calls The streaming implementation allows the UI to show tool parameters as they stream in, providing the same experience as XML tools during LLM streaming.
Re-reviewed commit 5a5ff93. This commit completes the refactoring to emit raw tool call chunks from providers, moving all state management into NativeToolCallParser. All previous review issues remain resolved. The implementation is sound with proper cleanup and no memory leaks. ✅ All issues from previous reviews are resolved Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
- Add clearAllStreamingToolCalls() to prevent memory leak when streams are interrupted - Add hasActiveStreamingToolCalls() for debugging/testing - Add comment clarifying the intentional difference between partial and complete validation logic for insert_content (partial uses OR to show progress incrementally) - Call clearAllStreamingToolCalls() in Task.ts when resetting streaming state
The providers now yield tool_call_partial chunks during streaming, and the NativeToolCallParser is responsible for reassembling them into complete tool_call chunks. Updated tests to match this new behavior.
* feat: add Google Tag Manager to marketing website (RooCodeInc#9148) * feat: add Google Tag Manager to marketing website using Next.js Script component * refactor: remove Google Ads implementation in favor of Tag Manager * fix: wrap GTM script in consent-checking client component for GDPR compliance --------- Co-authored-by: Roo Code <[email protected]> * IPC command for sending messages to the current task (RooCodeInc#9149) * fix: prevent command_output ask from blocking in cloud/headless environments (RooCodeInc#9152) * chore: add changeset for v3.31.1 (RooCodeInc#9153) * Release: v1.85.0 (RooCodeInc#9155) * Gate XML out when native tool protocol is ON (RooCodeInc#9107) * Add native tool definitions (RooCodeInc#9156) * feat: sync reviewer landing page copy - variant B to variant A (RooCodeInc#9158) - Updated variant A content to match variant B messaging - Both variants now show the same improved copy focused on catching meaningful bugs - Emphasizes depth over token-saving and repository-aware analysis Co-authored-by: Roo Code <[email protected]> * feat: sync reviewer landing page copy - variant B to variant A (RooCodeInc#9158) - Updated variant A content to match variant B messaging - Both variants now show the same improved copy focused on catching meaningful bugs - Emphasizes depth over token-saving and repository-aware analysis Co-authored-by: Roo Code <[email protected]> * Move auto-approval from `ChatView` to `Task` (RooCodeInc#9157) * feat(i18n): add internationalization for unexpected API response error message * fix(task): use consistent error message for API response failures and ensure message queue is never undefined * test: update vscode mock and improve test coverage * fix: Model switch re-applies selected profile (sync task.apiConfiguration) (RooCodeInc#9179) (RooCodeInc#9181) * Add custom Button component with variant system (RooCodeInc#9150) Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com> Co-authored-by: Roo Code <[email protected]> * Changeset version bump (RooCodeInc#9154) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Matt Rubens <[email protected]> * feat(core): detect API configuration changes for model switching * fix: include mcpServers in getState() for auto-approval (
Summary
This PR adds streaming support for native tool calls (OpenAI-style function calling) in both the Roo Code Cloud (roo.ts) and OpenRouter providers. This allows the UI to show tool parameters as they stream in, providing the same experience as XML tools during LLM streaming.
Changes
API Layer
tool_call_start,tool_call_delta, andtool_call_endevents toApiStreamChunktype insrc/api/transform/stream.tssrc/api/providers/roo.tssrc/api/providers/openrouter.tsTool Call Parsing
NativeToolCallParser.startStreamingToolCall()to initialize streaming stateNativeToolCallParser.processStreamingChunk()for incremental JSON parsing usingpartial-json-parserNativeToolCallParser.finalizeStreamingToolCall()to complete tool call processingcreatePartialToolUse()helper to build partial ToolUse objects from incomplete JSONTask Processing
Task.tsto handle the new streaming tool call eventstool.handlePartial()on each delta to update the UITool Infrastructure
BaseTool.tsto properly handle partial native tool callspartial-jsonpackage dependency for parsing incomplete JSONHow It Works
When the API streams a tool call, it yields:
tool_call_start: Tool name and ID (when available)tool_call_delta: Incremental JSON argument chunkstool_call_end: Signals completionTask.tsreceives these events and:tool_call_startpartial-json-parserto extract partial values from incomplete JSON on each deltaToolUseobjects and callstool.handlePartial()for UI updatestool_call_endIndividual tools can override
handlePartial()to show streaming UI (e.g., showing file content as it streams)Testing
roo.spec.tswith tests for the new streaming eventsImportant
Adds streaming support for native tool calls, enhancing real-time UI updates in
roo.tsandopenrouter.ts.roo.tsandopenrouter.ts.tool_call_start,tool_call_delta, andtool_call_endevents instream.ts.Task.tsto handle new streaming events and update UI.NativeToolCallParserwith methods for streaming tool call processing.partial-json-parserfor incremental JSON parsing.roo.spec.tswith tests for streaming events.This description was created by
for 5a5ff93. You can customize this summary. It will automatically update as commits are pushed.