HARPA.AI
LIBRARYAPIGUIDESAI COMMANDSBLOG

๐Ÿง ย ย WebReasoning: Smarter AI Answers

This command improves your AI's question-answering abilities by combining web search results with a reasoning process similar to OpenAI's o3-mini. It finds relevant online information, uses it to create a knowledge base, and then applies step-by-step reasoning to understand the question and provide a thorough answer. The web data is included in the final response. WebQ&A allows your AI to give well-informed, logical answers to complex questions using web research and reasoning

Created by Morteza
Updated on Feb 14, 08:54
Installed 27 times
RUNS JS CODE

How to Use

IMPORT COMMAND

Content

- type: say
  message: >-
    **Tip:** This command performs a thorough in-depth reasoning through
    multiple tasks for a given prompt or topic and is best used for
    low-budget/peformance AI Connections. It takes time.
  label: TIP ABOUT COMMAND
- type: ask
  param: toggle
  message: |-
    **Toggle off**

    Do you want to disable any of the options?
    Number of estimated tokens:
    - Deep Research: ~20k
    - Reasoning each depth: ~500 tokens  (in the case of a short input text)
  options:
    - label: ๐ŸŒ DEEP RESEARCH
      value: research
    - label: ๐Ÿ’ฌ REASONING
      value: reasoning
    - label: โŒ NONE
      value: none
  default: ''
  vision:
    enabled: false
    mode: area
    hint: ''
    send: true
  optionsInvalid: false
  label: TOGGLE OFF
- type: ask
  param: question
  message: >-
    Please enter your specific search query now. This query will be used as the
    basis for the AI-generated response. The more precisely you phrase your
    question or request, the better the AI can address it. What would you like
    to know?
  label: MAIN QUESTION
