name: google-ai-studio description: Orchestrates Gemini models via Google AI Studio and Gemini CLI for reasoning, code generation, multimodal analysis, and automated workflows. Use when user says "Gemini", "Google AI", "Gemini CLI", "prompt engineering", "model selection", "context window", "multimodal", "image analysis", "large context", "schedule Gemini", or needs AI model orchestration beyond Claude. compatibility: Requires Google AI Studio API key (GEMINI_API_KEY). Supports Gemini 2.0 Pro (long-horizon) and Flash (rapid tasks). Gemini CLI for terminal workflows. Integrates with knowledge-harvester for grounded prompting and n8n for scheduled automation. metadata: author: Apex AI Fleet version: 3.0.0 category: ai-orchestration tags: [gemini, google-ai, prompt-engineering, multimodal, model-selection, reasoning, gemini-cli, automation]
Google AI Studio: Model Orchestration and Gemini CLI
Enables orchestration of Gemini models for specialized tasks. Selects the right model for the right task horizon. Includes Gemini CLI setup for terminal-based AI workflows and n8n-scheduled automation.
Instructions
Step 1: Classify the Task Horizon
Match the task to the right model:
| Task Type | Model | Why |
|---|---|---|
| Long-horizon planning, complex architecture | Gemini 2.0 Pro | Deep reasoning, large context |
| Rapid prototyping, simple refactors | Gemini 2.0 Flash | Speed + cost optimized |
| Image generation/editing | Imagen 3 | Native visual generation |
| Screenshot/UI analysis | Gemini 2.0 Pro | Multimodal spatial reasoning |
| Data extraction at scale | Gemini 2.0 Flash | High throughput, low latency |
| Marketing content batch generation | Gemini 2.0 Flash | Speed for scheduled workflows |
| Codebase-wide analysis | Gemini 2.0 Pro | 1M+ token context window |
Step 2: Gemini CLI Setup
Install and authenticate the CLI for terminal-based workflows:
# Install the Google Generative AI SDK
npm install -g @google/generative-ai
# Set your API key
export GEMINI_API_KEY="your-api-key-from-ai-studio"
# Add to shell profile for persistence
echo 'export GEMINI_API_KEY="your-api-key"' >> ~/.bashrc
source ~/.bashrc
# Verify connection
gemini "Respond with 'Connected' if you can read this"
To get an API key:
- Go to Google AI Studio (aistudio.google.com)
- Click "Get API Key"
- Create key in your GCP project (see google-workspace-setup skill)
- Copy and set as environment variable
Step 3: Construct the Prompt
Follow these prompt engineering standards:
- System instruction: Define the role, constraints, and output format
- Context grounding: Include relevant docs from
knowledge/tool-docs/ - Task specification: Clear, unambiguous instruction
- Output format: Specify JSON, Markdown, code, or other format explicitly
- Thinking enabled: Use thinking levels to verify reasoning before execution
Prompt structure:
System: You are [role] specializing in [domain].
Context: [Relevant grounding documents]
Task: [Specific instruction]
Output: [Expected format and constraints]
For Gemini CLI, pipe context directly:
# Ground with project DNA
cat mygenie_dna.md | gemini "Based on this project context, [task]"
# Analyze code
cat site/app/api/leads/route.ts | gemini "Review this API route for security issues"
# Multi-file analysis
find site/app/api -name "*.ts" -exec cat {} + | gemini "Identify inconsistencies across these API routes"
Step 4: Execute and Validate
- Send the prompt to the selected model
- Enable thinking/reasoning traces for complex tasks
- Validate output against expected format
- Cross-reference factual claims against knowledge base
- Retry with refined prompt if output quality is insufficient
Step 5: Scheduled Automation via n8n
Set up Gemini to run on a schedule through n8n:
| Schedule | Task | Model | n8n Workflow |
|---|---|---|---|
| Daily 6AM | Industry news digest | Flash | Cron → HTTP Request (Gemini API) → Slack |
| Monday 8AM | Weekly content batch | Flash | Cron → Gemini → Save to Drive |
| Wednesday | Blog outline from calendar | Pro | Cron → Read Calendar → Gemini → Draft |
| Friday 4PM | Analytics review | Pro | Cron → GA4 API → Gemini Analysis → Slack |
n8n HTTP node configuration for Gemini API:
{
"url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"qs": {
"key": "{{$credentials.geminiApiKey}}"
},
"body": {
"contents": [
{
"parts": [
{"text": "Your prompt here"}
]
}
]
}
}
Step 6: Context Window Management
For large codebase analysis:
- Estimate token count before sending (rough guide: 1 token per 4 chars)
- Use the full context window for repository-wide reasoning
- Chunk large inputs if they exceed model limits
- Prioritize most relevant files first in the context
Examples
Example 1: Codebase Architecture Review
User says: "Analyze our entire codebase structure with Gemini"
Actions:
- Select Gemini 2.0 Pro (needs deep reasoning + large context)
- Gather all source files into context
- Prompt for architecture analysis with specific focus areas
- Return structured findings with recommendations Result: Comprehensive architecture review with actionable insights
Example 2: Automated Marketing Pipeline
User says: "Set up Gemini to generate our weekly marketing content"
Actions:
- Configure Gemini CLI with marketing-specific system prompts
- Create n8n workflow with Monday 8AM cron trigger
- Workflow fetches this week's theme from content calendar
- Calls Gemini API with LinkedIn post generation prompt
- Saves drafts to Google Drive for human review
- Sends Slack notification with preview links Result: Weekly content generated automatically, queued for approval
Example 3: Rapid Data Extraction
User says: "Extract pricing data from these 50 competitor pages"
Actions:
- Select Gemini 2.0 Flash (high throughput task)
- Batch URLs for parallel processing
- Define extraction schema (product, price, features)
- Validate extracted data for completeness Result: Structured pricing dataset in JSON format
Troubleshooting
Model Returns Low-Quality Output
- Add more context grounding from
knowledge/tool-docs/ - Be more specific in the task instruction
- Enable thinking mode for complex reasoning tasks
- Try upgrading from Flash to Pro for the task
Gemini CLI Not Responding
- Verify API key:
echo $GEMINI_API_KEY - Test API directly with curl (see google-workspace-setup troubleshooting)
- Check GCP Console for quota/billing issues
- Ensure the Generative Language API is enabled in your GCP project
Context Window Exceeded
- Prioritize the most relevant files/sections
- Summarize less critical context before including
- Split into multiple prompts with carry-forward summaries
Rate Limiting
- Implement exponential backoff on retries
- Use Flash for bulk operations to stay within quotas
- Queue requests through n8n for managed throughput
- Check your quota tier in GCP Console > APIs > Quotas
n8n Scheduled Workflow Fails
- Verify API key is stored in n8n Credentials (not hardcoded)
- Check the HTTP node response body for error messages
- Ensure the Gemini API URL and model name are correct
- Monitor n8n execution history for timeout issues