Home / Function/ _get_approximate_token_counter() — langchain Function Reference

_get_approximate_token_counter() — langchain Function Reference

Architecture documentation for the _get_approximate_token_counter() function in summarization.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  1c1e5e7f_dd6a_7ef9_53fd_a81f47694626["_get_approximate_token_counter()"]
  7fb364fc_5799_42dd_fceb_bf60f55185e9["summarization.py"]
  1c1e5e7f_dd6a_7ef9_53fd_a81f47694626 -->|defined in| 7fb364fc_5799_42dd_fceb_bf60f55185e9
  27600a06_3568_45a8_ef8e_efda7e6f1a1a["__init__()"]
  27600a06_3568_45a8_ef8e_efda7e6f1a1a -->|calls| 1c1e5e7f_dd6a_7ef9_53fd_a81f47694626
  style 1c1e5e7f_dd6a_7ef9_53fd_a81f47694626 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/summarization.py lines 142–150

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
        # 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(
            count_tokens_approximately, use_usage_metadata_scaling=True, chars_per_token=3.3
        )
    return partial(count_tokens_approximately, use_usage_metadata_scaling=True)

Domain

Subdomains

Called By

Frequently Asked Questions

What does _get_approximate_token_counter() do?
_get_approximate_token_counter() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/summarization.py.
Where is _get_approximate_token_counter() defined?
_get_approximate_token_counter() is defined in libs/langchain_v1/langchain/agents/middleware/summarization.py at line 142.
What calls _get_approximate_token_counter()?
_get_approximate_token_counter() is called by 1 function(s): __init__.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free