- type: group
  steps:
    - type: ask
      param: userQuery
      message: >-
        ![icon](/img/commands/general-search-refraction.svg) Provide a search
        query that will be used to retrieve Google search results:
      options: null
      default: ''
      vision:
        enabled: false
        mode: area
        hint: ''
        send: true
      condition: '{{toggle}} != research'
      label: SET USER QUERY FOR GOOGLE SEARCH
    - type: gpt
      prompt: >-
        You are a Research Agent. I need you to break down my search query into
        6 clarifying queries divided by the OR search operator and only in one
        line 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 by focusing on
        different aspects or using alternative wordings.

        - Each sub-query should include keywords from [my search query]. For
        example, if asking about a product, include its name, brand, or key
        features in all sub-queries to find relevant info.

        - If the query contains "best" or year specifications like "2025",
        maintain these keywords at the start of each sub-query.

        - Use the Google search operator "OR" to refine the sub-queries and get
        the best search results by including synonyms or related terms.

        - Configure your search operators to maximize relevant results.

        - Ensure diversity in results by varying sources and approaches.

        - Sub-queries should be brief but comprehensive.

        - Output a single optimized query only and DO NOT include quotation
        marks in the query.

        - Only response with the optimized query without further explanations or
        text!


        **[EXAMPLE OUTPUT]:**

        best cordless vacuum brand XY under $500 bagless handheld 2023 OR best
        wireless vacuum brand XY below $500 bagless handheld 2024 OR best
        battery vacuum brand XY under $500 bagless handheld 2023 OR best
        handheld vacuum XY under $500 bagless 2023 OR best portable vacuum XY
        under $500 bagless 2024 OR best bagless vacuum brand XY under $500
        handheld 2023
      label: CREATE AN EFFICIENT QUERY FOR GOOGLE
      silent: true
      param: query
      isolated: true
      condition: '{{toggle}} != research'
    - type: say
      message: |-
        ๐ŸŒ Query created and will be used for google search:
        ```
        {{query}}
        ``` 
      condition: '{{toggle}} != research'
      label: DISPLAY CONFIRM MESSAGE FOR QUERY CREATED
    - type: calc
      func: set
      param: internet_information
      format: ''
      value: '{{serp {{query}} crawl=all}}'
      label: SET INTERNET RESULT
      condition: '{{toggle}} != research'
    - type: js
      args: internet_information
      code: |-
        function countMarkdownLinks(args) {
          const text = args.internet_information;
          
          if (!text) return 0;
          
          // Regex Pattern fรผr Links mit โžŠ, โž‹, โžŒ etc.
          const linkPattern = /\[(โžŠ|โž‹|โžŒ|โž|โžŽ|โž|โž|โž‘|โž’|โž“)\]\([^)]+\)/g;
          
          // Matches finden und zรคhlen
          const matches = text.match(linkPattern) || [];
          
          // Just give the number back
          return matches.length;
        }

        return countMarkdownLinks(args);
      param: countSources
      timeout: 15000
      onFailure: DISPLAY SOURCES
      silent: true
      label: COUNT SOURCES
      condition: '{{toggle}} != research'
    - type: js
      args: internet_information
      code: |-
        const content = args['internet_information']; 
        return { 
         chars: internet_information.length, 
         estimatedTokens: Math.ceil(internet_information.length / 4), 
         estimatedWords: Math.ceil(internet_information.length / 4 * 0.75) 
        };
      param: count
      timeout: 15000
      onFailure: REGEX TO FIND SOURCES
      silent: true
      label: PAGE RESEARCH CONTENT TOKEN COUNT
    - type: say
      message: >-
        ![icon](/img/commands/general-download-cloud-01.svg) Successfully parsed
        the content from **{{countSources}}** web pages.

        - Chars: {{count.chars}}

        - Estimated Tokens: {{count.estimatedTokens}}

        - Estimated Words: {{count.estimatedWords}}
      label: DISPLAY CONFIRM MESSAGE FOR PARSED WEB PAGE CONTENT
      condition: '{{toggle}} != research'
    - type: js
      args: internet_information
      code: |-
        function formatMarkdownLinks(args) {
          const text = args.internet_information;
          
          if (!text) return "";
          
          // Regex pattern for links with โžŠ, โž‹, โžŒ etc.
          const linkPattern = /\[(โžŠ|โž‹|โžŒ|โž|โžŽ|โž|โž|โž‘|โž’|โž“)\]\([^)]+\)/g;
          
          // Collect all matches
          const matches = [];
          text.replace(linkPattern, (match) => {
            const url = match.match(/\((.*?)\)/)[1];
            // Extract domain and path
            const urlObj = new URL(url);
            // Combine domain and path
            const fullPath = urlObj.hostname.replace('www.', '') + urlObj.pathname;
            // If path is longer than 42 chars (45 - 3 for '...'), truncate it
            const shortPath = fullPath.length > 42 
              ? fullPath.slice(0, 42) + '...'
              : fullPath.replace(/\/$/, ''); // Remove trailing slash
            matches.push(`${match} [${shortPath}](${url})`);
          });
          
          // Return formatted output
          return matches.join('\n');
        }

        return formatMarkdownLinks(args);
      param: sources
      timeout: 15000
      onFailure: TOGGLE OFF
      silent: true
      label: REGEX TO FIND SOURCES
      condition: '{{toggle}} != research'
  label: DEEP RESEARCH STEPS
  condition: '{{toggle}} != research'
