Skip to main content
  • Time to complete: 15-20 minutes
  • What you’ll build: A basic chat agent with RAG and file discovery
  • What you’ll learn: Agent architecture, RAG integration, and the tool system
  • Platform: Runs locally on AI PCs with Ryzen AI (NPU/iGPU acceleration)

Why Build This Agent?

Privacy-First AI: This agent runs entirely on your AI PC with Ryzen AI. All processing happens locally—document content never leaves your machine.
If you have hundreds of PDF documents spread across your system—manuals, reports, specifications—finding specific information is tedious. You need to remember which file contains what, open each one, search manually, and piece together information from multiple sources. This agent automates that process entirely on your AI PC:
  1. Finds relevant documents on your drive
  2. Indexes them with vector embeddings (NPU-accelerated on Ryzen AI)
  3. Searches semantically using cosine similarity
  4. Returns specific information with source citations
  5. Runs completely locally—no cloud, no data leaving your machine
What you’re building: A chat agent that combines:
  • Agent reasoning - LLM-based tool selection and orchestration
  • RAG (Retrieval-Augmented Generation) - Vector search over document chunks
  • File discovery - Automated search across common directories
  • File monitoring - Watches folders and re-indexes on changes
  • Session persistence - Saves indexed state across restarts
  • Local execution - Runs entirely on your AI PC using Ryzen AI NPU/iGPU acceleration

The Architecture (What You’re Building)

Flow:
  1. User query → ChatAgent (orchestrator)
  2. Agent selects tool → RAGToolsMixin
  3. RAGToolsMixin calls → RAG SDK
  4. RAG SDK retrieves chunks from vector index → back to Agent
  5. Agent synthesizes answer → User receives response

Quick Start (5 Minutes)

Get a working agent running to understand the basic flow.
1

Set up your project

Choose your installation path:
2

Start Lemonade Server

Lemonade Server provides AMD-optimized inference for AI PCs with Ryzen AI. Models run on your NPU or iGPU for fast, private processing.
3

Create your first agent

Create my_chat_agent.py in your project folder:
my_chat_agent.py
4

Run it

What happens:
  1. PDF text extraction (PyMuPDF)
  2. Chunking into 500-token segments
  3. Embedding generation (EmbeddingGemma 300M running on NPU/iGPU)
  4. FAISS index creation
  5. Query processing via vector search
  6. LLM generates answer using retrieved chunks (Ryzen AI acceleration)
If you don’t have a PDF, the agent operates in general conversation mode using the LLM’s training data.
no_documents.py

Understanding the Components

Before we build step-by-step, let’s understand what each piece does under the hood.

1. The Agent Base Class

Processing flow when you call process_query(): Trade-off: You delegate control flow to the LLM. This is flexible but less deterministic than traditional programming.

2. The Tool Decorator

Implementation: The LLM receives tool schemas as context and decides when to invoke each function based on the user’s query and conversation state.

3. RAG SDK (Document Retrieval)

RAG pipeline: Why chunks?
  • LLMs have context window limits (e.g., 4096 tokens)
  • Smaller chunks enable more precise semantic matching
  • Overlap preserves context at chunk boundaries and reduces information loss
AMD Hardware Acceleration: Embedding generation runs on the Ryzen AI NPU/iGPU, enabling fast document indexing with minimal CPU usage on AI PCs.

4. Tool Mixins

Mixins are classes that provide reusable tool sets via Python multiple inheritance.

Building It: The Step-by-Step Journey

Now let’s build this agent incrementally, understanding each piece as we go.

Step 1: The Simplest Possible Agent

Start with a minimal agent implementation to understand the core structure.
step1_basic.py
Initialization:
Query processing:
Limitations:
  • No tools = no ability to execute actions
  • Cannot access external data sources
  • Relies solely on LLM training data
This basic agent cannot retrieve information from documents or perform actions. It’s limited to conversation using the LLM’s pre-trained knowledge.

Step 2: Add RAG (Document Understanding)

Add RAG capability to enable document search and retrieval.
step2_with_rag.py
Indexing phase (__init__):
On AI PCs with Ryzen AI, the embedding model runs on the NPU for efficient processing.
Query phase (process_query):
Key benefit: Grounding LLM responses in actual document text reduces hallucination for domain-specific content.
What you have: Document retrieval via vector search. The agent can answer questions using your specific documents rather than general knowledge.

Step 3: Add Smart File Discovery

Add file discovery to avoid hardcoding document paths.
Example query: “Find the oil manual and tell me about safety”LLM orchestration (automatic):
Implementation note: You define Python functions. The LLM decides when to call them based on tool schemas and user intent.
What you have: File discovery without hardcoded paths. The agent can locate, index, and query documents based on pattern matching.

Next Steps

You’ve built a functional document Q&A agent with RAG and file discovery! Continue with Part 2 to add more capabilities:

Part 2: Advanced Features & Customization

Add tool mixins, file monitoring, session persistence, and learn how to customize your agent for specific use cases.