This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Reproduction: _merge_messages in langchain-google-vertexai silently drops | |
| tool_result when ToolMessage has empty content (content=[]). | |
| Bug: | |
| _merge_messages in langchain_google_vertexai/_anthropic_utils.py treats | |
| ToolMessage(content=[]) as pre-formatted tool_result blocks because | |
| Python's `all(predicate for x in [])` returns True on an empty iterable. | |
| The empty list becomes HumanMessage([]), which then gets merged into the | |
| next HumanMessage, silently dropping the tool_result. The Anthropic API |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Reproduction: SummarizationMiddleware token underestimation with ChatAnthropicVertex. | |
| LangChain's _get_approximate_token_counter checks model._llm_type == "anthropic-chat", | |
| but ChatAnthropicVertex._llm_type returns "anthropic-chat-vertexai". This causes the | |
| token counter to use 4.0 chars/token instead of 3.3, underestimating by ~16%. | |
| The summarization middleware never triggers, and the API rejects the prompt. | |
| Additionally: | |
| - use_usage_metadata_scaling is gated on response_metadata["model_provider"], which | |
| ChatAnthropicVertex never sets. The scaling safety net is a no-op. |