test__format_messages_with_tool_use_blocks_and_tool_calls() — langchain Function Reference
Architecture documentation for the test__format_messages_with_tool_use_blocks_and_tool_calls() function in test_chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD a9fcd1c5_cbc3_2256_6b78_2d9b6dafad1d["test__format_messages_with_tool_use_blocks_and_tool_calls()"] 18428dc5_a41b_90c6_88ad_615296ee3311["test_chat_models.py"] a9fcd1c5_cbc3_2256_6b78_2d9b6dafad1d -->|defined in| 18428dc5_a41b_90c6_88ad_615296ee3311 style a9fcd1c5_cbc3_2256_6b78_2d9b6dafad1d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/tests/unit_tests/test_chat_models.py lines 803–852
def test__format_messages_with_tool_use_blocks_and_tool_calls() -> None:
"""Show that tool_calls are preferred to tool_use blocks when both have same id."""
system = SystemMessage("fuzz") # type: ignore[misc]
human = HumanMessage("foo") # type: ignore[misc]
# NOTE: tool_use block in contents and tool_calls have different arguments.
ai = AIMessage( # type: ignore[misc]
[
{"type": "text", "text": "thought"},
{
"type": "tool_use",
"name": "bar",
"id": "1",
"input": {"baz": "NOT_BUZZ"},
},
],
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"}, # tool_calls value preferred.
},
],
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"content": "blurb",
"tool_use_id": "1",
"is_error": False,
},
],
},
],
)
actual = _format_messages(messages)
assert expected == actual
Domain
Subdomains
Source
Frequently Asked Questions
What does test__format_messages_with_tool_use_blocks_and_tool_calls() do?
test__format_messages_with_tool_use_blocks_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_tool_use_blocks_and_tool_calls() defined?
test__format_messages_with_tool_use_blocks_and_tool_calls() is defined in libs/partners/anthropic/tests/unit_tests/test_chat_models.py at line 803.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free