{"version":3,"file":"outputParser.cjs","names":["AgentActionOutputParser","OutputParserException","FORMAT_INSTRUCTIONS"],"sources":["../../../src/agents/mrkl/outputParser.ts"],"sourcesContent":["import { OutputParserException } from \"@langchain/core/output_parsers\";\nimport { OutputParserArgs } from \"../agent.js\";\nimport { AgentActionOutputParser } from \"../types.js\";\n\nimport { FORMAT_INSTRUCTIONS } from \"./prompt.js\";\n\nexport const FINAL_ANSWER_ACTION = \"Final Answer:\";\n/**\n * A class that extends `AgentActionOutputParser` to provide a custom\n * implementation for parsing the output of a ZeroShotAgent action.\n */\nexport class ZeroShotAgentOutputParser extends AgentActionOutputParser {\n  lc_namespace = [\"langchain\", \"agents\", \"mrkl\"];\n\n  finishToolName: string;\n\n  constructor(fields?: OutputParserArgs) {\n    super(fields);\n    this.finishToolName = fields?.finishToolName || FINAL_ANSWER_ACTION;\n  }\n\n  /**\n   * Parses the text output of an agent action, extracting the tool, tool\n   * input, and output.\n   * @param text The text output of an agent action.\n   * @returns An object containing the tool, tool input, and output extracted from the text, along with the original text as a log.\n   */\n  async parse(text: string) {\n    if (text.includes(this.finishToolName)) {\n      const parts = text.split(this.finishToolName);\n      const output = parts[parts.length - 1].trim();\n      return {\n        returnValues: { output },\n        log: text,\n      };\n    }\n\n    const match = /Action:([\\s\\S]*?)(?:\\nAction Input:([\\s\\S]*?))?$/.exec(text);\n    if (!match) {\n      throw new OutputParserException(`Could not parse LLM output: ${text}`);\n    }\n\n    return {\n      tool: match[1].trim(),\n      toolInput: match[2]\n        ? match[2].trim().replace(/^(\"+)(.*?)(\\1)$/, \"$2\")\n        : \"\",\n      log: text,\n    };\n  }\n\n  /**\n   * Returns the format instructions for parsing the output of an agent\n   * action in the style of the ZeroShotAgent.\n   * @returns The format instructions for parsing the output.\n   */\n  getFormatInstructions(): string {\n    return FORMAT_INSTRUCTIONS;\n  }\n}\n"],"mappings":";;;;;;;;AAWA,IAAa,4BAAb,cAA+CA,cAAAA,wBAAwB;CACrE,eAAe;EAAC;EAAa;EAAU;EAAO;CAE9C;CAEA,YAAY,QAA2B;AACrC,QAAM,OAAO;AACb,OAAK,iBAAiB,QAAQ,kBAAA;;;;;;;;CAShC,MAAM,MAAM,MAAc;AACxB,MAAI,KAAK,SAAS,KAAK,eAAe,EAAE;GACtC,MAAM,QAAQ,KAAK,MAAM,KAAK,eAAe;AAE7C,UAAO;IACL,cAAc,EAAE,QAFH,MAAM,MAAM,SAAS,GAAG,MAAM,EAEnB;IACxB,KAAK;IACN;;EAGH,MAAM,QAAQ,mDAAmD,KAAK,KAAK;AAC3E,MAAI,CAAC,MACH,OAAM,IAAIC,+BAAAA,sBAAsB,+BAA+B,OAAO;AAGxE,SAAO;GACL,MAAM,MAAM,GAAG,MAAM;GACrB,WAAW,MAAM,KACb,MAAM,GAAG,MAAM,CAAC,QAAQ,mBAAmB,KAAK,GAChD;GACJ,KAAK;GACN;;;;;;;CAQH,wBAAgC;AAC9B,SAAOC,eAAAA"}