Skip to main content
CLI Command: gaia sd - Demonstrates multi-modal agents with SDToolsMixin + VLMToolsMixinSDK Reference: SDToolsMixin APIVLMToolsMixin API

What It Is

The gaia sd command demonstrates GAIA’s multi-modal agent architecture through a practical example: generating images with AI-enhanced prompts and automatic story creation. Local models working together on Ryzen AI:
  • 🧠 LLM (Gemma-4-E4B) - Analyzes your input, plans workflow, adds quality keywords
  • 🖼️ Stable Diffusion (SDXL-Turbo) - Generates images from enhanced prompts
  • 👁️ VLM (Gemma-4-E4B) - The same multimodal model analyzes images and writes stories
Type “robot kitten” → Get image + 2-3 paragraph story about the character

See It In Action

Complete multi-modal workflow: Prompt enhancement → Image generation → VLM analysis → Story creation (all in ~35 seconds)

Quick Start

First time? See Setup Guide to install GAIA and Lemonade Server.
1

Initialize GAIA (first time only)

This installs Lemonade Server and downloads all required models (~10GB):
  • SDXL-Turbo (image generation - 6.5GB)
  • Gemma-4-E4B-it-GGUF (multimodal: agentic reasoning, prompt enhancement, and vision/stories - ~3GB)
Already installed a different profile? Run this to add the SD models to your existing setup.
2

Generate image with story

LLM enhances prompt → SD generates image (~17s) → VLM creates story (~17s)Output:
  • Images: .gaia/cache/sd/images/robot_kitten.png
  • Stories: .gaia/cache/sd/images/robot_kitten_story.txt (auto-generated)
The story file includes both the VLM-generated narrative and image description.
The agent uses two models (auto-downloaded on first use):
  • SDXL-Turbo (6.5GB) - Image generation
  • Gemma-4-E4B-it-GGUF (~3GB) - Multimodal model for agentic reasoning, prompt enhancement, and vision/stories
Total: ~10GB for the complete multi-modal experience.Why a multimodal LLM? A single Gemma-4-E4B model handles both the agentic planning/tool-calling (LLM role) and image analysis/story writing (VLM role), so there’s no separate vision model to load.Already have them? The agent will use what’s available.

How It Works

Multi-Modal Agent Architecture

Execution Flow:
  1. Agent plans which tools to call based on request
  2. generate_image() → LLM enhances prompt → SDXL-Turbo generates (~17s)
  3. analyze_image() → Gemma-4-E4B describes the image
  4. create_story_from_image() → Gemma-4-E4B writes creative story (~17s)
All models run locally on Ryzen AI. Agent orchestrates the multi-modal workflow.

Example Output

What you see when you run gaia sd "create a cute robot kitten and tell me a short story about it":

Different Use Cases

The agent adapts to what you ask for:
The agent plans flexibly based on your request.

Models

Plus VLM: +17s for story creation (optional, based on request)
Performance benchmarks measured on AMD Ryzen AI MAX+ 395 with Radeon 8060S (16 cores, 32 threads @ 3.0 GHz). Your performance may vary based on hardware configuration.

Under the Hood: Architecture

Multi-Modal Agent Design

The SD Agent combines three mixins:
Available tools:
  • generate_image(prompt, model, size, steps, cfg_scale) - Generate with SD
  • analyze_image(image_path, focus) - VLM description
  • create_story_from_image(image_path, story_style) - VLM narrative, registered by SDAgent._register_tools()
  • list_sd_models() - Show available models

Tool Composition Example

SDAgent registers a single story tool (create_story_from_image) and relies on the agent’s $PREV placeholder substitution to chain it after generate_image. The planner produces a 2-step plan where step 2’s image_path is the path returned by step 1:
Why atomic=True? Inside the tool we make a VLM call; marking it atomic prevents the planner from trying to decompose it further. The planner simply calls create_story_from_image once with the image path from the previous step.

Agent Orchestration & Planning

The agent uses a plan-execute-reflect cycle powered by the LLM:
  1. Planning Phase - LLM analyzes user request and creates a plan
    • Examines available tools in the registry
    • Decides which tools to call and in what order
    • Can create multi-step plans: [generate_image, analyze_image, create_story_from_image]
  2. Execution Phase - Agent executes tools sequentially
    • Calls each tool with generated parameters
    • Captures results and errors
    • Maintains state in self.sd_generations list
  3. Reflection Phase - LLM examines results
    • Checks if goal achieved
    • Decides whether to continue or provide final answer
    • Can replan if errors occur (max 10 steps by default)
Example Planning:
The $PREV.image_path placeholder is automatically substituted with the real path returned by the preceding step before the tool is invoked.

Tool Discovery & Registration

Tools are discovered through a global registry pattern:
The LLM receives tool descriptions in its system prompt and decides which to call based on the user’s request.

State Management

The agent tracks generation history for session context:
This enables:
  • Chaining generate_imagecreate_story_from_image using $PREV.image_path
  • Session continuity (“create another one” references previous)

Multi-Model Coordination

Two models collaborate across three roles (Gemma-4-E4B serves both the LLM and VLM roles): Communication Flow:
Each model is loaded on-demand and cached by Lemonade Server.

System Prompt Intelligence

The agent’s system prompt encodes research-backed prompt engineering strategies tailored to each SD model. The LLM learns these patterns and applies them automatically. Research Sources (2026): Enhancement Strategy:
Parameters: size="512x512", steps=4, cfg_scale=1.0
Parameters: size="1024x1024", steps=20, cfg_scale=7.5
Why This Works: The LLM learns patterns from the system prompt’s examples and applies them contextually:
  • Sees user input: “robot kitten”
  • Matches to enhancement pattern for current model
  • Generates: enhanced prompt with quality keywords
  • Calls: generate_image(enhanced_prompt, size=512x512, steps=4, cfg_scale=1.0)
This approach is more flexible than hardcoded templates - the LLM can adapt enhancements based on user intent while following proven guidelines.

Options


Troubleshooting

If you only see image generation without story, the agent chose not to create one based on your request.To explicitly request story:
Or ask for it separately:
VLM analysis + story creation takes ~17 seconds total (two VLM calls).To skip stories (faster):
The agent decides based on your phrasing.
Gemma-4-E4B-it-GGUF needs 16K context for multi-step planning. Start Lemonade with:
Or use gaia init --profile sd to configure automatically.

Under the Hood: Composable System Prompts

The SD Agent uses GAIA’s composable system prompt pattern introduced in the playbook.

How It Works

SDToolsMixin provides prompt engineering guidelines automatically:
Agents automatically inherit this knowledge through mixin composition.

Debugging Prompts

To see what prompt the agent uses:
See the Agent System Deep Dive for more debugging methods.

Random Seeds for Variety

By default, each generation uses a random seed for unique results:
For reproducible results, specify a seed:
The agent returns the seed used in the response, so you can reproduce any image.

Hardware Acceleration

Current implementation: GGUF models run on integrated GPU via Vulkan. SD currently runs on CPU (GPU acceleration planned).

Next Steps

Build Your Own Agent

Complete playbook: Build a multi-modal image generation agent in ~60 lines of code

CLI Reference

Complete option reference