Skip to main content
First time here? Complete the Setup guide first to install GAIA and its dependencies.
Just want to use the agent? See the Medical Intake Agent Guide for quick start instructions without building from scratch.
  • Time to complete: 20-25 minutes
  • What you’ll build: An automated medical intake form processor
  • What you’ll learn: FileWatcherMixin, DatabaseMixin, VLM integration, and agent composition
  • Platform: Runs locally on AI PCs with Ryzen AI (NPU/iGPU acceleration)

Why Build This Agent?

Medical staff spend hours manually entering intake form data. This agent automates the process—form arrives, VLM extracts data, database stores it—all running locally on your AI PC. What you’ll learn: FileWatcherMixin, DatabaseMixin, VLM integration, and agent composition patterns.

The Architecture (What You’re Building)

Flow:
  1. New form dropped in watched folder
  2. FileWatcherMixin triggers callback → _on_file_created()
  3. VLM extracts patient data (Gemma-4-E4B-it GGUF runs on the iGPU via llama.cpp/Vulkan)
  4. JSON parsed and validated
  5. DatabaseMixin stores structured record in SQLite
  6. Agent can now query patients via natural language

Quick Start (5 Minutes)

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

Set up your project

Choose your installation path:
2

Start Lemonade Server

The VLM model (Gemma-4-E4B-it-GGUF) will be downloaded automatically on first use. This may take time depending on your connection.
3

Create your first intake agent

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

Run it

What happens:
  1. Creates ./intake_forms/ directory
  2. Creates ./data/patients.db SQLite database
  3. Starts watching for new files
  4. Processes your query using patient data
5

Test with a sample form

Drop an image of an intake form in ./intake_forms/:
You’ll see:

Core Components

Three components power this agent:

Step-by-Step Implementation

Build the agent incrementally to understand each component.

Step 1: Basic Agent Shell

Start with the simplest version—no file watching yet, just database setup.
step1_basic.py
Checkpoint: Run it and verify database is created at ./data/patients.db. Use a SQLite browser to inspect the schema.

Step 2: Add VLM Extraction

Add VLM to extract patient data from images.
step2_with_vlm.py
Extraction flow:
VLM prompt engineering:
  • Specify exact JSON structure needed
  • Request “ONLY valid JSON” to reduce parsing errors
  • Use strict date formats (YYYY-MM-DD)
  • Handle null values explicitly

Step 3: Add Automatic File Watching

Make the agent fully automatic—process forms as soon as they arrive.
step3_automatic.py
Try it:
  1. Run python step3_automatic.py
  2. In another terminal: cp sample_form.jpg ./intake_forms/
  3. Watch the agent automatically process it
  4. Query: “Show me all patients named Smith”

Testing Your Agent

Use GAIA’s testing utilities to test without real VLM/LLM.
test_intake_agent.py

Key Patterns and Best Practices

Pattern 1: Initialize Attributes Before super().init()

Why: super().__init__() calls _get_system_prompt(), which may reference your attributes.

Pattern 2: Lazy VLM Initialization

Why: VLM model loading is slow. Don’t load it until you actually process a file.

Pattern 3: Robust JSON Parsing

Why: VLMs sometimes add explanatory text around JSON. GAIA’s extract_json_from_text handles nested objects correctly (unlike simple regex).

Pattern 4: Context Manager Cleanup

Why: Ensures database connections close and file watchers stop properly.

What’s Next?

Part 2: Dashboard & API

Build a real-time web dashboard with FastAPI, SSE streaming, and React components

Part 3: Architecture

Deep dive into database schema, processing pipeline, and production considerations

Full Working Example

The complete MedicalIntakeAgent implementation is available in GAIA:
Source code: hub/agents/python/emr/gaia_agent_emr/agent.py