Skip to content

feat(gemini): Phase 4 — SSE streaming tool use (functionCall chunks) #1659

@bug-ops

Description

@bug-ops

Part of epic #1592 (Gemini provider).

Follow-up from #1639 (SSE TODO). Currently chat_with_tools() uses the non-streaming Gemini endpoint (generateContent), so tool calls work correctly. However, GeminiStreamPart in crates/zeph-llm/src/sse.rs does not have a function_call field — if a future caller uses the SSE path while tools are active, functionCall chunks will be silently dropped.

Goal

Extend the Gemini SSE parser to handle functionCall parts streamed by the Gemini API.

Required Changes

  1. Add function_call: Option<GeminiFunctionCall> field to GeminiStreamPart in sse.rs.
  2. Define GeminiFunctionCall { name: String, args: serde_json::Value }.
  3. In parse_gemini_sse_event(), accumulate functionCall parts across streaming chunks and emit them as StreamChunk::ToolCall (or equivalent) once complete.
  4. Wire accumulated tool calls into gemini_sse_to_stream() / chat_stream() output.
  5. Update chat_with_tools() to optionally use SSE for tool-use sessions.
  6. Add unit tests covering streamed functionCall chunks.

Acceptance Criteria

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions