Anthropic and Gemini APIs require ALL tool_result blocks for a given
assistant message to be in a SINGLE user message that immediately follows
the assistant message. Previously, each tool AiMessage was converted to
a separate user message, causing Anthropic to reject multi-turn tool
conversations with 'tool_result must follow a tool_use block' error.
Fix: collect consecutive 'tool' role messages into a buffer, then flush
as a single user message with all tool_result/functionResponse blocks
when a non-tool message is encountered or at end of message list.
- Claude: merge N tool results into 1 user message with N content blocks
- Gemini: merge N tool results into 1 user message with N functionResponse parts
- OpenAI path unchanged (each tool message already has tool_call_id field)
When the LLM calls `list_tables` tool without a `schema` parameter, the
backend receives an empty string. This caused PostgreSQL and MySQL
metadata queries to return no results because:
- PostgreSQL: `WHERE n.nspname = ''` matches nothing
- MySQL: `WHERE TABLE_SCHEMA = ''` matches nothing
Fix by falling back to sensible defaults:
- PostgreSQL `list_tables`/`get_columns`: empty schema → "public"
- MySQL `list_tables`: empty schema → database name (MySQL schema == database)
Move tool calling from non-streaming (complete) API calls to real
streaming SSE, so text, reasoning, and tool call arguments all arrive
incrementally — users see the AI think and act in real time.
- Extract ~370 lines of non-streaming tool-call functions from
agent_loop.rs (call_with_tools, call_openai_with_tools,
call_claude_with_tools, call_gemini_with_tools) and replace with
a single ai::stream_with_tools() dispatch call.
- Add streaming-with-tools infrastructure to ai.rs (~550 lines):
- StreamToolEvent enum: Chunk, ToolCallStart, ToolCallDelta,
ToolCallComplete — provider-agnostic, feeds into the
StreamingToolCallAccumulator
- stream_claude_with_tools(): parse SSE content_block_start/delta/
stop events, incremental input_json_delta for tool arguments
- stream_openai_with_tools(): parse SSE delta.tool_calls with
incremental function.arguments
- stream_gemini_with_tools(): parse SSE functionCall (Gemini
sends complete objects, not deltas — emit as one chunk)
- Cancellation support via tokio::select! in every streaming loop
- Extended timeout for reasoning models (600s vs 120s)
- StreamingToolCallAccumulator: collect partial tool call fragments
from streaming deltas, then deserialize into complete ToolCall
objects in index order once the stream ends.