Skip to content

Add streaming support for Gemini streamGenerateContent tool calls #76

Description

@KochC

In index.js the streamGenerateContent handler (reachable via POST /v1beta/models/:model:streamGenerateContent) calls executePromptStreaming and emits incremental text deltas correctly for plain-text turns. However, when callerTools is non-empty and runAgentTurn resolves with toolCalls.length > 0, the streaming response emits only a final candidates chunk with functionCall parts — it never emits the intermediate response.function_call_arguments.delta-equivalent Gemini streaming events that clients like Vertex AI SDK or LangChain's Gemini integration expect (candidates[].content.parts[].functionCall arriving before the terminal chunk). This is visible by comparing the OpenAI streaming path in createProxyFetchHandler (which emits a dedicated tool_calls delta chunk before the finish chunk) against the Gemini streaming path, which has no equivalent. Gemini streaming clients that buffer until they see a function-call part mid-stream will hang or mis-parse the response. The fix mirrors the OpenAI streaming approach: emit a pre-finish chunk containing the functionCall parts when toolCalls.length > 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions