Home / Function/ format_xml() — langchain Function Reference

format_xml() — langchain Function Reference

Architecture documentation for the format_xml() function in xml.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  a9d38aeb_60f2_0964_b563_c704ccade390["format_xml()"]
  b9bf24e2_44fd_b9c4_1e4a_a936f78c742f["xml.py"]
  a9d38aeb_60f2_0964_b563_c704ccade390 -->|defined in| b9bf24e2_44fd_b9c4_1e4a_a936f78c742f
  2edd0b5c_4b75_78ea_9267_b9495c190f7c["_escape()"]
  a9d38aeb_60f2_0964_b563_c704ccade390 -->|calls| 2edd0b5c_4b75_78ea_9267_b9495c190f7c
  style a9d38aeb_60f2_0964_b563_c704ccade390 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/format_scratchpad/xml.py lines 21–52

def format_xml(
    intermediate_steps: list[tuple[AgentAction, str]],
    *,
    escape_format: Literal["minimal"] | None = "minimal",
) -> str:
    """Format the intermediate steps as XML.

    Args:
        intermediate_steps: The intermediate steps.
        escape_format: The escaping format to use. Currently only 'minimal' is
            supported, which replaces XML tags with custom delimiters to prevent
            conflicts.

    Returns:
        The intermediate steps as XML.
    """
    log = ""
    for action, observation in intermediate_steps:
        if escape_format == "minimal":
            # Escape XML tags in tool names and inputs using custom delimiters
            tool = _escape(action.tool)
            tool_input = _escape(str(action.tool_input))
            observation_ = _escape(str(observation))
        else:
            tool = action.tool
            tool_input = str(action.tool_input)
            observation_ = str(observation)
        log += (
            f"<tool>{tool}</tool><tool_input>{tool_input}"
            f"</tool_input><observation>{observation_}</observation>"
        )
    return log

Subdomains

Calls

Frequently Asked Questions

What does format_xml() do?
format_xml() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/format_scratchpad/xml.py.
Where is format_xml() defined?
format_xml() is defined in libs/langchain/langchain_classic/agents/format_scratchpad/xml.py at line 21.
What does format_xml() call?
format_xml() calls 1 function(s): _escape.

Analyze Your Own Codebase

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

Try Supermodel Free