feat(chat): improve search feature with multi-round tool calls#37
Merged
Conversation
Add detailed debugPrint statements to trace the full tool-call flow: provider registration, tool dispatch, Cookidoo HTTP requests/responses, and chat stream handling. All logs are prefixed with >>> and guarded by kDebugMode. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The re-gen loop after a tool call only handled TextResponse, ignoring ThinkingResponse and subsequent FunctionCallResponse (e.g. search → get_recipe_detail). This caused empty responses when the LLM chained tool calls. - Re-gen now loops up to 10 rounds, handling ThinkingResponse, FunctionCallResponse, and ParallelFunctionCallResponse - Make credentialsReader async so credentials resolve even when the provider Future has not yet completed - Update search-recipe skill to always call get_recipe_detail and adapt the recipe to user settings while keeping faithful to the original Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Without reasoning mode the model emits tool calls as raw text tokens
(`<|tool_call>call:name{...}<tool_call|>`) instead of parsed
FunctionCallResponse objects. The re-gen loop missed these entirely,
resulting in empty responses after search_recipes.
- Add _parseRawToolCall helper to detect and parse the raw format
- Check text buffer after both the initial stream and each re-gen round
- Simplify search-recipe skill to present recipes as-is
- Temporarily disable config line in system prompt to reduce model
confusion
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add SuperGemma4-E4B-abliterated as an alternative model choice. Guard ref.read() calls with mounted checks in raw tool call handlers to prevent "Cannot use ref after widget disposed" crash when the user leaves the page during a tool call. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The config line in buildSystemPrompt was temporarily disabled so the tests that asserted config values in the output now fail. Simplify the tests to match the current prompt format. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The variable triggers a warning that fails CI Analyze. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR improves the chat recipe-search toolchain by adding multi-round tool-call handling (including parallel calls and a raw-token fallback), making Cookidoo credential loading async-safe, and adding extensive debug logging across the tool/cookidoo layers.
Changes:
- Update Cookidoo repository credential access to be asynchronous end-to-end (providers + repository + tests).
- Add multi-round re-generation logic in the chat streaming loop to support chained tool calls, plus a fallback parser for raw
<|tool_call>tokens. - Add debug logging across tool registry/provider and Cookidoo client; update search-recipe skill instructions and system prompt behavior; add a new model option.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/features/cookidoo/data/cookidoo_repository_impl_test.dart | Updates tests for async credentialsReader signature. |
| lib/features/tools/tool_registry.dart | Adds debug logging of handler outcomes. |
| lib/features/tools/providers.dart | Adds debug logging for enabled tools/handlers selection. |
| lib/features/recipe/domain/system_prompt_builder.dart | Temporarily removes the config line from the system prompt (commented out). |
| lib/features/cookidoo/providers.dart | Switches lazy credential reading to async storage-backed reads. |
| lib/features/cookidoo/data/cookidoo_repository_impl.dart | Makes credentialsReader async and awaits it in auth-sensitive methods. |
| lib/features/cookidoo/data/cookidoo_client.dart | Adds debug logging for requests/responses and basic parsing telemetry. |
| lib/features/chat/presentation/conversation_page.dart | Implements multi-round tool-call loop + raw-token tool-call parsing fallback + additional logging. |
| lib/features/chat/domain/chat_model_preference.dart | Adds “SuperGemma4-E4B-abliterated” model option. |
| assets/skills/search-recipe/SKILL.md | Updates skill guidance to always call get_recipe_detail and present results “as-is”. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Anchor raw tool call regex with ^...$ to prevent false matches on text that merely mentions the token format - Parse numeric values from raw tool call args so typed parameters (e.g. limit) are not silently dropped as strings - Wrap all verbose debugPrint calls with kDebugMode to prevent leaking user queries into production logs - Align SuperGemma4 fileType to ModelFileType.task to match the other Gemma 4 model entries Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
<|tool_call>tokens emitted in non-thinking mode as fallback for FunctionCallResponseTest plan
flutter test)🤖 Generated with Claude Code