Skip to content

fix: conditionally declare tools when OpenClaw is configured (fixes #12)#40

Open
juliosuas wants to merge 1 commit intoIntent-Lab:mainfrom
juliosuas:fix/conditional-tools-declaration
Open

fix: conditionally declare tools when OpenClaw is configured (fixes #12)#40
juliosuas wants to merge 1 commit intoIntent-Lab:mainfrom
juliosuas:fix/conditional-tools-declaration

Conversation

@juliosuas
Copy link
Copy Markdown

Problem

When OpenClaw is not configured, Gemini still receives tool declarations (execute) in the setup message. This causes Gemini to attempt tool calls (like web search) that have no backend to handle them — the app gets permanently stuck showing "Running: execute..." with no way to recover.

This is the root cause of Issue #12 ("Gemini stuck once it tries to search the web").

Root Cause

The sendSetupMessage() function unconditionally included the tools array, regardless of whether OpenClaw was configured. When Gemini called execute, the ToolCallRouter sent the request to a non-existent gateway, which either timed out after 120s or failed silently.

Fix (3 layers of defense)

1. Conditional tool declaration

sendSetupMessage() now only includes the tools array when GeminiConfig.isOpenClawConfigured is true.

2. No-tools system instruction

When OpenClaw is not configured, uses a different system prompt that tells Gemini it has no tools and should inform the user to set up OpenClaw in Settings.

3. Fast-fail in ToolCallRouter

As defense-in-depth, ToolCallRouter.handleToolCall() now checks isOpenClawConfigured before routing. If unconfigured, returns an immediate error response to Gemini instead of hanging.

Files Changed

  • GeminiLiveService.swift / .kt — conditional tool declaration in setup
  • GeminiConfig.swift / .kt — added noToolsSystemInstruction
  • ToolCallRouter.swift / .kt — fast-fail guard

Behaviour

Scenario Before After
No OpenClaw, user says "search for X" ⏳ Stuck on "Running: execute..." forever ✅ Gemini says "OpenClaw is not connected, set it up in Settings"
OpenClaw configured ✅ Works ✅ Works (no change)
OpenClaw configured but unreachable ⏳ 120s timeout ✅ Circuit breaker + fast-fail error

Test plan

  • Without OpenClaw: start session → ask "search for coffee shops" → Gemini responds verbally that tools aren't available
  • With OpenClaw: start session → ask "search for coffee shops" → tool call succeeds normally
  • Verify no tools array in WebSocket setup message when OpenClaw unconfigured (check logs)

🤖 Generated with Claude Code

When OpenClaw is not configured, Gemini still received tool declarations
in the setup message. This caused it to attempt tool calls (like web
search) that had no backend to handle them, getting permanently stuck
in "executing" state.

Changes:
- Only include tools array in Gemini setup when isOpenClawConfigured
- Use a no-tools system instruction when OpenClaw is absent, so Gemini
  tells the user to enable OpenClaw instead of attempting tool calls
- Add fast-fail in ToolCallRouter for unconfigured OpenClaw (defense
  in depth — returns immediate error instead of hanging)
- Applied to both iOS (Swift) and Android (Kotlin)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant