{"version":3,"file":"openai_functions.cjs","names":["AIMessage","HumanMessage","TEMPLATE_TOOL_RESPONSE","FunctionMessage"],"sources":["../../../src/agents/format_scratchpad/openai_functions.ts"],"sourcesContent":["import {\n  AIMessage,\n  type BaseMessage,\n  HumanMessage,\n  FunctionMessage,\n} from \"@langchain/core/messages\";\nimport type { AgentStep } from \"@langchain/core/agents\";\nimport { renderTemplate } from \"@langchain/core/prompts\";\nimport { TEMPLATE_TOOL_RESPONSE } from \"../chat_convo/prompt.js\";\n\n/**\n * Format a list of AgentSteps into a list of BaseMessage instances for\n * agents that use OpenAI's API. Helpful for passing in previous agent\n * step context into new iterations.\n *\n * @param steps A list of AgentSteps to format.\n * @returns A list of BaseMessages.\n */\nexport function formatForOpenAIFunctions(steps: AgentStep[]): BaseMessage[] {\n  const thoughts: BaseMessage[] = [];\n  for (const step of steps) {\n    thoughts.push(new AIMessage(step.action.log));\n    thoughts.push(\n      new HumanMessage(\n        renderTemplate(TEMPLATE_TOOL_RESPONSE, \"f-string\", {\n          observation: step.observation,\n        })\n      )\n    );\n  }\n  return thoughts;\n}\n\n/**\n * Format a list of AgentSteps into a list of BaseMessage instances for\n * agents that use OpenAI's API. Helpful for passing in previous agent\n * step context into new iterations.\n *\n * @param steps A list of AgentSteps to format.\n * @returns A list of BaseMessages.\n */\nexport function formatToOpenAIFunctionMessages(\n  steps: AgentStep[]\n): BaseMessage[] {\n  return steps.flatMap(({ action, observation }) => {\n    if (\"messageLog\" in action && action.messageLog !== undefined) {\n      const log = action.messageLog as BaseMessage[];\n      return log.concat(new FunctionMessage(observation, action.tool));\n    } else {\n      return [new AIMessage(action.log)];\n    }\n  });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAgB,yBAAyB,OAAmC;CAC1E,MAAM,WAA0B,EAAE;AAClC,MAAK,MAAM,QAAQ,OAAO;AACxB,WAAS,KAAK,IAAIA,yBAAAA,UAAU,KAAK,OAAO,IAAI,CAAC;AAC7C,WAAS,KACP,IAAIC,yBAAAA,cAAAA,GAAAA,wBAAAA,gBACaC,eAAAA,wBAAwB,YAAY,EACjD,aAAa,KAAK,aACnB,CAAC,CACH,CACF;;AAEH,QAAO;;;;;;;;;;AAWT,SAAgB,+BACd,OACe;AACf,QAAO,MAAM,SAAS,EAAE,QAAQ,kBAAkB;AAChD,MAAI,gBAAgB,UAAU,OAAO,eAAe,KAAA,EAElD,QADY,OAAO,WACR,OAAO,IAAIC,yBAAAA,gBAAgB,aAAa,OAAO,KAAK,CAAC;MAEhE,QAAO,CAAC,IAAIH,yBAAAA,UAAU,OAAO,IAAI,CAAC;GAEpC"}