Home / Class/ OpenAIToolsAgentOutputParser Class — langchain Architecture

OpenAIToolsAgentOutputParser Class — langchain Architecture

Architecture documentation for the OpenAIToolsAgentOutputParser class in openai_tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  74b43e77_d8a5_c926_0852_7149856fc8e6["OpenAIToolsAgentOutputParser"]
  5737332b_3e72_7783_8918_d16b746de940["MultiActionAgentOutputParser"]
  74b43e77_d8a5_c926_0852_7149856fc8e6 -->|extends| 5737332b_3e72_7783_8918_d16b746de940
  2bdc4d81_5592_3e8d_1079_4eb50790f1d0["ChatGeneration"]
  74b43e77_d8a5_c926_0852_7149856fc8e6 -->|extends| 2bdc4d81_5592_3e8d_1079_4eb50790f1d0
  01a8f147_c3fb_2633_e69b_be569e7ac472["openai_tools.py"]
  74b43e77_d8a5_c926_0852_7149856fc8e6 -->|defined in| 01a8f147_c3fb_2633_e69b_be569e7ac472
  16b0af7f_20a6_a37c_8293_91dead281cff["_type()"]
  74b43e77_d8a5_c926_0852_7149856fc8e6 -->|method| 16b0af7f_20a6_a37c_8293_91dead281cff
  882536d0_e325_fbbc_d978_402c399bf73a["parse_result()"]
  74b43e77_d8a5_c926_0852_7149856fc8e6 -->|method| 882536d0_e325_fbbc_d978_402c399bf73a
  d1ea0467_49b0_2229_d5ab_79e63f08c944["parse()"]
  74b43e77_d8a5_c926_0852_7149856fc8e6 -->|method| d1ea0467_49b0_2229_d5ab_79e63f08c944

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/output_parsers/openai_tools.py lines 39–71

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

    Is meant to be used with OpenAI models, as it relies on the specific
    tool_calls parameter from OpenAI to convey what tools to use.

    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 "openai-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_openai_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 OpenAIToolsAgentOutputParser class?
OpenAIToolsAgentOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/output_parsers/openai_tools.py.
Where is OpenAIToolsAgentOutputParser defined?
OpenAIToolsAgentOutputParser is defined in libs/langchain/langchain_classic/agents/output_parsers/openai_tools.py at line 39.
What does OpenAIToolsAgentOutputParser extend?
OpenAIToolsAgentOutputParser extends MultiActionAgentOutputParser, ChatGeneration.

Analyze Your Own Codebase

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

Try Supermodel Free