test_tool_message_histories_string_content() — langchain Function Reference
Architecture documentation for the test_tool_message_histories_string_content() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 9a87ba50_5760_7362_f7b7_b69c163b52f8["test_tool_message_histories_string_content()"] 971e928f_9c9b_ce7a_b93d_e762f2f5aa54["ChatModelIntegrationTests"] 9a87ba50_5760_7362_f7b7_b69c163b52f8 -->|defined in| 971e928f_9c9b_ce7a_b93d_e762f2f5aa54 style 9a87ba50_5760_7362_f7b7_b69c163b52f8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/standard-tests/langchain_tests/integration_tests/chat_models.py lines 1742–1814
def test_tool_message_histories_string_content(
self, model: BaseChatModel, my_adder_tool: BaseTool
) -> None:
"""Test that message histories are compatible with string tool contents.
For instance with OpenAI format contents.
If a model passes this test, it should be compatible
with messages generated from providers following OpenAI format.
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 `""` 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_string_content(self, *args: Any) -> None:
super().test_tool_message_histories_string_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_string_content = [
HumanMessage("What is 1 + 2"),
# string content (e.g. OpenAI)
AIMessage(
"",
tool_calls=[
{
"name": function_name,
"args": function_args,
"id": "abc123",
"type": "tool_call",
},
],
),
ToolMessage(
json.dumps({"result": 3}),
name=function_name,
tool_call_id="abc123",
),
]
result_string_content = model_with_tools.invoke(messages_string_content)
assert isinstance(result_string_content, AIMessage)
Domain
Subdomains
Source
Frequently Asked Questions
What does test_tool_message_histories_string_content() do?
test_tool_message_histories_string_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_string_content() defined?
test_tool_message_histories_string_content() is defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py at line 1742.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free