Skip to main content
Source Code: cpp/examples/process_agent.cpp — single-file, self-contained agent (~2,900 lines including 7 tools, action menu, and decision support).
Platform: Windows (Win32 APIs + PowerShell). Compiles on Linux/macOS for CI but tools require Windows to return real data. Prerequisite: Lemonade Server running with a model loaded. Recommended: Run as Administrator for full process visibility and quarantine access.

What This Agent Does

The Process Analyst is an AI agent that makes sense of what’s running on your PC. On startup it scans every process and service, classifies them by resource use and behavior, and shows you a plain-English summary. You can ask it to explain any task — what it is, what it does, and whether there’s reason to be concerned — or take action directly. Here’s what makes it interesting:
  • It explains what’s running — every process gets a plain-English description: what it is, what it does, and whether it looks normal
  • Ask about any task — describe an item from the summary and get a clear explanation without needing technical knowledge
  • Manage processes and services — stop, restart, or quarantine items; the agent always asks before acting
  • Background monitoring — toggle a background watcher that alerts you to memory spikes, new suspicious items, and health changes while you keep working
  • Everything is local — no data leaves your machine

See It In Action

The agent auto-runs a full system scan on startup, then waits for your input. You can ask about any item in plain English — or use the action menu to stop, restart, or quarantine it.

Quick Start

1

Build

If CMake reports a generator or platform mismatch, a stale build\ directory from a previous run is causing the conflict. Delete it and reconfigure:
Binary: build\Release\process_agent.exe
2

Start Lemonade Server

The agent connects to http://localhost:13305/api/v1 by default.
3

Run the agent

The agent auto-analyzes on startup. After the scan completes, you’ll see a summary followed by an action menu:
Each item gets a label (A1, A2, C1, etc.) you can use in any command:
For full process visibility and quarantine access, right-click your terminal and select Run as administrator before launching the agent.

Architecture

The agent runs in two phases. On startup it auto-scans the system — no menu shown first. The LLM calls system_snapshot and list_processes, classifies everything into three labeled sections (A: Processes, B: Services, C: Suspicious Items), then presents an action menu. Conversation history is preserved across all actions so the LLM can reference any labeled item without re-scanning. Only Reanalyze clears history, because the system state has genuinely changed.

How It Works

The entire agent is a single .cpp file with six sections. Let’s walk through each one.
  1. Shell Helper — bridges C++ and PowerShell for command execution and validates inputs
  2. Win32 Process Intelligence — native API for fast process snapshots with file version info
  3. Tool Registration — 7 tools the LLM can call (3 read-only + 4 destructive)
  4. System Prompt — teaches the LLM the A/B/C classification protocol
  5. ProcessConsole — custom TUI that formats A/B/C sections with color coding
  6. Monitor Mode — background thread that diffs snapshots and surfaces alerts
The agent subclasses gaia::Agent with three pieces: a config, registered tools, and a system prompt.

1. The Shell Helper: Bridging C++ and PowerShell

The runShell() function wraps PowerShell execution, building a command string and reading output through a pipe:
The agent also includes a dedicated path validator for quarantine operations:
Why a separate path validator? File paths need drive-letter validation and a different dangerous character set than shell arguments. isSafeShellArg() rejects single quotes (valid in Windows paths), while isSafePath() requires the X:\ prefix and allows single quotes but blocks shell metacharacters. Two validators, two threat models.

2. Win32 Process Intelligence

Rather than relying on PowerShell for everything, the Process Analyst uses native Win32 APIs for its hot path — process enumeration and memory measurement. The core of getTopProcesses() takes a snapshot, groups processes by exe name, then enriches each entry with version info and factual flags:
Three design choices worth understanding:
  • PerformanceCreateToolhelp32Snapshot + K32GetProcessMemoryInfo returns data in ~20ms for 200+ processes. Get-Process | ConvertTo-Json takes 2-3 seconds for the same data. When the agent needs to scan on every startup, that difference matters.
  • Process grouping — Instead of listing 45 separate chrome.exe entries, the agent groups by exe name with instance count and total memory. The LLM sees “chrome.exe x45 — 3.2 GB” which is far more actionable than 45 lines of individual PIDs.
  • Factual flagsunknown_company, unknown_description, temp_path are computed as structured metadata from Win32 GetFileVersionInfoW and path analysis. The LLM uses these as input to classification, not as final verdicts.

3. Tool Registration: Teaching the Agent What It Can Do

Tools are registered with a name, description, callback, and typed parameter list. The framework automatically includes registered tools in the system prompt sent to the LLM. Here’s system_snapshot, which demonstrates the hybrid Win32 + PowerShell approach:
And kill_process, which shows parameter validation and the command + output contract:
Why command + output keys? Every tool returns both a command string and an output string. The ProcessConsole uses these for its TUI display — the command appears in the tool header, and output appears in the preview box. This consistent contract means the output handler doesn’t need to understand tool-specific JSON structures.

