Home / Class/ ToolsAgentOutputParser Class — langchain Architecture

ToolsAgentOutputParser Class — langchain Architecture

Architecture documentation for the ToolsAgentOutputParser class in tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  7e9b794a_0457_fa5c_bbf3_e1ff79c8d364["ToolsAgentOutputParser"]
  5737332b_3e72_7783_8918_d16b746de940["MultiActionAgentOutputParser"]
  7e9b794a_0457_fa5c_bbf3_e1ff79c8d364 -->|extends| 5737332b_3e72_7783_8918_d16b746de940
  2bdc4d81_5592_3e8d_1079_4eb50790f1d0["ChatGeneration"]
  7e9b794a_0457_fa5c_bbf3_e1ff79c8d364 -->|extends| 2bdc4d81_5592_3e8d_1079_4eb50790f1d0
  db6a0881_03ef_4ad3_497e_fcf440388557["tools.py"]
  7e9b794a_0457_fa5c_bbf3_e1ff79c8d364 -->|defined in| db6a0881_03ef_4ad3_497e_fcf440388557
  16cc393e_cb1e_25f4_13b2_6b7a2f9ce440["_type()"]
  7e9b794a_0457_fa5c_bbf3_e1ff79c8d364 -->|method| 16cc393e_cb1e_25f4_13b2_6b7a2f9ce440
  57d58e2b_a110_69e9_a307_f50614a02b43["parse_result()"]
  7e9b794a_0457_fa5c_bbf3_e1ff79c8d364 -->|method| 57d58e2b_a110_69e9_a307_f50614a02b43
  1c10efe0_ee18_65d3_9d85_57a83c125f9a["parse()"]
  7e9b794a_0457_fa5c_bbf3_e1ff79c8d364 -->|method| 1c10efe0_ee18_65d3_9d85_57a83c125f9a

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/output_parsers/tools.py lines 87–116

class ToolsAgentOutputParser(MultiActionAgentOutputParser):
    """Parses a message into agent actions/finish.

    If a tool_calls parameter is passed, then that is used to get
    the tool names and tool inputs.

    If one is not passed, then the AIMessage is assumed to be the final output.
    """

    @property
    def _type(self) -> str:
        return "tools-agent-output-parser"

    @override
    def parse_result(
        self,
        result: list[Generation],
        *,
        partial: bool = False,
    ) -> list[AgentAction] | AgentFinish:
        if not isinstance(result[0], ChatGeneration):
            msg = "This output parser only works on ChatGeneration output"
            raise ValueError(msg)  # noqa: TRY004
        message = result[0].message
        return parse_ai_message_to_tool_action(message)

    @override
    def parse(self, text: str) -> list[AgentAction] | AgentFinish:
        msg = "Can only parse messages"
        raise ValueError(msg)

Frequently Asked Questions

What is the ToolsAgentOutputParser class?
ToolsAgentOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/output_parsers/tools.py.
Where is ToolsAgentOutputParser defined?
ToolsAgentOutputParser is defined in libs/langchain/langchain_classic/agents/output_parsers/tools.py at line 87.
What does ToolsAgentOutputParser extend?
ToolsAgentOutputParser extends MultiActionAgentOutputParser, ChatGeneration.

Analyze Your Own Codebase

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

Try Supermodel Free