Home / Function/ test_count_tokens_approximately_ai_tool_calls_skipped_for_list_content() — langchain Function Reference

test_count_tokens_approximately_ai_tool_calls_skipped_for_list_content() — langchain Function Reference

Architecture documentation for the test_count_tokens_approximately_ai_tool_calls_skipped_for_list_content() function in test_utils.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  da50414c_864c_9117_4703_913e9668ac67["test_count_tokens_approximately_ai_tool_calls_skipped_for_list_content()"]
  03f6a5ae_d57a_eb66_626a_b9e082b763ea["test_utils.py"]
  da50414c_864c_9117_4703_913e9668ac67 -->|defined in| 03f6a5ae_d57a_eb66_626a_b9e082b763ea
  style da50414c_864c_9117_4703_913e9668ac67 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/messages/test_utils.py lines 2866–2899

def test_count_tokens_approximately_ai_tool_calls_skipped_for_list_content() -> None:
    """Test that tool_calls aren't double-counted for list (Anthropic-style) content."""
    tool_calls = [
        {
            "id": "call_1",
            "name": "foo",
            "args": {"x": 1},
        }
    ]

    # Case 1: content is a string -> tool_calls should be added to the char count.
    ai_with_text_content = AIMessage(
        content="do something",
        tool_calls=tool_calls,
    )
    count_text = count_tokens_approximately([ai_with_text_content])

    # Case 2: content is a list (e.g. Anthropic-style blocks) -> tool_calls are
    # already represented in the content and should NOT be counted again.
    ai_with_list_content = AIMessage(
        content=[
            {"type": "text", "text": "do something"},
            {
                "type": "tool_use",
                "name": "foo",
                "input": {"x": 1},
                "id": "call_1",
            },
        ],
        tool_calls=tool_calls,
    )
    count_list = count_tokens_approximately([ai_with_list_content])

    assert count_text - 1 <= count_list <= count_text + 1

Domain

Subdomains

Frequently Asked Questions

What does test_count_tokens_approximately_ai_tool_calls_skipped_for_list_content() do?
test_count_tokens_approximately_ai_tool_calls_skipped_for_list_content() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/messages/test_utils.py.
Where is test_count_tokens_approximately_ai_tool_calls_skipped_for_list_content() defined?
test_count_tokens_approximately_ai_tool_calls_skipped_for_list_content() is defined in libs/core/tests/unit_tests/messages/test_utils.py at line 2866.

Analyze Your Own Codebase

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

Try Supermodel Free