Home / Function/ test_tool_runtime_async_injection() — langchain Function Reference

test_tool_runtime_async_injection() — langchain Function Reference

Architecture documentation for the test_tool_runtime_async_injection() function in test_injected_runtime_create_agent.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  849abde7_ba1b_3e7a_1d2f_1826b451c113["test_tool_runtime_async_injection()"]
  a4d83fe9_0a39_5761_b1a5_de54f81974c9["test_injected_runtime_create_agent.py"]
  849abde7_ba1b_3e7a_1d2f_1826b451c113 -->|defined in| a4d83fe9_0a39_5761_b1a5_de54f81974c9
  style 849abde7_ba1b_3e7a_1d2f_1826b451c113 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/test_injected_runtime_create_agent.py lines 84–120

async def test_tool_runtime_async_injection() -> None:
    """Test ToolRuntime injection works with async tools."""
    injected_data: dict[str, Any] = {}

    @tool
    async def async_runtime_tool(x: int, runtime: ToolRuntime) -> str:
        """Async tool that accesses runtime context."""
        injected_data["state"] = runtime.state
        injected_data["tool_call_id"] = runtime.tool_call_id
        injected_data["config"] = runtime.config
        return f"Async processed {x}"

    agent = create_agent(
        model=FakeToolCallingModel(
            tool_calls=[
                [{"args": {"x": 99}, "id": "async_call_456", "name": "async_runtime_tool"}],
                [],
            ]
        ),
        tools=[async_runtime_tool],
        system_prompt="You are a helpful assistant.",
    )

    result = await agent.ainvoke({"messages": [HumanMessage("Test async")]})

    # Verify tool executed
    assert len(result["messages"]) == 4
    tool_message = result["messages"][2]
    assert isinstance(tool_message, ToolMessage)
    assert tool_message.content == "Async processed 99"
    assert tool_message.tool_call_id == "async_call_456"

    # Verify runtime was injected
    assert injected_data["state"] is not None
    assert "messages" in injected_data["state"]
    assert injected_data["tool_call_id"] == "async_call_456"
    assert injected_data["config"] is not None

Domain

Subdomains

Frequently Asked Questions

What does test_tool_runtime_async_injection() do?
test_tool_runtime_async_injection() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/test_injected_runtime_create_agent.py.
Where is test_tool_runtime_async_injection() defined?
test_tool_runtime_async_injection() is defined in libs/langchain_v1/tests/unit_tests/agents/test_injected_runtime_create_agent.py at line 84.

Analyze Your Own Codebase

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

Try Supermodel Free