- type: group
  steps:
    - type: ask
      param: depth
      message: >-
        **Set the reasoning tasks depth.**


        The depth of reasoning specifies how many reasoning tasks are to be
        created and analysed. Each depth level creates an even more detailed
        breakdown of your question and improves the final result. If you want
        more than 5 tasks, just enter the number, but then it will use more
        tokens.
      label: CHOOSE DEPTH
      optionsInvalid: false
      options:
        - label: 1 REASONING-TASKS
          value: 1
        - label: 2 REASONING-TASKS
          value: 2
        - label: 3 REASONING-TASKS
          value: 3
        - label: 4 REASONING-TASKS
          value: 4
        - label: 5 REASONING-TASKS
          value: 5
        - $custom
      condition: '{{toggle}} != reasoning'
    - type: gpt
      prompt: >-
        [QUESTION]:

        {{question}}

        [LANGUAGE]: {{language}}


        As an AI assistant, your task is to break down the main question
        provided in [QUESTION] into a JSON array of specific reasoning tasks.
        These tasks will be completed individually to gather information
        necessary to answer the main question.


        AI reasoning simulates a thought process by using hidden "reasoning
        tokens."  These tokens are internal to the model and represent its
        intermediate steps in understanding and responding to a prompt. Unlike
        input and output tokens, which are part of the visible conversation,
        reasoning tokens are ephemeral and discarded after each turn. This
        process allows the AI to explore multiple approaches, break down complex
        ideas, and formulate a coherent response.  However, the model's memory
        of past conversations (input and output) is limited by a "context
        window."  When the accumulated conversation history exceeds this window,
        older information is truncated, much like how human memory can fade over
        time.  This continuous cycle of input, reasoning, output, and memory
        management allows the AI to engage in multi-turn conversations while
        maintaining context within its limited capacity.


        Generate a JSON array where each element is an object representing a
        reasoning task. Each task object should have a "task_id" key with a
        unique integer value and a "task_description" key with a string value
        describing the task.


        The task descriptions should focus on gathering specific pieces of
        information or performing reasoning steps that will contribute to
        answering the main question. Each task should represent a discrete step
        in the information gathering and reasoning process.


        Guidelines:

        - Ensure each task description is specific, actionable, and focused on
        gathering useful information about the [QUESTION]

        - Break down the [QUESTION] into sub-tasks that target different aspects
        or components needed to formulate a complete answer

        - Maintain a logical flow between tasks, with each task building upon
        the information gathered in previous steps

        - Cover all essential aspects of the main question, but avoid generating
        tasks for providing a summary or final answer

        - Create only {{depth}} task elements in the JSON array, no more and
        nothing less.

        - Avoid reasoning tasks requiring internet access or external knowledge.
        Reasoning must rely solely on internal data.


        Provide your output as a JSON array. Example:


        [
          {"task_id": 1, "task_description": "Identify the main categories in which major news typically occurs (e.g., politics, business, technology, science, culture, sports)."},
          {"task_id": 2, "task_description": "For each of the identified categories, determine the types of events that could be considered 'important' (e.g., elections, legislative changes, economic developments, technological breakthroughs, scientific discoveries, significant cultural or sporting events)."},
          {"task_id": 3, "task_description": "Determine the relevant sources that would most likely report on major events of 2025 *if* the model had access to them (e.g., major news agencies, professional journals, government publications) โ€“ purely hypothetically, without actual access."}
        ]


        Respond in the language specified in [LANGUAGE].
      label: GENERATE REASONING TASK LIST
      param: reasoning_tasks
      isolated: true
      silent: true
      condition: '{{toggle}} != reasoning'
    - type: calc
      func: extract-json
      to: reasoning_tasks
      param: reasoning_tasks
      index: ''
      label: EXTRACT JSON
      condition: '{{toggle}} != reasoning'
    - type: loop
      list: reasoning_tasks
      steps:
        - type: gpt
          prompt: >-
            [QUESTION]:

            {{question}}

            [ITEM]: "{{reasoning_tasks.{{index}}.task_description}}"

            [LANGUAGE]: {{language}}


            As an AI assistant, you are focusing on a single reasoning task
            specified by the [ITEM] object.


            Your goal is to provide information that addresses the specific task
            described in [ITEM]. Provide as much relevant and useful information
            as you think is necessary to contribute to answering the main
            question.


            Output format:

            {
              "info": "Provide textual information that addresses the specific task and helps answer the main question. Write as much as you think is necessary, focusing on useful information for further processing."
            }


            Guidelines:

            - Be thorough and detailed in your information gathering for this
            specific task

            - Focus on facts, analysis, and insights that are directly relevant
            to the task

            - Draw upon your knowledge and any relevant information from
            previous reasoning steps

            - Provide information in a clear, structured manner that will be
            easy to integrate into a final answer


            Respond in the language specified in [LANGUAGE].
          param: data
          label: PERFORM INDIVIDUAL REASONING TASK
          isolated: true
          silent: true
        - type: calc
          func: extract-json
          to: data
          param: data
          index: first
          label: EXTRACT JSON FROM TEXT
        - type: calc
          func: set
          param: data.task_id
          format: ''
          value: '{{item.task_id}}'
          label: SET TASK ID
        - type: calc
          func: set
          param: data.task_description
          format: ''
          value: '{{item.task_description}}'
          label: SET TASK DESC
        - type: calc
          func: list-add
          index: last
          list: reasoning_history
          item: data
          label: ADD TO ITEM LIST
        - type: calc
          func: set
          param: percentage_index
          format: ''
          value: '{{index}}'
          label: SET PRECENTAGE INDEX
        - type: calc
          func: increment
          param: percentage_index
          delta: 1
          label: ADD 1 TO PERCENTAGE INDEX
        - type: calc
          func: set
          param: total
          format: ''
          value: '{{reasoning_tasks.length}}'
          label: SET TOTAL
        - type: js
          args: percentage_index, total
          code: |-
            function calculatePercentage(percentage_index, total) {
                index = Number(percentage_index);
                total = Number(total);

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

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

            let result = calculatePercentage(percentage_index, total);
            return result;
          param: percentage
          timeout: 6000
          onFailure: PROCESSING...
          label: PERCENTAGE INDEX TOTAL
          silent: true
        - type: say
          message: >-
            ๐Ÿง  Reasoning **{{percentage}}**

            Analysis to `{{reasoning_tasks.{{index}}.task_description}}`
            completed!
          label: PROCESSING...
      label: REASONING
      condition: '{{toggle}} != reasoning'
  label: REASONING PREPERATION STEPS
  condition: '{{toggle}} != reasoning'
- type: group
  steps:
    - type: calc
      func: set
      param: internet_guidelines
      format: ''
      value: >-
        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 and be more specific and detailed.

        - Avoid spaces between paragraphs and keep it compact!
      label: SET INSTRUCTIONS FOR INTERNET INFORMATION
      condition: '{{toggle}} != research'
    - type: calc
      func: set
      param: reasoning_guidelines
      format: ''
      value: >-
        - Carefully review the information provided in each output object within
        [REASONING_HISTORY]

        - Identify the key facts, analyses, and insights that directly address
        the main question

        - Integrate this relevant information into a natural, well-structured
        response

        - Ensure your answer flows logically and covers all important aspects of
        the question

        - Provide clear explanations and supporting evidence from the gathered
        information

        - Craft a polished final answer that demonstrates a deep understanding
        of the question and provides valuable, comprehensive information
      label: SET INSTRUCTIONS FOR REASONING HISTORY
      condition: '{{toggle}} != reasoning'
    - type: calc
      func: set
      param: internet_label
      format: ''
      value: |-
        [INTERNET_INFORMATION]:
        {{internet_information}}

        IMPORTANT: Do NOT forget the source citation!
      label: SET LABEL FOR INTERNET INFORMATION
      condition: '{{toggle}} != research'
    - type: calc
      func: set
      param: reasoning_label
      format: ''
      value: |-
        [REASONING_HISTORY]:
        {{reasoning_history}}
      label: SET LABEL FOR REASONING HISTORY
      condition: '{{toggle}} != reasoning'
    - type: gpt
      prompt: >-
        [QUESTION]:

        {{question}}

        [LANGUAGE]: {{language}}


        As an AI assistant, your task is to provide a final comprehensive answer
        to the question given in [QUESTION]. You have completed a series of
        information gathering and reasoning tasks, with the outputs stored in
        [REASONING_HISTORY].


        Synthesize the information and insights from all the reasoning steps to
        construct a detailed, cohesive response that fully addresses the
        original question.


        Follow the following instructions:

        {{reasoning_guidelines}}

        {{internet_guidelines}}


        [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 or even better
        subbullet 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.


        Respond in the language specified in [LANGUAGE]. Your final answer
        should be a culmination of the information gathering and reasoning
        process, presenting a clear, insightful, and complete response to the
        original question.


        {{reasoning_label}}


        {{internet_label}}
      label: PROVIDE FINAL ANSWER
      param: ''
      isolated: true
      dumb: false
      silent: false
    - type: say
      message: |-
        ![icon](/img/commands/maps-globe-06.svg) Sources

        {{sources}}
      label: DISPLAY SOURCES
      condition: '{{toggle}} != research'
  label: SET LABEL AND INSTRUCTIONS | FINAL GPT
- type: jump
  to: TOGGLE OFF
Notice: Please read before using

This automation command is created by a community member. HARPA AI team does not audit community commands.

Please review the command carefully and only install if you trust the creator.

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