Home / Class/ TestLLMToolEmulatorAsync Class — langchain Architecture

TestLLMToolEmulatorAsync Class — langchain Architecture

Architecture documentation for the TestLLMToolEmulatorAsync class in test_tool_emulator.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  b8b6edb5_5f70_2c98_97cd_e94de900fbeb["TestLLMToolEmulatorAsync"]
  de5a7878_b3fe_95d7_2575_7f534546dc1e["AIMessage"]
  b8b6edb5_5f70_2c98_97cd_e94de900fbeb -->|extends| de5a7878_b3fe_95d7_2575_7f534546dc1e
  5b00cf78_0f18_c9ad_fc5f_85cc0378daf1["test_tool_emulator.py"]
  b8b6edb5_5f70_2c98_97cd_e94de900fbeb -->|defined in| 5b00cf78_0f18_c9ad_fc5f_85cc0378daf1
  80990747_28fe_8c53_dc58_e85096274724["test_async_emulates_specified_tool_by_name()"]
  b8b6edb5_5f70_2c98_97cd_e94de900fbeb -->|method| 80990747_28fe_8c53_dc58_e85096274724
  469df27e_dbb2_7ae8_b72f_e7e95ec844de["test_async_emulates_specified_tool_by_instance()"]
  b8b6edb5_5f70_2c98_97cd_e94de900fbeb -->|method| 469df27e_dbb2_7ae8_b72f_e7e95ec844de
  6c3a23a7_b767_d469_b4ac_4f5c61c00056["test_async_non_emulated_tools_execute_normally()"]
  b8b6edb5_5f70_2c98_97cd_e94de900fbeb -->|method| 6c3a23a7_b767_d469_b4ac_4f5c61c00056
  2ab0dd1c_28ed_c632_1b89_196126f1c1e1["test_async_none_tools_emulates_all()"]
  b8b6edb5_5f70_2c98_97cd_e94de900fbeb -->|method| 2ab0dd1c_28ed_c632_1b89_196126f1c1e1
  82f20f76_92a0_7e35_9091_c5696fb1a244["test_async_emulate_multiple_tools()"]
  b8b6edb5_5f70_2c98_97cd_e94de900fbeb -->|method| 82f20f76_92a0_7e35_9091_c5696fb1a244
  3e2a35a1_3f58_b0ee_e045_e4b34f4e1df1["test_async_mixed_emulated_and_real_tools()"]
  b8b6edb5_5f70_2c98_97cd_e94de900fbeb -->|method| 3e2a35a1_3f58_b0ee_e045_e4b34f4e1df1

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_emulator.py lines 421–623

class TestLLMToolEmulatorAsync:
    """Test async tool emulator functionality."""

    async def test_async_emulates_specified_tool_by_name(self) -> None:
        """Test that tools specified by name are emulated in async mode."""
        agent_model = FakeModel(
            messages=cycle(
                [
                    AIMessage(
                        content="",
                        tool_calls=[
                            {"name": "get_weather", "id": "1", "args": {"location": "Paris"}}
                        ],
                    ),
                    AIMessage(content="The weather has been retrieved."),
                ]
            )
        )

        emulator_model = FakeEmulatorModel(responses=["Emulated: 72°F, sunny in Paris"])

        emulator = LLMToolEmulator(tools=["get_weather"], model=emulator_model)

        agent = create_agent(
            model=agent_model,
            tools=[get_weather, calculator],
            middleware=[emulator],
        )

        result = await agent.ainvoke({"messages": [HumanMessage("What's the weather in Paris?")]})

        # Should complete without raising NotImplementedError
        assert isinstance(result["messages"][-1], AIMessage)

    async def test_async_emulates_specified_tool_by_instance(self) -> None:
        """Test that tools specified by BaseTool instance are emulated in async mode."""
        agent_model = FakeModel(
            messages=cycle(
                [
                    AIMessage(
                        content="",
                        tool_calls=[{"name": "search_web", "id": "1", "args": {"query": "Python"}}],
                    ),
                    AIMessage(content="Search results retrieved."),
                ]
            )
        )

        emulator_model = FakeEmulatorModel(responses=["Emulated: Python is a programming language"])

        emulator = LLMToolEmulator(tools=[search_web], model=emulator_model)

        agent = create_agent(
            model=agent_model,
            tools=[search_web, calculator],
            middleware=[emulator],
        )

        result = await agent.ainvoke({"messages": [HumanMessage("Search for Python")]})

        assert isinstance(result["messages"][-1], AIMessage)

    async def test_async_non_emulated_tools_execute_normally(self) -> None:
        """Test that tools not in tools_to_emulate execute normally in async mode."""
        agent_model = FakeModel(
            messages=cycle(
                [
                    AIMessage(
                        content="",
                        tool_calls=[
                            {"name": "calculator", "id": "1", "args": {"expression": "2+2"}}
                        ],
                    ),
                    AIMessage(content="The calculation is complete."),
                ]
            )
        )

        emulator_model = FakeEmulatorModel(responses=["Should not be used"])

        # Only emulate get_weather, not calculator

Extends

Frequently Asked Questions

What is the TestLLMToolEmulatorAsync class?
TestLLMToolEmulatorAsync is a class in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_emulator.py.
Where is TestLLMToolEmulatorAsync defined?
TestLLMToolEmulatorAsync is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_emulator.py at line 421.
What does TestLLMToolEmulatorAsync extend?
TestLLMToolEmulatorAsync extends AIMessage.

Analyze Your Own Codebase

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

Try Supermodel Free