Home / Function/ test_filter_message_exclude_tool_calls_content_blocks() — langchain Function Reference

test_filter_message_exclude_tool_calls_content_blocks() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/tests/unit_tests/messages/test_utils.py lines 222–269

def test_filter_message_exclude_tool_calls_content_blocks() -> None:
    tool_calls = [
        {"name": "foo", "id": "1", "args": {}, "type": "tool_call"},
        {"name": "bar", "id": "2", "args": {}, "type": "tool_call"},
    ]
    messages = [
        HumanMessage("foo", name="blah", id="1"),
        AIMessage("foo-response", name="blah", id="2"),
        HumanMessage("bar", name="blur", id="3"),
        AIMessage(
            [
                {"text": "bar-response", "type": "text"},
                {"name": "foo", "type": "tool_use", "id": "1"},
                {"name": "bar", "type": "tool_use", "id": "2"},
            ],
            tool_calls=tool_calls,
            id="4",
        ),
        ToolMessage("baz", tool_call_id="1", id="5"),
        ToolMessage("qux", tool_call_id="2", id="6"),
    ]
    messages_model_copy = [m.model_copy(deep=True) for m in messages]
    expected = messages[:3]

    # test excluding all tool calls
    actual = filter_messages(messages, exclude_tool_calls=True)
    assert expected == actual

    # test explicitly excluding all tool calls
    actual = filter_messages(messages, exclude_tool_calls=["1", "2"])
    assert expected == actual

    # test excluding a specific tool call
    expected = messages[:4] + messages[-1:]
    expected[3] = expected[3].model_copy(
        update={
            "tool_calls": [tool_calls[1]],
            "content": [
                {"text": "bar-response", "type": "text"},
                {"name": "bar", "type": "tool_use", "id": "2"},
            ],
        }
    )
    actual = filter_messages(messages, exclude_tool_calls=["1"])
    assert expected == actual

    # assert that we didn't mutate the original messages
    assert messages == messages_model_copy

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free