HARPA.AI
LIBRARYUSE CASESGUIDESAI COMMANDSBLOG

๐Ÿค–ย ย Deep Research Bot

Performs an in-depth online research to answer user queries. Split questions into sub-queries for deeper scans.

Created by HARPA AI
Updated on Nov 11, 08:24
Installed 185 times
RUNS JS CODE

How to Use

IMPORT COMMAND

Content

- type: say
  message: >-
    **Tip:** This command performs a thorough in-depth online search for a given
    query or topic and is best used for research. It takes time and is token
    hungry (~20k tokens on GPT-4o-mini per search depth).
- param: userQuery
  message: '![icon](/img/commands/general-search-refraction.svg) Type your search query:'
  type: ask
  options: null
  default: ''
- param: depth
  message: >-
    **Set the search depth.**


    Search depth indicates how many search pages will be analyzed. Each depth
    level generates an extra sub-query, improving search quality.
  options:
    - label: ๐Ÿ” SEARCH
      value: 1
    - label: 2 SUB-QUERIES
      value: 2
    - label: 3 SUB-QUERIES
      value: 3
    - label: 4 SUB-QUERIES
      value: 4
  type: ask
  default: ''
  optionsInvalid: false
- steps:
    - prompt: >-
        You are a Research Agent. I need you to break down my search query into
        {{depth}} clarifying queries in {{language}}, the answers to which are
        necessary to form a detailed response to my query: "{{userQuery}}"


        Follow the instructions:

        - The first sub-query should be as close as possible to My Query in
        wording. If my query is short and simple - repeat it in the first
        sub-query. 

        - Subsequent sub-queries should clarify the first one.

        - Each sub-query should include keywords from [my search query]. For
        example, if asking about a city, include it in all sub-queries to find
        relevant info.

        - Sub-queries should be brief. Imagine typing a brief Google query for a
        precise answer.

        - Do not repeat my command and instructions.

        - Response in JSON array with {{depth}} objects (queries). 

        - Write nothing other than the JSON.


        Example input: "What is the history of the steam engine, its industrial
        impact, and who invented the first practical version and when?"


        Example JSON response: 


        [
          {
            "query": "Steam engine history and industrial impact"
          },
          {
            "query": "First practical steam engine inventor and date"
          }
        ]



        JSON response:
      param: subqueries
      condition: '{{depth}} > 1'
      type: gpt
      silent: true
    - type: calc
      func: extract-json
      to: subqueries
      param: subqueries
      index: all
    - message: >-
        ๐Ÿงฉ To give a comprehensive response, your question was split into
        **{{subqueries.length}}** sub-queries.
      type: say
    - steps:
        - value: '{{item.query}}'
          type: calc
          func: set
          param: query
          format: text
        - message: 'โณ Scanning information for sub-query: "**{{query}}**".'
          type: say
        - param: information
          value: '{{serp {{query}}}}'
          type: calc
          func: set
          format: ''
        - func: serp.extract-links
          to: links
          type: calc
          from: information
        - param: total
          value: '{{links.length}}'
          type: calc
          func: set
          format: number
        - steps:
            - value: '{{page {{item.url}}}}'
              type: calc
              func: set
              param: content
              format: ''
            - param: pageUrl
              type: calc
              func: set
              format: text
              value: '{{item.url}}'
            - code: |-
                const regex = /^(?:https?:\/\/)?(?:www\.)?([^\/]+)/;
                const testString = pageUrl;
                const matches = testString.match(regex);

                if (matches) {
                  const hostname = matches[1];
                  return hostname; 
                }
              param: hostname
              type: js
              args: pageUrl
              timeout: 15000
              silent: true
            - type: calc
              func: increment
              param: index
              delta: 1
            - args: index, total
              code: |-
                function calculatePercentage(index, total) {
                    index = Number(index);
                    total = Number(total);

                    if (isNaN(index) || isNaN(total)) {
                        return "Error";
                    }

                    return (index / total * 100).toFixed(1) + "%";
                }

                let result = calculatePercentage(index, total);
                return result;
              param: percentage
              type: js
              timeout: 15000
              silent: true
            - steps:
                - prompt: >-
                    Act as a professional researcher. 


                    Analyze the given [web page content] and summarize useful
                    information to answer my query: "{{query}}"


                    Instructions:

                    - Imagine you are a Google Search engine, collecting
                    relevant information from various websites to form an answer
                    to my query in {{language}}.

                    - Gather only information that will be useful in answering
                    my question. 

                    - Extract as much useful information as possible, be concise
                    and don't write more than needed to answer the question.

                    - Avoid general phrases.

                    - When referring to someone's opinion about something,
                    mention the author. Quote if appropriate. 

                    - If you haven't found anything useful, don't make up
                    information or guess - simply say "No relevant information
                    found" in {{language}}.

                    - Do not echo my prompt in your response.

                    - Respond with a JSON object containing a single field:
                    "info".

                    - Write nothing other than the JSON.


                    Example JSON response:


                    {
                      "info": "Write here textual information that would help answer my query. Write as much as you think is necessary, focusing on providing useful information for further processing."
                    }



                    [Web page content]: {{content}}.



                    JSON response:
                  param: data
                  type: gpt
                  isolated: true
                  silent: true
                - index: first
                  type: calc
                  func: extract-json
                  to: data
                  param: data
                - param: data.url
                  type: calc
                  func: set
                  format: auto
                  value: '{{item.url}}'
                - param: data.title
                  type: calc
                  func: set
                  format: auto
                  value: '{{item.title}}'
                - list: array
                  type: calc
                  func: list-add
                  index: last
                  item: data
                - to: SAY STATUS
                  type: jump
              condition: '{{content}} ~= /(?s)^.{200,}$/gm'
              label: FETCHED
              type: group
            - steps:
                - type: navigate
                  url: '{{item.url}}'
                  waitForIdle: false
                  silent: false
                - type: wait
                  for: 0.5s
                  silent: true
                - prompt: >-
                    Act as a professional researcher. 


                    Analyze the given [web page content] and summarize useful
                    information to answer my query: "{{query}}"


                    Instructions:

                    - Imagine you are a Google Search engine, collecting
                    relevant information from various websites to form an answer
                    to my query in {{language}}.

                    - Gather only information that will be useful in answering
                    my question. 

                    - Extract as much useful information as possible from the
                    page content.

                    - Avoid general phrases.

                    - When referring to someone's opinion about something,
                    mention the author. Quote if appropriate. 

                    - If you haven't found anything useful, don't make up
                    information or guess - simply say "No relevant information
                    found" in {{language}}.

                    - Do not echo my prompt in your response.

                    - Respond with a JSON object containing a single field:
                    "info".

                    - Write nothing other than the JSON.


                    Example JSON response:


                    {
                      "info": "Write here textual information that would help answer my query. Write as much as you think is necessary, focusing on providing useful information for further processing."
                    }



                    [Web page content]: {{page {{query}} limit=30%}}.



                    JSON response:
                  type: gpt
                  isolated: true
                  param: data
                  silent: true
                - type: calc
                  func: extract-json
                  to: data
                  param: data
                  index: first
                - type: calc
                  func: set
                  param: data.url
                  format: auto
                  value: '{{item.url}}'
                - type: calc
                  func: set
                  param: data.title
                  format: auto
                  value: '{{item.title}}'
                - type: calc
                  func: list-add
                  index: last
                  list: array
                  item: data
              label: NOT FETCHED
              type: group
            - message: >-
                ๐Ÿ” Analyzed **{{index}} / {{total}}**, 
                [{{hostname}}]({{pageUrl}})
              label: โ›”๏ธSAY STATUS
              condition: '{{index}} = {{total1}}'
              type: say
            - message: ๐Ÿ” Analyzed **{{percentage}}**,  [{{hostname}}]({{pageUrl}})
              condition: '{{index}} != {{total}}'
              type: say
              label: SAY STATUS
            - message: |-
                โœ… **{{percentage}}** pages scanned for "**{{query}}**". 

                Last checked page: [{{hostname}}]({{pageUrl}})
              condition: '{{index}} = {{total}}'
              type: say
              label: SAY STATUS
          type: loop
          list: links
      type: loop
      list: subqueries
    - message: >-
        ๐Ÿค– Analyzed **{{array.length}}** pages from **{{subqueries.length}}**
        Google searches. 

        Now preparing a comprehensive answer to your question.
      type: say
  label: DEPTH > 1
  type: group
  condition: '{{depth}} > 1'
