Home / File/ test_log_to_messages.py — langchain Source File

test_log_to_messages.py — langchain Source File

Architecture documentation for test_log_to_messages.py, a python file in the langchain codebase. 3 imports, 0 dependents.

File python LangChainCore Runnables 3 imports 4 functions

Entity Profile

Dependency Diagram

graph LR
  022a381a_891e_110d_baf6_ddec630c8081["test_log_to_messages.py"]
  59e0d3b0_0f8e_4b79_d442_e9b4821561c7["langchain_core.agents"]
  022a381a_891e_110d_baf6_ddec630c8081 --> 59e0d3b0_0f8e_4b79_d442_e9b4821561c7
  9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"]
  022a381a_891e_110d_baf6_ddec630c8081 --> 9444498b_8066_55c7_b3a2_1d90c4162a32
  74ac89a2_28a0_1483_94f9_e954c774f0d8["langchain_classic.agents.format_scratchpad.log_to_messages"]
  022a381a_891e_110d_baf6_ddec630c8081 --> 74ac89a2_28a0_1483_94f9_e954c774f0d8
  style 022a381a_891e_110d_baf6_ddec630c8081 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from langchain_core.agents import AgentAction
from langchain_core.messages import AIMessage, HumanMessage

from langchain_classic.agents.format_scratchpad.log_to_messages import (
    format_log_to_messages,
)


def test_single_intermediate_step_default_response() -> None:
    intermediate_steps = [
        (AgentAction(tool="Tool1", tool_input="input1", log="Log1"), "Observation1"),
    ]
    expected_result = [AIMessage(content="Log1"), HumanMessage(content="Observation1")]
    assert format_log_to_messages(intermediate_steps) == expected_result


def test_multiple_intermediate_steps_default_response() -> None:
    intermediate_steps = [
        (AgentAction(tool="Tool1", tool_input="input1", log="Log1"), "Observation1"),
        (AgentAction(tool="Tool2", tool_input="input2", log="Log2"), "Observation2"),
        (AgentAction(tool="Tool3", tool_input="input3", log="Log3"), "Observation3"),
    ]
    expected_result = [
        AIMessage(content="Log1"),
        HumanMessage(content="Observation1"),
        AIMessage(content="Log2"),
        HumanMessage(content="Observation2"),
        AIMessage(content="Log3"),
        HumanMessage(content="Observation3"),
    ]
    assert format_log_to_messages(intermediate_steps) == expected_result


def test_custom_template_tool_response() -> None:
    intermediate_steps = [
        (AgentAction(tool="Tool1", tool_input="input1", log="Log1"), "Observation1"),
    ]
    template_tool_response = "Response: {observation}"
    expected_result = [
        AIMessage(content="Log1"),
        HumanMessage(content="Response: Observation1"),
    ]
    assert (
        format_log_to_messages(
            intermediate_steps,
            template_tool_response=template_tool_response,
        )
        == expected_result
    )


def test_empty_steps() -> None:
    assert format_log_to_messages([]) == []

Domain

Subdomains

Dependencies

  • langchain_classic.agents.format_scratchpad.log_to_messages
  • langchain_core.agents
  • langchain_core.messages

Frequently Asked Questions

What does test_log_to_messages.py do?
test_log_to_messages.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, Runnables subdomain.
What functions are defined in test_log_to_messages.py?
test_log_to_messages.py defines 4 function(s): test_custom_template_tool_response, test_empty_steps, test_multiple_intermediate_steps_default_response, test_single_intermediate_step_default_response.
What does test_log_to_messages.py depend on?
test_log_to_messages.py imports 3 module(s): langchain_classic.agents.format_scratchpad.log_to_messages, langchain_core.agents, langchain_core.messages.
Where is test_log_to_messages.py in the architecture?
test_log_to_messages.py is located at libs/langchain/tests/unit_tests/agents/format_scratchpad/test_log_to_messages.py (domain: LangChainCore, subdomain: Runnables, directory: libs/langchain/tests/unit_tests/agents/format_scratchpad).

Analyze Your Own Codebase

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

Try Supermodel Free