Home / Function/ test_count_tokens_approximately_tool_calls() — langchain Function Reference

test_count_tokens_approximately_tool_calls() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  6338f1ac_5b6f_c24e_38bf_e017b2d25a66["test_count_tokens_approximately_tool_calls()"]
  ea3f8d89_f44b_6738_3cb9_a740a73cfca4["test_utils.py"]
  6338f1ac_5b6f_c24e_38bf_e017b2d25a66 -->|defined in| ea3f8d89_f44b_6738_3cb9_a740a73cfca4
  style 6338f1ac_5b6f_c24e_38bf_e017b2d25a66 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/messages/test_utils.py lines 1534–1548

def test_count_tokens_approximately_tool_calls() -> None:
    tool_calls = [{"name": "test_tool", "args": {"foo": "bar"}, "id": "1"}]
    messages = [
        # tool calls json -> 79 chars + 9 role chars -> 22 + 3 = 25 tokens
        AIMessage(content="", tool_calls=tool_calls),
        # 15 chars + 4 role chars -> 5 + 3 = 8 tokens
        HumanMessage(content="Regular message"),
    ]
    assert count_tokens_approximately(messages) == 33
    # AI message w/ both content and tool calls
    # 94 chars + 9 role chars -> 26 + 3 = 29 tokens
    messages = [
        AIMessage(content="Regular message", tool_calls=tool_calls),
    ]
    assert count_tokens_approximately(messages) == 29

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free