Home / File/ test_xml.py — langchain Source File

test_xml.py — langchain Source File

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

File python CoreAbstractions Serialization 2 imports 5 functions

Entity Profile

Dependency Diagram

graph LR
  7731ee09_cb43_cf57_bda7_0571366103e9["test_xml.py"]
  80d582c5_7cc3_ac96_2742_3dbe1cbd4e2b["langchain_core.agents"]
  7731ee09_cb43_cf57_bda7_0571366103e9 --> 80d582c5_7cc3_ac96_2742_3dbe1cbd4e2b
  6c9b29eb_d57e_f4c7_286a_ee223575f947["langchain_classic.agents.format_scratchpad.xml"]
  7731ee09_cb43_cf57_bda7_0571366103e9 --> 6c9b29eb_d57e_f4c7_286a_ee223575f947
  style 7731ee09_cb43_cf57_bda7_0571366103e9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from langchain_core.agents import AgentAction

from langchain_classic.agents.format_scratchpad.xml import format_xml


def test_single_agent_action_observation() -> None:
    # Arrange
    agent_action = AgentAction(tool="Tool1", tool_input="Input1", log="Log1")
    observation = "Observation1"
    intermediate_steps = [(agent_action, observation)]

    # Act
    result = format_xml(intermediate_steps)
    expected_result = """<tool>Tool1</tool><tool_input>Input1\
</tool_input><observation>Observation1</observation>"""
    # Assert
    assert result == expected_result


def test_multiple_agent_actions_observations() -> None:
    # Arrange
    agent_action1 = AgentAction(tool="Tool1", tool_input="Input1", log="Log1")
    agent_action2 = AgentAction(tool="Tool2", tool_input="Input2", log="Log2")
    observation1 = "Observation1"
    observation2 = "Observation2"
    intermediate_steps = [(agent_action1, observation1), (agent_action2, observation2)]

    # Act
    result = format_xml(intermediate_steps)

    # Assert
    expected_result = """<tool>Tool1</tool><tool_input>Input1\
</tool_input><observation>Observation1</observation><tool>\
Tool2</tool><tool_input>Input2</tool_input><observation>\
Observation2</observation>"""
    assert result == expected_result


def test_empty_list_agent_actions() -> None:
    result = format_xml([])
    assert result == ""


def test_xml_escaping_minimal() -> None:
    """Test that XML tags in tool names are escaped with minimal format."""
    # Arrange
    agent_action = AgentAction(
        tool="search<tool>nested</tool>", tool_input="query<input>test</input>", log=""
    )
    observation = "Found <observation>result</observation>"
    intermediate_steps = [(agent_action, observation)]

    # Act
    result = format_xml(intermediate_steps, escape_format="minimal")

    # Assert - XML tags should be replaced with custom delimiters
    expected_result = (
        "<tool>search[[tool]]nested[[/tool]]</tool>"
        "<tool_input>query<input>test</input></tool_input>"
        "<observation>Found [[observation]]result[[/observation]]</observation>"
    )
    assert result == expected_result


def test_no_escaping() -> None:
    """Test that escaping can be disabled."""
    # Arrange
    agent_action = AgentAction(tool="Tool1", tool_input="Input1", log="")
    observation = "Observation1"
    intermediate_steps = [(agent_action, observation)]

    # Act
    result = format_xml(intermediate_steps, escape_format=None)

    # Assert
    expected_result = (
        "<tool>Tool1</tool><tool_input>Input1</tool_input>"
        "<observation>Observation1</observation>"
    )
    assert result == expected_result

Subdomains

Dependencies

  • langchain_classic.agents.format_scratchpad.xml
  • langchain_core.agents

Frequently Asked Questions

What does test_xml.py do?
test_xml.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in test_xml.py?
test_xml.py defines 5 function(s): test_empty_list_agent_actions, test_multiple_agent_actions_observations, test_no_escaping, test_single_agent_action_observation, test_xml_escaping_minimal.
What does test_xml.py depend on?
test_xml.py imports 2 module(s): langchain_classic.agents.format_scratchpad.xml, langchain_core.agents.
Where is test_xml.py in the architecture?
test_xml.py is located at libs/langchain/tests/unit_tests/agents/format_scratchpad/test_xml.py (domain: CoreAbstractions, subdomain: Serialization, 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