- steps:
    - message: โณ Give me a minute to search through the web for you...
      type: say
    - value: '{{userQuery}}'
      type: calc
      func: set
      param: query
      format: text
    - type: calc
      func: set
      param: information
      format: ''
      value: '{{serp {{query}}}}'
    - type: calc
      func: serp.extract-links
      from: information
      to: links
    - type: calc
      func: set
      param: total
      format: number
      value: '{{links.length}}'
    - steps:
        - label: TRYING TO FETCH
          type: calc
          func: set
          param: content
          format: ''
          value: '{{page {{item.url}}}}'
        - type: calc
          func: set
          param: pageUrl
          format: text
          value: '{{item.url}}'
        - type: js
          args: pageUrl
          code: |-
            const regex = /^(?:https?:\/\/)?(?:www\.)?([^\/]+)/;
            const testString = pageUrl;
            const matches = testString.match(regex);

            if (matches) {
              const hostname = matches[1];
              return hostname; 
            }
          param: hostname
          timeout: 15000
          silent: true
        - type: calc
          func: increment
          param: index
          delta: 1
        - type: js
          args: index, total
          code: |-
            function calculatePercentage(index, total) {
                index = Number(index);
                total = Number(total);

                if (isNaN(index) || isNaN(total)) {
                    return "Error";
                }

                return (index / total * 100).toFixed(1) + "%";
            }

            let result = calculatePercentage(index, total);
            return result;
          param: percentage
          timeout: 15000
          silent: true
        - steps:
            - type: gpt
              prompt: >-
                Act as a professional researcher. 


                Analyze the given [web page content] and summarize useful
                information to answer my query: "{{query}}"


                Instructions:

                - Imagine you are a Google Search engine, collecting relevant
                information from various websites to form an answer to my query
                in {{language}}.

                - Gather only information that will be useful in answering my
                question. 

                - Extract as much useful information as possible, be concise and
                don't write more than needed to answer the question.

                - Avoid general phrases.

                - When referring to someone's opinion about something, mention
                the author. Quote if appropriate. 

                - If you haven't found anything useful, don't make up
                information or guess - simply say "No relevant information
                found" in {{language}}.

                - Do not echo my prompt in your response.

                - Respond with a JSON object containing a single field: "info".

                - Write nothing other than the JSON.


                Example JSON response:


                {
                  "info": "Write here textual information that would help answer my query. Write as much as you think is necessary, focusing on providing useful information for further processing."
                }



                [Web page content]: {{content}}.



                JSON response:
              isolated: true
              param: data
              silent: true
            - type: calc
              func: extract-json
              to: data
              param: data
              index: first
            - type: calc
              func: set
              param: data.url
              format: auto
              value: '{{item.url}}'
            - type: calc
              func: set
              param: data.title
              format: auto
              value: '{{item.title}}'
            - type: calc
              func: list-add
              index: last
              list: array
              item: data
            - type: jump
              to: SAY STATUS
          type: group
          condition: '{{content}} ~= /(?s)^.{200,}$/gm'
          label: FETCHED
        - steps:
            - type: navigate
              url: '{{item.url}}'
              waitForIdle: false
              silent: false
            - type: wait
              for: 0.5s
              silent: true
            - type: gpt
              prompt: >-
                Act as a professional researcher. 


                Analyze the given [web page content] and summarize useful
                information to answer my query: "{{query}}"


                Instructions:

                - Imagine you are a Google Search engine, collecting relevant
                information from various websites to form an answer to my query
                in {{language}}.

                - Gather only information that will be useful in answering my
                question. 

                - Extract as much useful information as possible from the page
                content.

                - Avoid general phrases.

                - When referring to someone's opinion about something, mention
                the author. Quote if appropriate. 

                - If you haven't found anything useful, don't make up
                information or guess - simply say "No relevant information
                found" in {{language}}.

                - Do not echo my prompt in your response.

                - Respond with a JSON object containing a single field: "info".

                - Write nothing other than the JSON.


                Example JSON response:


                {
                  "info": "Write here textual information that would help answer my query. Write as much as you think is necessary, focusing on providing useful information for further processing."
                }



                [Web page content]: {{page {{query}} limit=30%}}.



                JSON response:
              isolated: true
              param: data
              silent: true
            - type: calc
              func: extract-json
              to: data
              param: data
              index: first
            - type: calc
              func: set
              param: data.url
              format: auto
              value: '{{item.url}}'
            - type: calc
              func: set
              param: data.title
              format: auto
              value: '{{item.title}}'
            - type: calc
              func: list-add
              index: last
              list: array
              item: data
          type: group
          label: NOT FETCHED
        - type: say
          message: ๐Ÿ” Analyzed **{{index}} / {{total}}**,  [{{hostname}}]({{pageUrl}})
          label: โ›”๏ธSAY STATUS
          condition: '{{index}} = {{total1}}'
        - type: say
          message: ๐Ÿ” Analyzed **{{percentage}}**,  [{{hostname}}]({{pageUrl}})
          label: SAY STATUS
          condition: '{{index}} != {{total}}'
        - type: say
          message: |-
            โœ… **{{percentage}}** pages scanned for "**{{query}}**". 

            Last checked page: [{{hostname}}]({{pageUrl}})
          label: SAY STATUS
          condition: '{{index}} = {{total}}'
      type: loop
      list: links
  condition: '{{depth}} = 1'
  label: DEPTH = 1
  type: group
