# expand_answer

Adopt this skill: https://proskills.md/skills/other/leefc01-gemma-skill-universal-search-universal-expand-answer

Page: https://proskills.md/skills/other/leefc01-gemma-skill-universal-search-universal-expand-answer
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: universal-expand-answer/SKILL.md
size: 556
sha: dbce8c1c3bc8196c8631f130e6edf882b24cef85
upstream: https://github.com/leefc01/gemma_skill_universal_search/blob/main/universal-expand-answer/SKILL.md

```text
---
name: expand_answer
description: Expands text into a detailed explanation.
---

# Expand Answer

## Instructions

1. Rewrite the input as a direct answer.
2. Present the information as established facts.
3. Treat the input as raw knowledge, not search results.
4. Do NOT mention sources, searches, or results.
5. Do NOT describe the process of finding the information.

## Style

- Start immediately with the subject.
- Use a confident, encyclopedic tone.
- Write 2–3 paragraphs with concrete details.
- Include bullets with details of facts and data
```

## File: universal-expand-answer/scripts/index.html
size: 791
sha: 4172a2f4737a61bc4ebc6b1b77fe27e35e709ce7
upstream: https://github.com/leefc01/gemma_skill_universal_search/blob/main/universal-expand-answer/scripts/index.html

```text
<script>
  window["ai_edge_gallery_get_result"] = async (data) => {
    try {
      let text = "";

      // ✅ handle both string and object
      if (typeof data === "string") {
        try {
          const parsed = JSON.parse(data);
          text = parsed.result || parsed.text || data;
        } catch {
          text = data;
        }
      } else if (data && typeof data === "object") {
        text = data.result || data.text || "";
      }

      text = (text || "").trim();

      if (!text) {
        return JSON.stringify({ result: "No input provided." });
      }

      // 🔥 pass-through (let model expand)
      return JSON.stringify({
        result: text
      });

    } catch (e) {
      return JSON.stringify({ result: "Error: " + e.message });
    }
  };
</script>
```

## File: README.md
upstream: https://github.com/leefc01/gemma_skill_universal_search/blob/main/README.md

````text
# Universal Search and Expand Bundle

## Overview

Universal Search and Expand is a Gemma Edge Gallery skill bundle that retrieves fresh information from external APIs and turns it into a readable, grounded answer.

The bundle is designed to work well on phones and other resource-constrained devices. It keeps retrieval and expansion separate so the model can first gather context and then rewrite that context into a clearer response.

Use `search_and_expand` as the main entry point. It is the recommended skill for most users because it chains the retrieval and expansion steps for you.

## What the bundle does

The bundle is built around three skills:

1. `search_and_expand`
2. `universal_search`
3. `expand_answer`

Recommended flow:

- `search_and_expand` calls `universal_search`
- `universal_search` calls one or more search APIs and returns dense plain text
- `expand_answer` rewrites that text into a fuller answer

This design is useful when the model alone produces short, generic answers. By separating search from expansion, the bundle gives the model a better starting point for a grounded response.

## Why not just 1 skill?  A walk down the development process 

I orignallly tried just 1 skill.  I separted the concerns into various files.  So much more robust in structure, but not in function.  Slimmed down to the flattest possible format.  Then the problem was Gemma completely ignored the skill instructions.  You can try it yourself and send searches to `universal_search` if you are a glutton for narrated meta summaries.

Next, I tried `expand_answer` to elaborate further.  This worked with a few tweaks, but the narrated voice persisted.  Gemma has a way of inferring intent despite what your explicit instructions may be.

Finally, a 3rd level orchestrator.  This got to the best answers to date.  The drawback is potential accumulated latency along with a much more laborious deployment process.

I'd like to make this more elegant.  Still, a good learning process.

## Skills in this repository

### 1. `search_and_expand`

This is the recommended skill to use.

It orchestrates the workflow and is the user-facing entry point. In normal use, the user only needs to ask one question, and this skill handles the rest.

### 2. `universal_search`

This skill performs the search step.

It supports multiple providers and returns the result as a single dense text block. That output is intentionally simple so the model can use it safely on-device.

### 3. `expand_answer`

This skill performs the rewrite step.

It turns the dense search text into a more readable response, usually with more detail and better flow than the raw search output.

## Architecture overview

```mermaid
graph TD
  U[User Query] --> S[search_and_expand]
  S --> US[universal_search]
  US --> R[Provider Router]

  R --> WF[Wolfram Alpha]
  R --> SP[Serper]
  R --> TV[Tavily]
  R --> BR[Brave]
  R --> GM[Gemini]

  WF --> M[Merge and Clean]
  SP --> M
  TV --> M
  BR --> M
  GM --> M

  M --> EA[expand_answer]
  EA --> O[Final Answer]
```

