{"version":3,"file":"tool_calling.cjs","names":["ToolMessage","AIMessage"],"sources":["../../../src/agents/format_scratchpad/tool_calling.ts"],"sourcesContent":["import { AIMessage, BaseMessage, ToolMessage } from \"@langchain/core/messages\";\nimport { ToolsAgentStep } from \"../tool_calling/output_parser.js\";\n\n/**\n * Convert agent action and observation into a function message.\n * @param agentAction - The tool invocation request from the agent\n * @param observation - The result of the tool invocation\n * @returns FunctionMessage that corresponds to the original tool invocation\n */\nexport function _createToolMessage(step: ToolsAgentStep): ToolMessage {\n  return new ToolMessage({\n    tool_call_id: step.action.toolCallId,\n    content: step.observation,\n    additional_kwargs: { name: step.action.tool },\n  });\n}\n\nexport function formatToToolMessages(steps: ToolsAgentStep[]): 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(_createToolMessage({ action, observation }));\n    } else {\n      return [new AIMessage(action.log)];\n    }\n  });\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,mBAAmB,MAAmC;AACpE,QAAO,IAAIA,yBAAAA,YAAY;EACrB,cAAc,KAAK,OAAO;EAC1B,SAAS,KAAK;EACd,mBAAmB,EAAE,MAAM,KAAK,OAAO,MAAM;EAC9C,CAAC;;AAGJ,SAAgB,qBAAqB,OAAwC;AAC3E,QAAO,MAAM,SAAS,EAAE,QAAQ,kBAAkB;AAChD,MAAI,gBAAgB,UAAU,OAAO,eAAe,KAAA,EAElD,QADY,OAAO,WACR,OAAO,mBAAmB;GAAE;GAAQ;GAAa,CAAC,CAAC;MAE9D,QAAO,CAAC,IAAIC,yBAAAA,UAAU,OAAO,IAAI,CAAC;GAEpC"}