Skip to content

The agent engineering platform.

fix(langchain): recognize ChatAnthropicVertex in _get_approximate_token_counter (#36320)

Jordan Hury475408fa6209
diff --git a/libs/langchain_v1/langchain/agents/middleware/summarization.py b/libs/langchain_v1/langchain/agents/middleware/summarization.py
index 42d2760b4e..6c1091152c 100644
--- a/libs/langchain_v1/langchain/agents/middleware/summarization.py
+++ b/libs/langchain_v1/langchain/agents/middleware/summarization.py
@@ -141,7 +141,7 @@ Example:
def _get_approximate_token_counter(model: BaseChatModel) -> TokenCounter:
"""Tune parameters of approximate token counter based on model type."""
- if model._llm_type == "anthropic-chat": # noqa: SLF001
+ if model._llm_type.startswith("anthropic-chat"): # noqa: SLF001
# 3.3 was estimated in an offline experiment, comparing with Claude's token-counting
# API: https://platform.claude.com/docs/en/build-with-claude/token-counting
return partial(