Home / Function/ test_agent_loop() — langchain Function Reference

test_agent_loop() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/partners/anthropic/tests/integration_tests/test_chat_models.py lines 893–916

def test_agent_loop(output_version: Literal["v0", "v1"]) -> None:
    @tool
    def get_weather(location: str) -> str:
        """Get the weather for a location."""
        return "It's sunny."

    llm = ChatAnthropic(model=MODEL_NAME, output_version=output_version)  # type: ignore[call-arg]
    llm_with_tools = llm.bind_tools([get_weather])
    input_message = HumanMessage("What is the weather in San Francisco, CA?")
    tool_call_message = llm_with_tools.invoke([input_message])
    assert isinstance(tool_call_message, AIMessage)
    tool_calls = tool_call_message.tool_calls
    assert len(tool_calls) == 1
    tool_call = tool_calls[0]
    tool_message = get_weather.invoke(tool_call)
    assert isinstance(tool_message, ToolMessage)
    response = llm_with_tools.invoke(
        [
            input_message,
            tool_call_message,
            tool_message,
        ]
    )
    assert isinstance(response, AIMessage)

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free