Skip to content

feat(chat): improve search feature with multi-round tool calls#37

Merged
using-system merged 7 commits into
mainfrom
feat/improve-search-feature
Apr 27, 2026
Merged

feat(chat): improve search feature with multi-round tool calls#37
using-system merged 7 commits into
mainfrom
feat/improve-search-feature

Conversation

@using-system
Copy link
Copy Markdown
Owner

@using-system using-system commented Apr 27, 2026

Summary

  • Add debug logging across the recipe search tool chain (providers, registry, handlers, Cookidoo client)
  • Fix multi-round tool calls: re-gen loop now handles ThinkingResponse, FunctionCallResponse, and ParallelFunctionCallResponse across up to 10 rounds
  • Fix async credentials loading so get_recipe_detail resolves credentials even when the provider Future has not yet completed
  • Parse raw <|tool_call> tokens emitted in non-thinking mode as fallback for FunctionCallResponse
  • Fix "Cannot use ref after widget disposed" crash by guarding ref.read() with mounted checks
  • Add SuperGemma4-E4B-abliterated as alternative model option
  • Simplify search-recipe skill to present recipes as-is
  • Temporarily disable config line in system prompt

Test plan

  • Test recipe search with thinking mode enabled (Gemma 4 E4B)
  • Test recipe search with thinking mode disabled (raw tool call fallback)
  • Test get_recipe_detail with Cookidoo credentials configured
  • Test leaving the page during a tool call (no crash)
  • Test SuperGemma4-E4B-abliterated model loading
  • Verify all existing tests pass (flutter test)

🤖 Generated with Claude Code

using-system and others added 4 commits April 26, 2026 14:03
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>
Copilot AI review requested due to automatic review settings April 27, 2026 06:36
using-system and others added 2 commits April 27, 2026 08:38
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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread lib/features/chat/presentation/conversation_page.dart Outdated
Comment thread lib/features/chat/presentation/conversation_page.dart
Comment thread lib/features/chat/presentation/conversation_page.dart Outdated
Comment thread lib/features/chat/domain/chat_model_preference.dart Outdated
- 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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread lib/features/recipe/domain/system_prompt_builder.dart
@using-system using-system merged commit b68a973 into main Apr 27, 2026
7 checks passed
@using-system using-system deleted the feat/improve-search-feature branch April 27, 2026 07:01
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.

2 participants