Home / Function/ test_async_tool_use() — langchain Function Reference

test_async_tool_use() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  c8465ee4_fc01_ac75_7e61_070f9bd16205["test_async_tool_use()"]
  f27640dd_3870_5548_d153_f9504ae1021f["test_chat_models.py"]
  c8465ee4_fc01_ac75_7e61_070f9bd16205 -->|defined in| f27640dd_3870_5548_d153_f9504ae1021f
  style c8465ee4_fc01_ac75_7e61_070f9bd16205 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/tests/integration_tests/test_chat_models.py lines 187–233

async def test_async_tool_use() -> None:
    llm = ChatAnthropic(
        model=MODEL_NAME,  # type: ignore[call-arg]
    )

    llm_with_tools = llm.bind_tools(
        [
            {
                "name": "get_weather",
                "description": "Get weather report for a city",
                "input_schema": {
                    "type": "object",
                    "properties": {"location": {"type": "string"}},
                },
            },
        ],
    )
    response = await llm_with_tools.ainvoke("what's the weather in san francisco, ca")
    assert isinstance(response, AIMessage)
    assert isinstance(response.content, list)
    assert isinstance(response.tool_calls, list)
    assert len(response.tool_calls) == 1
    tool_call = response.tool_calls[0]
    assert tool_call["name"] == "get_weather"
    assert isinstance(tool_call["args"], dict)
    assert "location" in tool_call["args"]

    # Test streaming
    first = True
    chunks: list[BaseMessage | BaseMessageChunk] = []
    async for chunk in llm_with_tools.astream(
        "what's the weather in san francisco, ca",
    ):
        chunks = [*chunks, chunk]
        if first:
            gathered = chunk
            first = False
        else:
            gathered = gathered + chunk  # type: ignore[assignment]
    assert len(chunks) > 1
    assert isinstance(gathered, AIMessageChunk)
    assert isinstance(gathered.tool_call_chunks, list)
    assert len(gathered.tool_call_chunks) == 1
    tool_call_chunk = gathered.tool_call_chunks[0]
    assert tool_call_chunk["name"] == "get_weather"
    assert isinstance(tool_call_chunk["args"], str)
    assert "location" in json.loads(tool_call_chunk["args"])

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free