{"version":3,"file":"json.cjs","names":["BaseToolkit","JsonListKeysTool","JsonGetValueTool","JSON_PREFIX","JSON_SUFFIX","ZeroShotAgent","LLMChain","AgentExecutor"],"sources":["../../../../src/agents/toolkits/json/json.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { type ToolInterface, BaseToolkit } from \"@langchain/core/tools\";\nimport {\n  JsonGetValueTool,\n  JsonListKeysTool,\n  JsonSpec,\n} from \"../../../tools/json.js\";\nimport { JSON_PREFIX, JSON_SUFFIX } from \"./prompt.js\";\nimport { LLMChain } from \"../../../chains/llm_chain.js\";\nimport { ZeroShotCreatePromptArgs, ZeroShotAgent } from \"../../mrkl/index.js\";\nimport { AgentExecutor } from \"../../executor.js\";\n\n/**\n * Represents a toolkit for working with JSON data. It initializes the\n * JSON tools based on the provided JSON specification.\n * @example\n * ```typescript\n * const toolkit = new JsonToolkit(new JsonSpec());\n * const executor = createJsonAgent(model, toolkit);\n * const result = await executor.invoke({\n *   input: 'What are the required parameters in the request body to the /completions endpoint?'\n * });\n * ```\n */\nexport class JsonToolkit extends BaseToolkit {\n  tools: ToolInterface[];\n\n  constructor(public jsonSpec: JsonSpec) {\n    super();\n    this.tools = [\n      new JsonListKeysTool(jsonSpec),\n      new JsonGetValueTool(jsonSpec),\n    ];\n  }\n}\n\n/**\n * Creates a JSON agent using a language model, a JSON toolkit, and\n * optional prompt arguments. It creates a prompt for the agent using the\n * JSON tools and the provided prefix and suffix. It then creates a\n * ZeroShotAgent with the prompt and the JSON tools, and returns an\n * AgentExecutor for executing the agent with the tools.\n * @param llm The language model used to create the JSON agent.\n * @param toolkit The JSON toolkit used to create the JSON agent.\n * @param args Optional prompt arguments used to create the JSON agent.\n * @returns An AgentExecutor for executing the created JSON agent with the tools.\n */\nexport function createJsonAgent(\n  llm: BaseLanguageModelInterface,\n  toolkit: JsonToolkit,\n  args?: ZeroShotCreatePromptArgs\n) {\n  const {\n    prefix = JSON_PREFIX,\n    suffix = JSON_SUFFIX,\n    inputVariables = [\"input\", \"agent_scratchpad\"],\n  } = args ?? {};\n  const { tools } = toolkit;\n  const prompt = ZeroShotAgent.createPrompt(tools, {\n    prefix,\n    suffix,\n    inputVariables,\n  });\n  const chain = new LLMChain({ prompt, llm });\n  const agent = new ZeroShotAgent({\n    llmChain: chain,\n    allowedTools: tools.map((t) => t.name),\n  });\n  return AgentExecutor.fromAgentAndTools({\n    agent,\n    tools,\n    returnIntermediateSteps: true,\n  });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwBA,IAAa,cAAb,cAAiCA,sBAAAA,YAAY;CAC3C;CAEA,YAAY,UAA2B;AACrC,SAAO;AADU,OAAA,WAAA;AAEjB,OAAK,QAAQ,CACX,IAAIC,aAAAA,iBAAiB,SAAS,EAC9B,IAAIC,aAAAA,iBAAiB,SAAS,CAC/B;;;;;;;;;;;;;;AAeL,SAAgB,gBACd,KACA,SACA,MACA;CACA,MAAM,EACJ,SAASC,eAAAA,aACT,SAASC,eAAAA,aACT,iBAAiB,CAAC,SAAS,mBAAmB,KAC5C,QAAQ,EAAE;CACd,MAAM,EAAE,UAAU;CAOlB,MAAM,QAAQ,IAAIC,cAAAA,cAAc;EAC9B,UAFY,IAAIC,kBAAAA,SAAS;GAAE,QALdD,cAAAA,cAAc,aAAa,OAAO;IAC/C;IACA;IACA;IACD,CAAC;GACmC;GAAK,CAAC;EAGzC,cAAc,MAAM,KAAK,MAAM,EAAE,KAAK;EACvC,CAAC;AACF,QAAOE,iBAAAA,cAAc,kBAAkB;EACrC;EACA;EACA,yBAAyB;EAC1B,CAAC"}