Home / Function/ test_fetch_last_ai_and_tool_messages_no_ai_message() — langchain Function Reference

test_fetch_last_ai_and_tool_messages_no_ai_message() — langchain Function Reference

Architecture documentation for the test_fetch_last_ai_and_tool_messages_no_ai_message() function in test_fetch_last_ai_and_tool_messages.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  b14cedee_84b3_321b_aac8_6a060b13ded3["test_fetch_last_ai_and_tool_messages_no_ai_message()"]
  377b132d_d3e1_0d37_8fdd_618ce0d34bb1["test_fetch_last_ai_and_tool_messages.py"]
  b14cedee_84b3_321b_aac8_6a060b13ded3 -->|defined in| 377b132d_d3e1_0d37_8fdd_618ce0d34bb1
  style b14cedee_84b3_321b_aac8_6a060b13ded3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/test_fetch_last_ai_and_tool_messages.py lines 48–65

def test_fetch_last_ai_and_tool_messages_no_ai_message() -> None:
    """Test handling when no AIMessage exists in messages.

    This is the edge case that caused issue #34792 - UnboundLocalError
    when using RemoveMessage(id=REMOVE_ALL_MESSAGES) to clear thread messages.
    The function now returns None for the AIMessage, allowing callers to
    handle this edge case explicitly.
    """
    messages = [
        HumanMessage(content="Hello"),
        SystemMessage(content="You are a helpful assistant"),
    ]

    ai_msg, tool_msgs = _fetch_last_ai_and_tool_messages(messages)

    # Should return None when no AIMessage is found
    assert ai_msg is None
    assert len(tool_msgs) == 0

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free