## Execution flow

1. The user asks a question.
2. `search_and_expand` is triggered.
3. `search_and_expand` calls `universal_search`.
4. `universal_search` selects a provider or tries providers in order.
5. The provider returns search or knowledge text.
6. The text is cleaned and merged into a dense plain-text block.
7. `expand_answer` rewrites that block into a fuller answer.
8. The final answer is returned.

## Deployment structure

The repository is organized as three skill directories.

```text
skills/
└── universal_search_bundle/
    ├── search_and_expand/
    │   └── SKILL.md
    ├── universal_search/
    │   ├── SKILL.md
    │   └── scripts/
    │       └── index.html
    └── expand_answer/
        ├── SKILL.md
        └── scripts/
            └── index.html
```

## Prerequisites

### Required

- Google AI Edge Gallery
- A Gemma model installed in the app
- At least one supported API key for search or knowledge retrieval

### Recommended

- A Serper API key
- One backup provider key, such as Tavily or Brave
- A Wolfram Alpha API key for math, computation, and factual lookups

## Installation on phone

### Android phone

1. Install Google AI Edge Gallery on your Android device.
2. Open the app and load the Gemma model you want to use.
3. Add the skills from this repository.
4. Make sure the bundle is installed with the skills in this order:
   - `search_and_expand`
   - `universal_search`
   - `expand_answer`
5. Configure API keys in `universal_search/scripts/index.html`.
6. Save the files and refresh or reload the skills in the app.

### Phone-specific notes

- Use `search_and_expand` as the default skill.
- Keep API keys in the configuration block near the top of `universal_search/scripts/index.html`.
- Leave debug mode on only when you are testing.
- Keep the output plain and compact in `universal_search`; let `expand_answer` do the rewriting.

## Installation on desktop or laptop

The bundle is phone-safe, but it can also be used on desktop or laptop through an Android emulator or any supported local build of the Gallery app.

### Option 1: Android emulator

1. Install an Android emulator on your computer.
2. Install Google AI Edge Gallery inside the emulator.
3. Load the Gemma model.
4. Copy the skill bundle into the Gallery skill directory used by the emulator.
5. Refresh the skills list.
6. Open `search_and_expand` and test with a simple query such as `OpenAI`.

### Option 2: Supported desktop build

If you are using a desktop build of AI Edge Gallery or a compatible runtime:

1. Open the skill directory used by that runtime.
2. Copy the three skill folders into the correct location.
3. Confirm that `universal_search/scripts/index.html` is present.
4. Reload the app or restart the runtime.
5. Run a test query.

### Desktop and laptop notes

- Use the same skill order as on phone.
- Verify that API keys are valid before testing.
- Start with a simple query such as `debug` if the debug toggle is enabled.

## Supported search and knowledge providers

The bundle supports multiple providers. In auto mode, `universal_search` can try them in sequence and fall back if one is missing, disabled, or unavailable.

| Provider | Description | Free tier limits | API URL |
| --- | --- | --- | --- |
| Serper | Google Search API wrapper with strong general-purpose web search coverage. | 2,500 free queries; no credit card required. | https://serper.dev/ |
| Tavily | Search API designed for AI retrieval and RAG workflows. | Free for students is advertised; the public pricing page also shows a free plan with 1,000 API credits per month. | https://www.tavily.com/pricing |
| Brave Search | Web search API with web, news, image, and other search results. | Includes $5 in free credits every month. | https://brave.com/search/api/ |
| Wolfram Alpha | Computational knowledge engine for math, science, and factual queries. | Up to 2,000 non-commercial API calls per month. | https://products.wolframalpha.com/api |
| Gemini API | Google developer API for model-based retrieval, grounding, and fallback text generation. | Free tier available; quotas vary by model and tier. | https://ai.google.dev/gemini-api/docs/pricing |

## Recommended provider order

The default order in `universal_search` is designed to balance speed, accuracy, and fallback behavior.

Recommended order:

1. Wolfram Alpha
2. Serper
3. Tavily
4. Brave
5. Gemini

This order works well for mixed queries because Wolfram Alpha is strong for numeric and factual lookups, Serper is fast and broad, Tavily is useful for AI-oriented retrieval, Brave is a good fallback search source, and Gemini can act as a final fallback when needed.

## Configuration

Most user-configurable values are grouped near the top of `universal_search/scripts/index.html`.

Typical configuration values include:

- API keys
- default provider order
- debug toggle
- result limit
- output length limit
- timeout settings

## How to use the bundle

##
````
