Source Code:
examples/hardware_advisor_agent.pyWhy Build This Agent?
Privacy-First AI: This agent runs entirely on your AI PC. Hardware detection and model recommendations happen locally—no data leaves your machine.
- Detects system RAM, GPU, and NPU via Lemonade Server
- Queries the available model catalog with size estimates
- Calculates which models fit in available memory
- Provides personalized recommendations based on real hardware specs
- LemonadeClient SDK - System info and model catalog APIs
- Platform-specific detection - Windows PowerShell / Linux lspci for GPU info
- Memory calculations - 70% rule for safe model sizing
- Interactive CLI - Natural language queries about capabilities
- Local execution - Runs entirely on your AI PC using Ryzen AI acceleration
The Architecture (What You’re Building)
Flow:- User query → HardwareAdvisorAgent (orchestrator)
- Agent selects tool → get_hardware_info / list_available_models / recommend_models
- Tools call → LemonadeClient SDK + OS-specific detection
- Results aggregated → Agent synthesizes recommendation
- User receives personalized advice
Quick Start (5 Minutes)
Get a working agent running to understand the basic flow.1
Set up your project
Choose your installation path:
- PyPI (Recommended)
- Developer (Editable Install)
Create a new project folder and install from PyPI:
This is the recommended path for most users. You’ll create your agent scripts in this folder.
2
Start Lemonade Server
Lemonade Server provides AMD-optimized inference for AI PCs with Ryzen AI. It also exposes system info and model catalog APIs that this agent uses.
3
Run the Hardware Advisor
- PyPI Installation
- Developer Installation
Create
hardware_advisor.py in your project folder and follow the step-by-step build below, or copy the complete example from the Building It section.- “What size LLM can I run?”
- “Show me my system specs”
- “What models are available?”
- “Can I run a 30B model?”
4
See it in action
Example interaction:
The agent requires Lemonade Server to be running for hardware detection and model catalog queries. GAIA auto-starts it on first use if not running.
Understanding the Components
Before we build step-by-step, let’s understand what each piece does under the hood.1. LemonadeClient SDK
- Import
- get_system_info()
- list_models()
- get_model_info()
- Provides unified API for system detection
- Returns NPU/GPU availability from Lemonade Server
- Model catalog with size estimates for recommendations
2. Platform-Specific GPU Detection
- Windows
- Linux
- Why Not PyTorch?
3. The 70% Memory Rule
Rule: Model size should be less than 70% of available RAM to leave 30% overhead for inference operations.
- KV cache for context window
- Batch processing buffers
- Runtime memory spikes during generation
Building It: The Step-by-Step Journey
Now let’s build this agent incrementally using a single file that grows with each step. We’ll build exactly what’s inexamples/hardware_advisor_agent.py by adding functionality progressively.
Building Strategy: You’ll create ONE file called
hardware_advisor.py and progressively add features to it. Each step builds on the previous one, and by Step 6 you’ll have code that matches the example exactly.Step 1: Agent Skeleton
Start by creating the file with a minimal agent structure—just the class and a basic system prompt. This creates the foundation, but the agent has no tools yet and cannot answer queries.Implementation
hardware_advisor.py
Running It
Progress Check
- ✓ Basic agent structure
- ✓ LemonadeClient connection
- ✓ Minimal system prompt
- ✗ GPU detection helper (
_get_gpu_info()) - ✗ Hardware detection tool (
get_hardware_info()) - ✗ Model catalog tool (
list_available_models()) - ✗ Smart recommendations tool (
recommend_models()) - ✗ Interactive CLI
Step 2: GPU & Hardware Detection
Add the_get_gpu_info() helper method and the full get_hardware_info() tool with GPU object, NPU object, and OS field. This makes the agent interactive—you can now query it about system specs!
Implementation
First, update the imports at the top of the file:_get_gpu_info() helper after the _get_system_prompt() method:
_register_tools() method with:
__main__ block to enable interactive testing:
Running It
Progress Check
- ✓ Basic agent structure
- ✓ LemonadeClient connection
- ✓ Minimal system prompt
- ✓ GPU detection helper (
_get_gpu_info()) - ✓ Hardware detection tool (
get_hardware_info()) - ✗ Model catalog tool (
list_available_models()) - ✗ Smart recommendations tool (
recommend_models()) - ✓ Interactive CLI
Step 3: Model Catalog
Add thelist_available_models() tool with labels field and message in the response. Now the agent can tell you what models are available in the Lemonade catalog.
Implementation
Add this tool inside the_register_tools() method (after the get_hardware_info function):
__main__ block stays the same (already interactive from Step 2)
Running It
Progress Check
- ✓ Basic agent structure
- ✓ LemonadeClient connection
- ✓ Minimal system prompt
- ✓ GPU detection helper (
_get_gpu_info()) - ✓ Hardware detection tool (
get_hardware_info()) - ✓ Model catalog tool (
list_available_models()) - ✗ Smart recommendations tool (
recommend_models()) - ✓ Interactive CLI
Step 4: Smart Recommendations
Add the completerecommend_models() tool with estimated_runtime_gb, fits_in_ram, fits_in_gpu, and constraints object. The agent can now calculate which models fit in your system’s memory!
Implementation
Add this tool inside the_register_tools() method (after the list_available_models function):
__main__ block stays the same (already interactive from Step 2)
Running It
Progress Check
- ✓ Basic agent structure
- ✓ LemonadeClient connection
- ✓ Minimal system prompt
- ✓ GPU detection helper (
_get_gpu_info()) - ✓ Hardware detection tool (
get_hardware_info()) - ✓ Model catalog tool (
list_available_models()) - ✓ Smart recommendations tool (
recommend_models()) - ✓ Interactive CLI
Step 5: Production CLI
Replace the simple__main__ block with a full interactive CLI function. This adds a professional banner, better error handling, and graceful exit options.
Implementation
Replace the entireif __name__ == "__main__": block at the end of the file with:
Running It
Progress Check
- ✓ Basic agent structure
- ✓ LemonadeClient connection
- ✓ Minimal system prompt
- ✓ GPU detection helper (
_get_gpu_info()) - ✓ Hardware detection tool (
get_hardware_info()) - ✓ Model catalog tool (
list_available_models()) - ✓ Smart recommendations tool (
recommend_models()) - ✓ Interactive CLI
Step 6: Final Verification
Verify that yourhardware_advisor.py has all the components working together correctly.
Verify Structure
Your file should have:- ✓ Imports:
from typing import Any, Dictandfrom gaia import Agent, tool - ✓ LemonadeClient import:
from gaia.llm.lemonade_client import LemonadeClient - ✓
HardwareAdvisorAgentclass with minimal__init__and one-line system prompt - ✓
_get_gpu_info()helper method (Windows and Linux GPU detection) - ✓
_register_tools()method withclient = self.clientandagent = self - ✓
get_hardware_info()tool with GPU object, NPU object, and OS field - ✓
list_available_models()tool withlabelsandmessagefields - ✓
recommend_models()tool withestimated_runtime_gb,fits_in_ram,fits_in_gpu,constraints - ✓
main()function with interactive CLI (banner, loop, quit handling) - ✓
if __name__ == "__main__": main()
Test Your Implementation
Run your agent:- “What size LLM can I run?”
- “Show me my system specs”
- “What models are available?”
- “Can I run a 30B model?”
- Agent starts with interactive banner
- Hardware detection returns system specs
- Model catalog lists available models
- Recommendations calculate safe model sizes based on your RAM
Complete!
- ✓ Basic agent structure
- ✓ LemonadeClient connection
- ✓ Minimal system prompt
- ✓ GPU detection helper (
_get_gpu_info()) - ✓ Hardware detection tool (
get_hardware_info()) - ✓ Model catalog tool (
list_available_models()) - ✓ Smart recommendations tool (
recommend_models()) - ✓ Interactive CLI
Congratulations! You’ve built a fully functional hardware advisor agent! Your implementation includes OS-native GPU detection, smart memory-based recommendations, and an interactive CLI—all running locally on AMD hardware with Ryzen AI acceleration.
Under the Hood
Under the Hood: Hardware Detection Flow
Under the Hood: Hardware Detection Flow
Detection sequence:Platform-specific notes:
- Windows: Uses WMI queries via PowerShell (wmic deprecated on Windows 11)
- Linux: Uses lspci for GPU detection (memory not available via this method)
- NPU: Only available on Ryzen AI processors (8000/9000 series)
- System info query: ~50ms
- GPU detection: ~200ms (subprocess overhead)
- NPU detection: ~10ms (cached in Lemonade Server)
Under the Hood: Recommendation Algorithm
Under the Hood: Recommendation Algorithm
Memory calculation logic:Safety margins explained:
- 70% rule: Prevents OOM errors during inference peaks
- 30% overhead: Accounts for KV cache, context window, batch processing
- GPU 90% rule: Reserves 10% VRAM for driver overhead
Under the Hood: Error Handling Pattern
Under the Hood: Error Handling Pattern
Consistent response structure:All tools return dictionaries with this pattern:Benefits:
- LLM can check
successfield before using data - Error messages help LLM explain issues to users
- Consistent pattern across all tools
The Complete Implementation
The full implementation is available at:- GPU detection for both Windows and Linux
- Interactive CLI with suggested questions
- Timeout handling for subprocess calls
- Graceful error recovery
View Source
See the complete Hardware Advisor Agent implementation on GitHub
Try It Out
Run the agent and try these queries:- “What size LLM can I run?”
- “Show me my system specs”
- “What models are available?”
- “Can I run a 30B model?”
- “Which models are already downloaded?”
Next Steps
You’ve built a hardware advisor agent! Here are ways to extend it:LLM Integration
Explore LLM client APIs for model management
Voice Integration
Add speech recognition and text-to-speech to your agent