4. The System Prompt: Classification Protocol

The system prompt teaches the LLM how to classify processes into three labeled sections and how to respond to user actions. Here are the core classification criteria:
The system prompt also defines the action behavior protocol, including the multi-step quarantine confirmation:
Why A/B/C labels? They create a shared vocabulary between the LLM and the user. “Explain A3” unambiguously maps to the third process in the resource consumers section — no re-scanning required. Why explicit quarantine protocol? Quarantine is irreversible — it kills the process AND moves the executable file. The multi-step protocol (explain, confirm, wait for yes/no) prevents accidental data loss from an LLM hallucination.

5. ProcessConsole: Section-Aware Formatting

The ProcessConsole overrides CleanConsole::printFinalAnswer() to render the LLM’s structured A/B/C output with visual hierarchy. It applies six line detection rules in order (first match wins):
  1. Blank line — suppresses consecutive blanks to keep output tight
  2. Section header — “A. Processes”, “B. Services”, “C. Suspicious Items” — rendered as bold white label with a gray description line underneath
  3. Item referenceA4: cpptools-srv.exe — bold cyan tag, bold white name
  4. Key: Value — first colon within 20 chars with alpha key — bold white key, normal value
  5. Numbered item1. chrome.exe ... — normal rendering with markdown bold support
  6. Default paragraph — everything else — gray (dimmed) prose
Here’s how Rule 3 handles item reference lines:
Why override printFinalAnswer()? The LLM outputs structured sections that need visual hierarchy. Default CleanConsole treats all text equally — ProcessConsole adds section headers with descriptions, color-coded item tags, and Key: Value formatting that makes the output scannable at a glance.

6. Monitor Mode: Background Health Watcher

The monitor is a background thread that periodically re-scans the system and compares consecutive snapshots to detect changes. It runs alongside the interactive agent — you can keep explaining, stopping, or restarting processes while the monitor watches for anomalies. Starting and stopping. Monitor is a toggle on [6]. Press it once to start, again to stop. You can also specify an interval: 6 5 starts monitoring every 5 minutes. Typing monitor or monitor N at the prompt does the same thing. The default interval is 5 minutes. How it works internally. When started, the agent spawns a second ProcessAgent on a dedicated thread. This background agent uses a SilentConsole — it runs the same system_snapshot and list_processes tools but produces no visible output. After each scan it builds a MonitorSnapshot (memory usage, top process list, suspicious items, health status) and diffs it against the previous snapshot. Any meaningful changes become alerts. Alert types and thresholds: Alert delivery. Pending alerts are displayed before the next menu prompt, so you see them naturally between actions. For CRITICAL and NEW_SUSPICIOUS alerts, the agent also sends a Windows notification so you get alerted even if the terminal is in the background. Design choices:
  • Separate agent instance — the monitor’s ProcessAgent has its own conversation history and LLM connection. This avoids corrupting the interactive agent’s context with monitoring chatter.
  • SilentConsole — suppresses all tool output and conclusions from the background scan. Only the diff-based alerts reach the user.
  • Deterministic scans — the monitor agent uses temperature=0 for consistent health classifications across consecutive scans when system state hasn’t changed.
  • Toggle, not a mode — the interactive menu stays fully functional while the monitor runs. There is no “monitor mode” to enter or exit.
  • NPU-friendly — background monitoring is an ideal workload for AMD Ryzen AI NPU inference. The monitor runs periodic scans without tying up the CPU or GPU, leaving them free for your other work.

Tool Reference

The agent registers 7 tools in two categories:

Analysis Tools (Read-Only)

These gather information without changing anything on the system.

Action Tools (Destructive — require user confirmation)

These modify the system. The system prompt mandates user approval before the LLM calls any of them.

Diagnostics Flow

Diagnostic nodes (dark) gather data. Red nodes are destructive actions requiring confirmation. Blue nodes are the Reanalyze and Monitor paths. Orange is the alert display. Green nodes are conclusion displays where the user reads output.

Sample Session


Extending the Agent

Want to add your own tools? The pattern is straightforward. Here’s an example that lists Windows startup items:
The framework automatically appends registered tools to the system prompt — the new tool is available to the LLM immediately. Optionally, add an ActionEntry to kActions[] if you want a new numbered menu item (e.g., [7] Startup Items).

Next Steps

C++ Framework Overview

AgentConfig reference, project structure, and how the agent loop works

Customizing Your Agent

Custom prompts, typed tools, MCP servers, output capture, and tuning

Integration Guide

Use gaia_core in your own CMake project via FetchContent or find_package

Wi-Fi Troubleshooter Agent

Single-phase diagnostic agent with registered C++ tools