Skip to content

Gemini models streamed tool calls are missing tool_call.id, resulting in no final response after tool execution #698

Description

@Thirukumaran-SF4558

Description

Hi! While testing DeepAgents with ChatGoogleGenerativeAI or ChatGoogle and Gemini 2.5 Flash, I noticed a difference in behavior between agent.invoke() and agent.streamEvents().

Tool calling works correctly in the non-streaming flow (agent.invoke()), but in the streaming flow (agent.streamEvents()), the generated tool call does not include a tool_call.id. After the tool executes, the model returns only a newline ("\n") instead of generating the expected final assistant response.

Using the exact same code with ChatOpenRouter (Gemini 2.5 Flash) works correctly and includes a tool call ID.

Environment

  • DeepAgents: Latest
  • @langchain/google-genai
  • LangChain
  • Model: gemini-2.5-flash

Minimal Reproduction

import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
import { createDeepAgent } from "deepagents";
import { tool } from "langchain/tools";
import { z } from "zod";

const model = new ChatGoogleGenerativeAI({
  model: "gemini-2.5-flash",
  apiKey: process.env.GOOGLE_API_KEY,
});

const echoTool = tool(
  ({ message }) => `Echo: ${message}`,
  {
    name: "echo",
    description: "Echoes back whatever message you give it.",
    schema: z.object({
      message: z.string(),
    }),
  }
);

const agent = createDeepAgent({
  model,
  tools: [echoTool],
  systemPrompt:
    "You are a helpful assistant. Always use the echo tool.",
});

const run = await agent.streamEvents(
  {
    messages: [
      {
        role: "user",
        content: "hi how are you",
      },
    ],
  },
  { version: "v3" }
);

Observed Behavior

The first streamed AI message contains a tool call without a tool_call.id.

{
  "tool_calls": [
    {
      "type": "tool_call",
      "name": "echo",
      "args": {
        "message": "Hello! I am doing well, thank you for asking."
      }
    }
  ]
}

After the tool executes, the next streamed assistant message is:

{
  "content": [
    {
      "type": "text",
      "text": "\n"
    }
  ],
  "tool_calls": []
}

As a result, no final assistant response is streamed.

Expected Behavior

The streamed tool call should include a valid tool_call.id, for example:

{
  "tool_calls": [
    {
      "id": "call_xxxxx",
      "type": "tool_call",
      "name": "echo",
      "args": {
        "message": "Hello! I am doing well, thank you for asking."
      }
    }
  ]
}

After the tool executes, the model should stream the final assistant response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions