fix(agent): map native google_search and surface empty rounds
Models (notably Gemini) emit a native 'google_search' function call, but the agent loop had no mapping for it, so the call failed to convert, the round produced 0 chars and 0 tool blocks, and generation died silently — the web client hung on 'waiting for first token' with no error (also #443). - Map google_search / google_search_retrieval / google_search_grounding to the web_search tool, and read Gemini's 'queries' array (falling back to 'query'). - In stream_agent_loop, when a round yields no response text and no tool events, emit a visible fallback message instead of leaving the user hanging. - Give the unknown-tool execution branch an explicit exit_code=1 so the failure is logged as an error rather than 'n/a'. Unknown/unconvertible tool names still return None (unchanged) so they are dropped safely rather than executed. Added tests covering the google_search mapping, the queries array, and unknown/invalid-JSON returning None.
This commit is contained in:
@@ -2161,6 +2161,13 @@ async def stream_agent_loop(
|
||||
# Separator in accumulated response
|
||||
full_response += "\n\n"
|
||||
|
||||
# If the response is completely empty and no tools were executed,
|
||||
# yield a fallback message so the user is not left hanging.
|
||||
if not full_response.strip() and not tool_events:
|
||||
_error_msg = "The model returned an empty response. Please try again or switch to a different model."
|
||||
yield f'data: {json.dumps({"delta": _error_msg})}\n\n'
|
||||
full_response = _error_msg
|
||||
|
||||
# --- Final metrics ---
|
||||
total_duration = time.time() - total_start
|
||||
metrics = _compute_final_metrics(
|
||||
|
||||
Reference in New Issue
Block a user