Home / Function/ test__format_messages_with_str_content_and_tool_calls() — langchain Function Reference

test__format_messages_with_str_content_and_tool_calls() — langchain Function Reference

Architecture documentation for the test__format_messages_with_str_content_and_tool_calls() function in test_chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  ecc327f5_ff32_e45f_bf13_97ad7f585d7f["test__format_messages_with_str_content_and_tool_calls()"]
  18428dc5_a41b_90c6_88ad_615296ee3311["test_chat_models.py"]
  ecc327f5_ff32_e45f_bf13_97ad7f585d7f -->|defined in| 18428dc5_a41b_90c6_88ad_615296ee3311
  style ecc327f5_ff32_e45f_bf13_97ad7f585d7f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/tests/unit_tests/test_chat_models.py lines 714–755

def test__format_messages_with_str_content_and_tool_calls() -> None:
    system = SystemMessage("fuzz")  # type: ignore[misc]
    human = HumanMessage("foo")  # type: ignore[misc]
    # If content and tool_calls are specified and content is a string, then both are
    # included with content first.
    ai = AIMessage(  # type: ignore[misc]
        "thought",
        tool_calls=[{"name": "bar", "id": "1", "args": {"baz": "buzz"}}],
    )
    tool = ToolMessage("blurb", tool_call_id="1")  # type: ignore[misc]
    messages = [system, human, ai, tool]
    expected = (
        "fuzz",
        [
            {"role": "user", "content": "foo"},
            {
                "role": "assistant",
                "content": [
                    {"type": "text", "text": "thought"},
                    {
                        "type": "tool_use",
                        "name": "bar",
                        "id": "1",
                        "input": {"baz": "buzz"},
                    },
                ],
            },
            {
                "role": "user",
                "content": [
                    {
                        "type": "tool_result",
                        "content": "blurb",
                        "tool_use_id": "1",
                        "is_error": False,
                    },
                ],
            },
        ],
    )
    actual = _format_messages(messages)
    assert expected == actual

Domain

Subdomains

Frequently Asked Questions

What does test__format_messages_with_str_content_and_tool_calls() do?
test__format_messages_with_str_content_and_tool_calls() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/unit_tests/test_chat_models.py.
Where is test__format_messages_with_str_content_and_tool_calls() defined?
test__format_messages_with_str_content_and_tool_calls() is defined in libs/partners/anthropic/tests/unit_tests/test_chat_models.py at line 714.

Analyze Your Own Codebase

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

Try Supermodel Free