{"version":3,"file":"output_parser.cjs","names":["AgentActionOutputParser","OutputParserException"],"sources":["../../../src/agents/xml/output_parser.ts"],"sourcesContent":["import { AgentAction, AgentFinish } from \"@langchain/core/agents\";\nimport { OutputParserException } from \"@langchain/core/output_parsers\";\nimport { AgentActionOutputParser } from \"../types.js\";\n\n/**\n * @example\n * ```typescript\n * const prompt = ChatPromptTemplate.fromMessages([\n *   HumanMessagePromptTemplate.fromTemplate(AGENT_INSTRUCTIONS),\n *   new MessagesPlaceholder(\"agent_scratchpad\"),\n * ]);\n * const runnableAgent = RunnableSequence.from([\n *   ...rest of runnable\n *   prompt,\n *   new ChatAnthropic({ modelName: \"claude-2\", temperature: 0 }).withConfig({\n *     stop: [\"</tool_input>\", \"</final_answer>\"],\n *   }),\n *   new XMLAgentOutputParser(),\n * ]);\n * const result = await executor.invoke({\n *   input: \"What is the weather in Honolulu?\",\n *   tools: [],\n * });\n * ```\n */\nexport class XMLAgentOutputParser extends AgentActionOutputParser {\n  lc_namespace = [\"langchain\", \"agents\", \"xml\"];\n\n  static lc_name() {\n    return \"XMLAgentOutputParser\";\n  }\n\n  /**\n   * Parses the output text from the agent and returns an AgentAction or\n   * AgentFinish object.\n   * @param text The output text from the agent.\n   * @returns An AgentAction or AgentFinish object.\n   */\n  async parse(text: string): Promise<AgentAction | AgentFinish> {\n    if (text.includes(\"</tool>\")) {\n      const _toolMatch = text.match(/<tool>([^<]*)<\\/tool>/);\n      const _tool = _toolMatch ? _toolMatch[1] : \"\";\n      const _toolInputMatch = text.match(\n        /<tool_input>([^<]*?)(?:<\\/tool_input>|$)/\n      );\n      const _toolInput = _toolInputMatch ? _toolInputMatch[1] : \"\";\n      return { tool: _tool, toolInput: _toolInput, log: text };\n    } else if (text.includes(\"<final_answer>\")) {\n      const answerMatch = text.match(\n        /<final_answer>([^<]*?)(?:<\\/final_answer>|$)/\n      );\n      const answer = answerMatch ? answerMatch[1] : \"\";\n      return { returnValues: { output: answer }, log: text };\n    } else {\n      throw new OutputParserException(`Could not parse LLM output: ${text}`);\n    }\n  }\n\n  getFormatInstructions(): string {\n    throw new Error(\n      \"getFormatInstructions not implemented inside OpenAIFunctionsAgentOutputParser.\"\n    );\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,uBAAb,cAA0CA,cAAAA,wBAAwB;CAChE,eAAe;EAAC;EAAa;EAAU;EAAM;CAE7C,OAAO,UAAU;AACf,SAAO;;;;;;;;CAST,MAAM,MAAM,MAAkD;AAC5D,MAAI,KAAK,SAAS,UAAU,EAAE;GAC5B,MAAM,aAAa,KAAK,MAAM,wBAAwB;GACtD,MAAM,QAAQ,aAAa,WAAW,KAAK;GAC3C,MAAM,kBAAkB,KAAK,MAC3B,2CACD;AAED,UAAO;IAAE,MAAM;IAAO,WADH,kBAAkB,gBAAgB,KAAK;IACb,KAAK;IAAM;aAC/C,KAAK,SAAS,iBAAiB,EAAE;GAC1C,MAAM,cAAc,KAAK,MACvB,+CACD;AAED,UAAO;IAAE,cAAc,EAAE,QADV,cAAc,YAAY,KAAK,IACL;IAAE,KAAK;IAAM;QAEtD,OAAM,IAAIC,+BAAAA,sBAAsB,+BAA+B,OAAO;;CAI1E,wBAAgC;AAC9B,QAAM,IAAI,MACR,iFACD"}