Home / Class/ TestLLMToolEmulatorBasic Class — langchain Architecture

TestLLMToolEmulatorBasic Class — langchain Architecture

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

Entity Profile

Dependency Diagram

graph TD
  f4edbff2_7ddf_8a09_14d8_c5faf6609d38["TestLLMToolEmulatorBasic"]
  de5a7878_b3fe_95d7_2575_7f534546dc1e["AIMessage"]
  f4edbff2_7ddf_8a09_14d8_c5faf6609d38 -->|extends| de5a7878_b3fe_95d7_2575_7f534546dc1e
  5b00cf78_0f18_c9ad_fc5f_85cc0378daf1["test_tool_emulator.py"]
  f4edbff2_7ddf_8a09_14d8_c5faf6609d38 -->|defined in| 5b00cf78_0f18_c9ad_fc5f_85cc0378daf1
  9a30a8a1_ce8b_02ae_b044_b6c6300e2877["test_emulates_specified_tool_by_name()"]
  f4edbff2_7ddf_8a09_14d8_c5faf6609d38 -->|method| 9a30a8a1_ce8b_02ae_b044_b6c6300e2877
  7ecc5de1_4551_25b9_3f46_b558a87627f9["test_emulates_specified_tool_by_instance()"]
  f4edbff2_7ddf_8a09_14d8_c5faf6609d38 -->|method| 7ecc5de1_4551_25b9_3f46_b558a87627f9
  cf50a1c8_6424_5097_ee7e_7e20e3669a80["test_non_emulated_tools_execute_normally()"]
  f4edbff2_7ddf_8a09_14d8_c5faf6609d38 -->|method| cf50a1c8_6424_5097_ee7e_7e20e3669a80
  984ec8ee_0c34_b8db_c870_d4203ce6e213["test_empty_tools_to_emulate_does_nothing()"]
  f4edbff2_7ddf_8a09_14d8_c5faf6609d38 -->|method| 984ec8ee_0c34_b8db_c870_d4203ce6e213
  6c67bdb9_e8b8_e81e_4924_7105b09fc0c3["test_none_tools_emulates_all()"]
  f4edbff2_7ddf_8a09_14d8_c5faf6609d38 -->|method| 6c67bdb9_e8b8_e81e_4924_7105b09fc0c3

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_emulator.py lines 118–284

class TestLLMToolEmulatorBasic:
    """Test basic tool emulator functionality."""

    def test_emulates_specified_tool_by_name(self) -> None:
        """Test that tools specified by name are emulated."""
        # Model that will call the tool
        agent_model = FakeModel(
            messages=cycle(
                [
                    AIMessage(
                        content="",
                        tool_calls=[
                            {"name": "get_weather", "id": "1", "args": {"location": "Paris"}}
                        ],
                    ),
                    AIMessage(content="The weather has been retrieved."),
                ]
            )
        )

        # Model that emulates tool responses
        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 = agent.invoke({"messages": [HumanMessage("What's the weather in Paris?")]})

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

    def test_emulates_specified_tool_by_instance(self) -> None:
        """Test that tools specified by BaseTool instance are emulated."""
        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 = agent.invoke({"messages": [HumanMessage("Search for Python")]})

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

    def test_non_emulated_tools_execute_normally(self) -> None:
        """Test that tools not in tools_to_emulate execute normally."""
        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"])

Extends

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free