Skip to content

The agent engineering platform.

google-genai[patch]: on_llm_new_token fix (#16924)

Sandeep Banerjee183daa6e6fe1
diff --git a/libs/partners/google-genai/langchain_google_genai/chat_models.py b/libs/partners/google-genai/langchain_google_genai/chat_models.py
index 420dbcfd13..496f54add5 100644
--- a/libs/partners/google-genai/langchain_google_genai/chat_models.py
+++ b/libs/partners/google-genai/langchain_google_genai/chat_models.py
@@ -598,6 +598,7 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
for chunk in response:
_chat_result = _response_to_result(chunk, stream=True)
gen = cast(ChatGenerationChunk, _chat_result.generations[0])
+
if run_manager:
run_manager.on_llm_new_token(gen.text)
yield gen
@@ -622,6 +623,7 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
):
_chat_result = _response_to_result(chunk, stream=True)
gen = cast(ChatGenerationChunk, _chat_result.generations[0])
+
if run_manager:
await run_manager.on_llm_new_token(gen.text)
yield gen