- prompt: >-
    Please ignore all previous instructions. I want you to only respond in
    {{language}}.


    You are a Research AI Agent.  


    I would like you create a comprehensive answer to [MY QUESTION], adhering to
    a specific format I provide:

    - Utilize [Information from the Web], provided below.

    - Extract as much useful information as possible from the web search results

    - Integrate insights from multiple web search sources, and ensure inclusion
    of relevant links in a markdown fully rendered format: [โžŠ](URL), [โž‹](URL)
    etc, to each bullet point.

    - Every URL should correspond to only one symbol: โžŠ โž‹ โžŒ โž โžŽ โž โž โž‘ โž’ โž“.

    - If multiple sources repeat the same information, describe it and cite all
    sources at once. 

    - If you know the answer, add your own knowledge to make it more complete.

    - Do not hallucinate facts or information.

    - Do not use any other tools.

    - Avoid general phrases.


    Follow the [RESPONSE FORMAT]:


    ## Key takeaway:

    Provide a single, most important takeaway from the web search results in
    {{language}}.


    ## Detailed answer:

    Analyze and present detailed information that helps answer my question.
    There should be no limit in words or bullet points to the report. Ensure
    that all ideas, facts, and relevant information are concisely reported, and
    the answer is comprehensive. Incorporate the maximum number of source links
    within the text.



    [MY QUESTION]: {{userQuery}}



    [Information from the Web]:

    {{array}}



    [COMPREHENSIVE RESPONSE WITH SOURCE LINKS ([โžŠ](URL))]:
  type: gpt
  isolated: true
  param: gpt
Contact us
HomeUse CasesGuidesPrivacy PolicyTerms of Service
CAN WE STORE COOKIES?
Our website uses cookies for the purposes of accessibility and security. They also allow us to gather statistics in order to improve the website for you. More info: Privacy Policy