test_tool_message_histories_list_content() — langchain Function Reference
Architecture documentation for the test_tool_message_histories_list_content() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD fc2a7ce6_0daa_076a_8e5c_e51edd960155["test_tool_message_histories_list_content()"] 971e928f_9c9b_ce7a_b93d_e762f2f5aa54["ChatModelIntegrationTests"] fc2a7ce6_0daa_076a_8e5c_e51edd960155 -->|defined in| 971e928f_9c9b_ce7a_b93d_e762f2f5aa54 style fc2a7ce6_0daa_076a_8e5c_e51edd960155 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/standard-tests/langchain_tests/integration_tests/chat_models.py lines 1816–1911
def test_tool_message_histories_list_content(
self,
model: BaseChatModel,
my_adder_tool: BaseTool,
) -> None:
"""Test that message histories are compatible with list tool contents.
For instance with Anthropic format contents.
These message histories will include `AIMessage` objects with "tool use" and
content blocks, e.g.,
```python
[
{"type": "text", "text": "Hmm let me think about that"},
{
"type": "tool_use",
"input": {"fav_color": "green"},
"id": "foo",
"name": "color_picker",
},
]
```
This test should be skipped if the model does not support tool calling
(see configuration below).
??? note "Configuration"
To disable tool calling tests, set `has_tool_calling` to `False` in your
test class:
```python
class TestMyChatModelIntegration(ChatModelIntegrationTests):
@property
def has_tool_calling(self) -> bool:
return False
```
??? question "Troubleshooting"
If this test fails, check that:
1. The model can correctly handle message histories that include
`AIMessage` objects with list content.
2. The `tool_calls` attribute on `AIMessage` objects is correctly
handled and passed to the model in an appropriate format.
3. The model can correctly handle ToolMessage objects with string content
and arbitrary string values for `tool_call_id`.
You can `xfail` the test if tool calling is implemented but this format
is not supported.
```python
@pytest.mark.xfail(reason=("Not implemented."))
def test_tool_message_histories_list_content(self, *args: Any) -> None:
super().test_tool_message_histories_list_content(*args)
```
"""
if not self.has_tool_calling:
pytest.skip("Test requires tool calling.")
model_with_tools = model.bind_tools([my_adder_tool])
function_name = "my_adder_tool"
function_args = {"a": 1, "b": 2}
messages_list_content = [
HumanMessage("What is 1 + 2"),
# List content (e.g., Anthropic)
AIMessage(
[
{"type": "text", "text": "some text"},
{
"type": "tool_use",
"id": "abc123",
"name": function_name,
"input": function_args,
},
],
tool_calls=[
{
Domain
Subdomains
Source
Frequently Asked Questions
What does test_tool_message_histories_list_content() do?
test_tool_message_histories_list_content() is a function in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py.
Where is test_tool_message_histories_list_content() defined?
test_tool_message_histories_list_content() is defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py at line 1816.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free