test_tool_calling_async() — langchain Function Reference
Architecture documentation for the test_tool_calling_async() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD ea8f4255_67c7_7352_2219_71761cc9609d["test_tool_calling_async()"] 971e928f_9c9b_ce7a_b93d_e762f2f5aa54["ChatModelIntegrationTests"] ea8f4255_67c7_7352_2219_71761cc9609d -->|defined in| 971e928f_9c9b_ce7a_b93d_e762f2f5aa54 93a476c6_2ee3_787e_23b4_3d1e8b2d3794["magic_function()"] ea8f4255_67c7_7352_2219_71761cc9609d -->|calls| 93a476c6_2ee3_787e_23b4_3d1e8b2d3794 873906e7_1aac_f857_fbc7_973f8d33d1de["_validate_tool_call_message()"] ea8f4255_67c7_7352_2219_71761cc9609d -->|calls| 873906e7_1aac_f857_fbc7_973f8d33d1de style ea8f4255_67c7_7352_2219_71761cc9609d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/standard-tests/langchain_tests/integration_tests/chat_models.py lines 1615–1675
async def test_tool_calling_async(self, model: BaseChatModel) -> None:
"""Test that the model generates tool calls.
This test is skipped if the `has_tool_calling` property on the test class is
set to `False`.
This test is optional and 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 `bind_tools` is implemented to correctly
translate LangChain tool objects into the appropriate schema for your
chat model.
This test may fail if the chat model does not support a `tool_choice`
parameter. This parameter can be used to force a tool call. If
`tool_choice` is not supported and the model consistently fails this
test, you can `xfail` the test:
```python
@pytest.mark.xfail(reason=("Does not support tool_choice."))
async def test_tool_calling_async(self, model: BaseChatModel) -> None:
await super().test_tool_calling_async(model)
```
Otherwise, in the case that only one tool is bound, ensure that
`tool_choice` supports the string `'any'` to force calling that tool.
"""
if not self.has_tool_calling:
pytest.skip("Test requires tool calling.")
tool_choice_value = None if not self.has_tool_choice else "any"
model_with_tools = model.bind_tools(
[magic_function], tool_choice=tool_choice_value
)
# Test ainvoke
query = "What is the value of magic_function(3)? Use the tool."
result = await model_with_tools.ainvoke(query)
_validate_tool_call_message(result)
# Test astream
full: BaseMessage | None = None
async for chunk in model_with_tools.astream(query):
full = chunk if full is None else full + chunk # type: ignore[assignment]
assert isinstance(full, AIMessage)
_validate_tool_call_message(full)
Domain
Subdomains
Source
Frequently Asked Questions
What does test_tool_calling_async() do?
test_tool_calling_async() is a function in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py.
Where is test_tool_calling_async() defined?
test_tool_calling_async() is defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py at line 1615.
What does test_tool_calling_async() call?
test_tool_calling_async() calls 2 function(s): _validate_tool_call_message, magic_function.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free