{"version":3,"file":"agent/prompts/validator.mjs","sources":["webpack://@agent-infra/browser-use/./src/agent/prompts/validator.ts"],"sourcesContent":["/**\n * The following code is modified based on\n * https://github.com/nanobrowser/nanobrowser/blob/master/chrome-extension/src/background/agent/prompts/validator.ts\n *\n * Apache-2.0 License\n * Copyright (c) 2024 alexchenzl\n * https://github.com/nanobrowser/nanobrowser/blob/master/LICENSE\n */\nimport { BasePrompt } from './base';\nimport { type HumanMessage, SystemMessage } from '@langchain/core/messages';\nimport type { AgentContext } from '../types';\n\nexport class ValidatorPrompt extends BasePrompt {\n  private tasks: string[] = [];\n\n  constructor(task: string) {\n    super();\n    this.tasks.push(task);\n  }\n\n  private tasksToValidate(): string {\n    if (this.tasks.length === 1) {\n      return this.tasks[0];\n    }\n\n    const lastTask = this.tasks[this.tasks.length - 1];\n    const previousTasks = this.tasks\n      .slice(0, -1)\n      .map((task, index) => `${index + 1}. ${task}`)\n      .join('\\n');\n    const tasksString = `\n${lastTask}\n\nThe above task is a follow up task of the following tasks, please take the previous context into account when validating the task.\n\nPrevious tasks:\n${previousTasks}\n`;\n    return tasksString;\n  }\n\n  getSystemMessage(): SystemMessage {\n    return new SystemMessage(`You are a validator of an agent who interacts with a browser.\nYOUR ROLE:\n1. Validate if the agent's last action matches the user's request and if the task is completed.\n2. Determine if the task is fully completed\n3. Answer the task based on the provided context if the task is completed\n\nRULES of ANSWERING THE TASK:\n  - Read the task description carefully, neither miss any detailed requirements nor make up any requirements\n  - Compile the final answer from provided context, do NOT make up any information not provided in the context\n  - Make answers concise and easy to read\n  - Include relevant numerical data when available, but do NOT make up any numbers\n  - Include exact urls when available, but do NOT make up any urls\n  - Format the final answer in a user-friendly way\n\nSPECIAL CASES:\n1. If the task is unclear defined, you can let it pass. But if something is missing or the image does not show what was requested, do NOT let it pass\n2. Try to understand the page and help the model with suggestions like scroll, do x, ... to get the solution right\n3. If the webpage is asking for username or password, you should respond with:\n  - is_valid: true\n  - reason: describe the reason why it is valid although the task is not completed yet\n  - answer: ask the user to sign in by themselves\n4. If the output is correct and the task is completed, you should respond with\n  - is_valid: true\n  - reason: \"Task completed\"\n  - answer: The final answer to the task\n\nRESPONSE FORMAT: You must ALWAYS respond with valid JSON in this exact format:\n{\n  \"is_valid\": boolean,  // true if task is completed correctly\n  \"reason\": string      // clear explanation of validation result\n  \"answer\": string      // empty string if is_valid is false; human-readable final answer and should not be empty if is_valid is true\n}\n\nANSWER FORMATTING GUIDELINES:\n- Start with an emoji \"✅\" if is_valid is true\n- Use markdown formatting if required by the task description\n- By default use plain text\n- Use bullet points for multiple items if needed\n- Use line breaks for better readability\n- Use indentations for nested lists\n\n<example_output>\n{\n  \"is_valid\": false,\n  \"reason\": \"The user wanted to search for \\\\\"cat photos\\\\\", but the agent searched for \\\\\"dog photos\\\\\" instead.\",\n  \"answer\": \"\"\n}\n</example_output>\n\n<example_output>\n{\n  \"is_valid\": true,\n  \"reason\": \"The task is completed\",\n  \"answer\": \"✅ Successfully followed @nanobrowser_ai on X.\"\n}\n</example_output>\n\nTASK TO VALIDATE:\n${this.tasksToValidate()}`);\n  }\n\n  /**\n   * Get the user message for the validator prompt\n   * @param context - The agent context\n   * @returns The user message\n   */\n  async getUserMessage(context: AgentContext): Promise<HumanMessage> {\n    return await this.buildBrowserStateUserMessage(context);\n  }\n\n  addFollowUpTask(task: string): void {\n    this.tasks.push(task);\n  }\n}\n"],"names":["ValidatorPrompt","BasePrompt","lastTask","previousTasks","task","index","tasksString","SystemMessage","context"],"mappings":";;;;;;AAOC;;;;;;;;;;AAKM,MAAMA,wBAAwBC;IAQ3B,kBAA0B;QAChC,IAAI,AAAsB,MAAtB,IAAI,CAAC,KAAK,CAAC,MAAM,EACnB,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE;QAGtB,MAAMC,WAAW,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,EAAE;QAClD,MAAMC,gBAAgB,IAAI,CAAC,KAAK,CAC7B,KAAK,CAAC,GAAG,IACT,GAAG,CAAC,CAACC,MAAMC,QAAU,GAAGA,QAAQ,EAAE,EAAE,EAAED,MAAM,EAC5C,IAAI,CAAC;QACR,MAAME,cAAc,CAAC;AACzB,EAAEJ,SAAS;;;;;AAKX,EAAEC,cAAc;AAChB,CAAC;QACG,OAAOG;IACT;IAEA,mBAAkC;QAChC,OAAO,IAAIC,cAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0D9B,EAAE,IAAI,CAAC,eAAe,IAAI;IACxB;IAOA,MAAM,eAAeC,OAAqB,EAAyB;QACjE,OAAO,MAAM,IAAI,CAAC,4BAA4B,CAACA;IACjD;IAEA,gBAAgBJ,IAAY,EAAQ;QAClC,IAAI,CAAC,KAAK,CAAC,IAAI,CAACA;IAClB;IAnGA,YAAYA,IAAY,CAAE;QACxB,KAAK,IAHP,uBAAQ,SAAkB,EAAE;QAI1B,IAAI,CAAC,KAAK,CAAC,IAAI,CAACA;IAClB;AAiGF"}