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.
Description
Hi! While testing DeepAgents with
ChatGoogleGenerativeAIorChatGoogleand Gemini 2.5 Flash, I noticed a difference in behavior betweenagent.invoke()andagent.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 atool_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
@langchain/google-genaigemini-2.5-flashMinimal Reproduction
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.