Skip to main content
Glama

enhance_prompt_gemini

Improves prompts using Gemini API strategies like few-shot examples, output formatting, and context placement to enhance AI response quality.

Instructions

prompt improvement|gemini strategies|quality improvement|prompt enhancement|gemini strategies|quality improvement - Enhance prompts using Gemini API prompting strategies (Few-Shot, Output Format, Context)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesThe original prompt to enhance
agent_roleNoThe role of the agent that will receive this prompt (e.g., "Specification Agent", "Planning Agent")
strategiesNoSpecific Gemini strategies to apply. If not provided, all strategies will be applied.

Implementation Reference

  • Main handler function implementing the tool logic: parses args, applies Gemini-specific prompting strategies (few-shot examples, output format spec, context placement, decomposition, parameters), generates enhancements, combines into enhanced prompt, and formats structured output.
    export async function enhancePromptGemini(args: {
      prompt: string;
      agent_role?: string;
      strategies?: string[];
    }): Promise<ToolResult> {
      const { prompt, agent_role, strategies } = args;
    
      const allStrategies = ['few-shot', 'output-format', 'context-placement', 'decomposition', 'parameters'];
      const strategiesToApply = strategies && strategies.length > 0 ? strategies : allStrategies;
    
      const enhancements: PromptEnhancement[] = [];
    
      // 1. Few-Shot Examples
      if (strategiesToApply.includes('few-shot')) {
        enhancements.push({
          strategy: 'Add Few-Shot Examples',
          description: 'Add 2-3 high-quality examples to guide the model to learn patterns',
          applied: addFewShotExamples(prompt, agent_role),
          improvement: 'Improve consistency by clarifying format, expression, and scope'
        });
      }
    
      // 2. Output Format Specification
      if (strategiesToApply.includes('output-format')) {
        enhancements.push({
          strategy: 'Output Format Specification',
          description: 'Specify structured format with XML tags or markdown headers',
          applied: specifyOutputFormat(prompt, agent_role),
          improvement: 'Clarify desired response structure for easier parsing'
        });
      }
    
      // 3. Context Placement
      if (strategiesToApply.includes('context-placement')) {
        enhancements.push({
          strategy: 'Context Placement Optimization',
          description: 'Place long context before specific requests (Gemini 3 optimization)',
          applied: optimizeContextPlacement(prompt),
          improvement: 'Help model utilize context more effectively'
        });
      }
    
      // 4. Prompt Decomposition
      if (strategiesToApply.includes('decomposition')) {
        enhancements.push({
          strategy: 'Prompt Decomposition',
          description: 'Decompose complex tasks into multiple steps and chain them',
          applied: decomposePrompt(prompt, agent_role),
          improvement: 'Improve output quality at each step, easier debugging'
        });
      }
    
      // 5. Parameter Tuning Suggestions
      if (strategiesToApply.includes('parameters')) {
        enhancements.push({
          strategy: 'Parameter Tuning Suggestions',
          description: 'Suggest optimal values for Temperature, Top-K, Top-P, Max Tokens',
          applied: suggestParameters(prompt, agent_role),
          improvement: 'Optimize model behavior for task type'
        });
      }
    
      const result = {
        original_prompt: prompt,
        agent_role: agent_role || 'Generic Agent',
        strategies_applied: strategiesToApply,
        enhancements,
        enhanced_prompt: combineEnhancements(prompt, enhancements),
        summary: generateSummary(enhancements)
      };
    
      const output = formatOutput(result);
    
      return {
        content: [{ type: 'text', text: output }]
      };
    }
  • ToolDefinition schema defining name 'enhance_prompt_gemini', description, input schema with prompt (required), optional agent_role and strategies, and annotations.
    export const enhancePromptGeminiDefinition: ToolDefinition = {
      name: 'enhance_prompt_gemini',
      description: 'prompt improvement|gemini strategies|quality improvement|prompt enhancement|gemini strategies|quality improvement - Enhance prompts using Gemini API prompting strategies (Few-Shot, Output Format, Context)',
      inputSchema: {
        type: 'object',
        properties: {
          prompt: {
            type: 'string',
            description: 'The original prompt to enhance'
          },
          agent_role: {
            type: 'string',
            description: 'The role of the agent that will receive this prompt (e.g., "Specification Agent", "Planning Agent")'
          },
          strategies: {
            type: 'array',
            items: {
              type: 'string',
              enum: ['few-shot', 'output-format', 'context-placement', 'decomposition', 'parameters']
            },
            description: 'Specific Gemini strategies to apply. If not provided, all strategies will be applied.'
          }
        },
        required: ['prompt']
      },
      annotations: {
        title: 'Enhance Prompt (Gemini Strategies)',
        audience: ['user', 'assistant']
      }
    };
  • src/index.ts:104-160 (registration)
    Registration of the tool definition in the main tools array used for listing tools via MCP protocol.
    const tools: ToolDefinition[] = [
      // Time Utility Tools
      getCurrentTimeDefinition,
    
      // Semantic Code Analysis Tools (Serena-inspired)
      findSymbolDefinition,
      findReferencesDefinition,
    
      // Sequential Thinking Tools
      createThinkingChainDefinition,
      analyzeProblemDefinition,
      stepByStepAnalysisDefinition,
      breakDownProblemDefinition,
      thinkAloudProcessDefinition,
      formatAsPlanDefinition,
    
      // Browser Development Tools
      monitorConsoleLogsDefinition,
      inspectNetworkRequestsDefinition,
    
      // Memory Management Tools
      saveMemoryDefinition,
      recallMemoryDefinition,
      listMemoriesDefinition,
      deleteMemoryDefinition,
      searchMemoriesDefinition,
      updateMemoryDefinition,
      autoSaveContextDefinition,
      restoreSessionContextDefinition,
      prioritizeMemoryDefinition,
      startSessionDefinition,
    
      // Convention Tools
      getCodingGuideDefinition,
      applyQualityRulesDefinition,
      validateCodeQualityDefinition,
      analyzeComplexityDefinition,
      checkCouplingCohesionDefinition,
      suggestImprovementsDefinition,
    
      // Planning Tools
      generatePrdDefinition,
      createUserStoriesDefinition,
      analyzeRequirementsDefinition,
      featureRoadmapDefinition,
    
      // Prompt Enhancement Tools
      enhancePromptDefinition,
      analyzePromptDefinition,
      enhancePromptGeminiDefinition,
    
      // Reasoning Tools
      applyReasoningFrameworkDefinition,
    
      // UI Preview Tools
      previewUiAsciiDefinition
    ];
  • src/index.ts:686-687 (registration)
    Dispatch registration in the executeToolCall switch statement, mapping tool name to handler invocation.
    case 'enhance_prompt_gemini':
      return await enhancePromptGemini(args as any) as CallToolResult;
  • Supporting helper functions for each strategy and output formatting.
    function addFewShotExamples(prompt: string, agent_role?: string): string {
      const examples = {
        'Specification Agent': `
    **Example 1: Push Notification Settings**
    Input: "Let me turn on/off notifications for comments, likes, and follows"
    Output:
    - Notification types: 6 (comments, likes, follows, announcements, events, marketing)
    - Setting method: ON/OFF toggle
    - Design reference: iOS Settings > Notifications
    - Tech stack: FCM (currently in use)
    
    **Example 2: User Profile Editing**
    Input: "Let me change my profile picture and bio"
    Output:
    - Editable fields: Profile picture, bio, display name
    - Validation: Image size < 5MB, bio < 500 chars
    - UI pattern: Inline editing (not modal)
    - Save method: Auto-save (debounce 500ms)`,
    
        'Planning Agent': `
    **Example 1: API Endpoint Addition**
    Input: "User follow/unfollow feature"
    Output:
    - Phase 1: Backend (8 hours)
      - DB schema (follows table)
      - API endpoints (POST /follows, DELETE /follows/:id)
      - Business logic (duplicate prevention, self-follow prevention)
    - Phase 2: Frontend (6 hours)
      - Follow button component
      - Followers/following list
    - Cost impact: +$0 (using existing infrastructure)
    
    **Example 2: Real-time Notifications**
    Input: "Real-time notification when someone comments"
    Output:
    - Phase 1: WebSocket server setup (12 hours)
    - Phase 2: Client subscription logic (8 hours)
    - Phase 3: Notification UI (6 hours)
    - Cost impact: +$20/month (Redis Pub/Sub)`
      };
    
      return examples[agent_role as keyof typeof examples] || `
    **Add Few-Shot examples matching the task type**:
    - Example 1: [Specific input] → [Clear output]
    - Example 2: [Different input format] → [Consistent output format]
    - Example 3: [Edge case] → [How to handle]
    
    **Guidelines**:
    - 2-3 examples (avoid overfitting)
    - Include diverse scenarios
    - Maintain consistent output format`;
    }
    
    function specifyOutputFormat(prompt: string, agent_role?: string): string {
      const formats = {
        'Specification Agent': `
    **Output Format (Markdown + YAML frontmatter)**:
    
    \`\`\`markdown
    ---
    title: [Feature Name]
    priority: [HIGH/MEDIUM/LOW]
    created: [Date]
    ---
    
    # SPEC: [Feature Name]
    
    ## REQ-001: [Requirement Title]
    **WHEN** [Condition]
    **THEN** [Result]
    
    ### Acceptance Criteria
    - [ ] [Criterion 1]
    - [ ] [Criterion 2]
    \`\`\`
    
    **Response prefix**: Start with "# SPEC: " to guide model to complete in correct format`,
    
        'Planning Agent': `
    **Output Format (Structured Markdown)**:
    
    \`\`\`markdown
    # PLAN: [Feature Name]
    
    ## Architecture
    - Backend: [Tech Stack]
    - Frontend: [Tech Stack]
    - Database: [Schema Changes]
    
    ## Timeline
    | Phase | Tasks | Duration |
    |-------|-------|----------|
    | 1     | ...   | 8h       |
    
    ## Cost Analysis
    - Infrastructure: +$X/month
    - Third-party: +$Y/month
    - Total: +$Z/month
    \`\`\`
    
    **Response prefix**: Start with "# PLAN: "`
      };
    
      return formats[agent_role as keyof typeof formats] || `
    **Output Format Specification**:
    - Separate sections with markdown headers (##, ###)
    - Use tables, bullet points, checkboxes
    - Optionally label semantic components with XML tags
      e.g.: <analysis>...</analysis>, <recommendation>...</recommendation>
    - Use response prefix to guide completion
      e.g.: Starting with "Analysis result: " makes model complete with analysis content`;
    }
    
    function optimizeContextPlacement(prompt: string): string {
      return `
    **Context Placement Optimization (Gemini 3 Recommended)**:
    
    1. **Place long context first**:
    \`\`\`
    [Tech stack info (CLAUDE.md content)]
    [Existing codebase structure]
    [Related SPEC/PLAN documents]
    
    --- Specific request below ---
    
    [User's specific question or task]
    \`\`\`
    
    2. **Structure context**:
    - Group by category (tech stack, architecture, business logic)
    - Emphasize important constraints repeatedly
    - Label clearly for reference
    
    3. **Place explicit instructions**:
    - Specific task instructions after context
    - Step-by-step guidelines (1, 2, 3...)
    - Output format examples`;
    }
    
    function decomposePrompt(prompt: string, agent_role?: string): string {
      const isComplex = prompt.length > 200 || prompt.includes('and') || prompt.includes('also') || prompt.includes('and');
    
      if (!isComplex) {
        return '**Prompt decomposition not needed**: Simple task, single prompt is sufficient.';
      }
    
      return `
    **Prompt Decomposition (Sequential Chain)**:
    
    **Step 1: Information Gathering**
    \`\`\`
    Prompt: Identify required information for "${prompt.slice(0, 100)}..."
    Output: List of required tech stack, constraints, prerequisite tasks
    \`\`\`
    
    **Step 2: Analysis and Planning**
    \`\`\`
    Prompt: Create implementation plan based on Step 1 information.
    Input: [Step 1 output]
    Output: Phase-by-phase tasks, timeline, risks
    \`\`\`
    
    **Step 3: Detailed Task Generation**
    \`\`\`
    Prompt: Decompose Step 2 plan into actionable tasks.
    Input: [Step 2 output]
    Output: Task list (with dependencies)
    \`\`\`
    
    **Benefits**:
    - Improved output quality at each step
    - Intermediate validation possible
    - Re-run only specific step on error`;
    }
    
    function suggestParameters(prompt: string, agent_role?: string): string {
      const isCreative = prompt.includes('design') || prompt.includes('idea') || prompt.includes('suggest');
      const isDeterministic = prompt.includes('analyze') || prompt.includes('calculate') || prompt.includes('verify');
    
      let temperature = 1.0; // Gemini 3 default
      let topP = 0.95;
      let topK = 40;
    
      if (isCreative) {
        temperature = 1.0;
        topP = 0.95;
      } else if (isDeterministic) {
        temperature = 0.2;
        topP = 0.8;
        topK = 20;
      }
    
      return `
    **Recommended Parameters** (Based on task characteristics):
    
    - **Temperature**: ${temperature}
      ${temperature > 0.7 ? 'Suitable for creative tasks (explore diverse options)' : 'Suitable for deterministic tasks (consistent output)'}
    
    - **Top-P**: ${topP}
      Select tokens up to ${topP * 100}% cumulative probability
    
    - **Top-K**: ${topK}
      Consider only top ${topK} tokens
    
    - **Max Output Tokens**: ${agent_role === 'Specification Agent' ? '4000 (detailed document)' : '2000 (general)'}
    
    - **Stop Sequences**: ["---END---", "\`\`\`"] (optional)
    
    **Note**:
    - Gemini 3 recommends keeping temperature at default 1.0
    - Avoid deviating significantly from defaults to prevent unexpected behavior`;
    }
    
    function combineEnhancements(prompt: string, enhancements: PromptEnhancement[]): string {
      let enhanced = `# Enhanced Prompt\n\n`;
      enhanced += `## Original Request\n${prompt}\n\n`;
      enhanced += `---\n\n`;
    
      enhancements.forEach((e, i) => {
        enhanced += `## Enhancement ${i + 1}: ${e.strategy}\n\n`;
        enhanced += `${e.applied}\n\n`;
      });
    
      return enhanced;
    }
    
    function generateSummary(enhancements: PromptEnhancement[]): string {
      return `Applied ${enhancements.length} Gemini prompting strategies to improve prompt quality:
    ${enhancements.map(e => `- ${e.strategy}: ${e.improvement}`).join('\n')}`;
    }
    
    function formatOutput(result: any): string {
      let output = `# Gemini Prompt Enhancement\n\n`;
      output += `**Original Prompt**: ${result.original_prompt}\n`;
      output += `**Target Agent**: ${result.agent_role}\n`;
      output += `**Applied Strategies**: ${result.strategies_applied.join(', ')}\n\n`;
      output += `---\n\n`;
    
      result.enhancements.forEach((e: PromptEnhancement, i: number) => {
        output += `## ${i + 1}. ${e.strategy}\n\n`;
        output += `**Description**: ${e.description}\n\n`;
        output += `**Applied Content**:\n${e.applied}\n\n`;
        output += `**Improvement Effect**: ${e.improvement}\n\n`;
        output += `---\n\n`;
      });
    
      output += `## Enhanced Prompt\n\n`;
      output += '```markdown\n' + result.enhanced_prompt + '\n```\n\n';
      output += `## Summary\n\n${result.summary}`;
    
      return output;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations only provide a title, so the description carries the burden of behavioral disclosure. It mentions 'Gemini API prompting strategies' and lists specific techniques (Few-Shot, Output Format, etc.), which adds some context about the enhancement approach. However, it doesn't describe the output format, potential side effects, or how the enhancement is applied (e.g., returns a modified prompt vs. suggestions). With no annotations to rely on, this is a minimal but not comprehensive disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is poorly structured and repetitive, with 'gemini strategies|quality improvement' listed twice, reducing clarity. It's front-loaded with keywords but lacks coherent sentences. While brief, the repetition and lack of flow make it inefficient, as it doesn't earn its place with useful information beyond the initial intent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema and minimal annotations, the description is incomplete. It doesn't explain what the enhanced prompt looks like, how quality is measured, or any limitations (e.g., token limits, strategy interactions). For a tool with 3 parameters and no structured output info, more context is needed to guide effective use, making this inadequate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents parameters like 'prompt', 'agent_role', and 'strategies'. The description doesn't add any meaning beyond this—it doesn't explain how 'agent_role' influences enhancement or what the strategies entail in practice. With high schema coverage, the baseline is 3, as the description doesn't compensate with extra insights.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool enhances prompts using Gemini API strategies, which provides a general purpose. However, it's vague about what 'enhance' specifically means (e.g., rewriting, adding structure, optimizing) and doesn't clearly distinguish from sibling tools like 'enhance_prompt' (without Gemini) or 'suggest_improvements'. The repetition of 'quality improvement' adds noise but doesn't clarify the unique value.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention when to choose it over 'enhance_prompt' (the sibling tool) or other prompt-related tools like 'analyze_prompt' or 'suggest_improvements'. The description lists strategies but doesn't explain scenarios where this tool is appropriate, leaving usage unclear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ssdeanx/ssd-ai'

If you have feedback or need assistance with the MCP directory API, please join our Discord server