Vapora/docs/examples-guide.html
Jesús Pérez 7110ffeea2
Some checks failed
Rust CI / Security Audit (push) Has been cancelled
Rust CI / Check + Test + Lint (nightly) (push) Has been cancelled
Rust CI / Check + Test + Lint (stable) (push) Has been cancelled
chore: extend doc: adr, tutorials, operations, etc
2026-01-12 03:32:47 +00:00

941 lines
41 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML>
<html lang="en" class="light sidebar-visible" dir="ltr">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>Examples Guide - VAPORA Platform Documentation</title>
<!-- Custom HTML head -->
<meta name="description" content="Comprehensive documentation for VAPORA, an intelligent development orchestration platform built entirely in Rust.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff">
<link rel="icon" href="favicon.svg">
<link rel="shortcut icon" href="favicon.png">
<link rel="stylesheet" href="css/variables.css">
<link rel="stylesheet" href="css/general.css">
<link rel="stylesheet" href="css/chrome.css">
<link rel="stylesheet" href="css/print.css" media="print">
<!-- Fonts -->
<link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
<link rel="stylesheet" href="fonts/fonts.css">
<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" id="highlight-css" href="highlight.css">
<link rel="stylesheet" id="tomorrow-night-css" href="tomorrow-night.css">
<link rel="stylesheet" id="ayu-highlight-css" href="ayu-highlight.css">
<!-- Custom theme stylesheets -->
<!-- Provide site root and default themes to javascript -->
<script>
const path_to_root = "";
const default_light_theme = "light";
const default_dark_theme = "dark";
</script>
<!-- Start loading toc.js asap -->
<script src="toc.js"></script>
</head>
<body>
<div id="mdbook-help-container">
<div id="mdbook-help-popup">
<h2 class="mdbook-help-title">Keyboard shortcuts</h2>
<div>
<p>Press <kbd></kbd> or <kbd></kbd> to navigate between chapters</p>
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
<p>Press <kbd>?</kbd> to show this help</p>
<p>Press <kbd>Esc</kbd> to hide this help</p>
</div>
</div>
</div>
<div id="body-container">
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script>
try {
let theme = localStorage.getItem('mdbook-theme');
let sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') && theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
</script>
<!-- Set the theme before any content is loaded, prevents flash -->
<script>
const default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? default_dark_theme : default_light_theme;
let theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
const html = document.documentElement;
html.classList.remove('light')
html.classList.add(theme);
html.classList.add("js");
</script>
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
<!-- Hide / unhide sidebar before it is displayed -->
<script>
let sidebar = null;
const sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
} else {
sidebar = 'hidden';
}
sidebar_toggle.checked = sidebar === 'visible';
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
</script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<!-- populated by js -->
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
<noscript>
<iframe class="sidebar-iframe-outer" src="toc.html"></iframe>
</noscript>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>
<div id="page-wrapper" class="page-wrapper">
<div class="page">
<div id="menu-bar-hover-placeholder"></div>
<div id="menu-bar" class="menu-bar sticky">
<div class="left-buttons">
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i>
</label>
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
<i class="fa fa-paint-brush"></i>
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="default_theme">Auto</button></li>
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
</ul>
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
<i class="fa fa-search"></i>
</button>
</div>
<h1 class="menu-title">VAPORA Platform Documentation</h1>
<div class="right-buttons">
<a href="print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
</a>
<a href="https://github.com/vapora-platform/vapora" title="Git repository" aria-label="Git repository">
<i id="git-repository-button" class="fa fa-github"></i>
</a>
<a href="https://github.com/vapora-platform/vapora/edit/main/docs/src/../examples-guide.md" title="Suggest an edit" aria-label="Suggest an edit">
<i id="git-edit-button" class="fa fa-edit"></i>
</a>
</div>
</div>
<div id="search-wrapper" class="hidden">
<form id="searchbar-outer" class="searchbar-outer">
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
</form>
<div id="searchresults-outer" class="searchresults-outer hidden">
<div id="searchresults-header" class="searchresults-header"></div>
<ul id="searchresults">
</ul>
</div>
</div>
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
<script>
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
});
</script>
<div id="content" class="content">
<main>
<h1 id="vapora-examples-guide"><a class="header" href="#vapora-examples-guide">VAPORA Examples Guide</a></h1>
<p>Comprehensive guide to understanding and using VAPORA's example collection.</p>
<h2 id="overview"><a class="header" href="#overview">Overview</a></h2>
<p>VAPORA includes 26+ runnable examples demonstrating all major features:</p>
<ul>
<li><strong>6 Basic examples</strong> - Hello world for each component</li>
<li><strong>9 Intermediate examples</strong> - Multi-system integration patterns</li>
<li><strong>2 Advanced examples</strong> - End-to-end full-stack workflows</li>
<li><strong>3 Real-world examples</strong> - Production scenarios with ROI analysis</li>
<li><strong>4 Interactive notebooks</strong> - Marimo-based exploration (requires Python)</li>
</ul>
<p>Total time to explore all examples: <strong>2-3 hours</strong></p>
<h2 id="quick-start"><a class="header" href="#quick-start">Quick Start</a></h2>
<h3 id="run-your-first-example"><a class="header" href="#run-your-first-example">Run Your First Example</a></h3>
<pre><code class="language-bash"># Navigate to workspace root
cd /path/to/vapora
# Run basic agent example
cargo run --example 01-simple-agent -p vapora-agents
</code></pre>
<p>Expected output:</p>
<pre><code>=== Simple Agent Registration Example ===
Created agent registry with capacity 10
Defined agent: "Developer A" (role: developer)
Capabilities: ["coding", "testing"]
Agent registered successfully
Agent ID: &lt;uuid&gt;
</code></pre>
<h3 id="list-all-available-examples"><a class="header" href="#list-all-available-examples">List All Available Examples</a></h3>
<pre><code class="language-bash"># Per-crate examples
cargo build --examples -p vapora-agents
# All examples in workspace
cargo build --examples --workspace
</code></pre>
<h2 id="examples-by-category"><a class="header" href="#examples-by-category">Examples by Category</a></h2>
<h3 id="phase-1-basic-examples-foundation"><a class="header" href="#phase-1-basic-examples-foundation">Phase 1: Basic Examples (Foundation)</a></h3>
<p>Start here to understand individual components.</p>
<h4 id="agent-registry"><a class="header" href="#agent-registry">Agent Registry</a></h4>
<p><strong>File</strong>: <code>crates/vapora-agents/examples/01-simple-agent.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Creating an agent registry</li>
<li>Registering agents with metadata</li>
<li>Querying registered agents</li>
<li>Agent status management</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 01-simple-agent -p vapora-agents
</code></pre>
<p><strong>Key concepts</strong>:</p>
<ul>
<li><code>AgentRegistry</code> - thread-safe registry with capacity limits</li>
<li><code>AgentMetadata</code> - agent name, role, capabilities, LLM provider</li>
<li><code>AgentStatus</code> - Active, Busy, Offline</li>
</ul>
<p><strong>Time</strong>: 5-10 minutes</p>
<hr />
<h4 id="llm-provider-selection"><a class="header" href="#llm-provider-selection">LLM Provider Selection</a></h4>
<p><strong>File</strong>: <code>crates/vapora-llm-router/examples/01-provider-selection.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Available LLM providers (Claude, GPT-4, Gemini, Ollama)</li>
<li>Provider pricing and use cases</li>
<li>Routing rules by task type</li>
<li>Cost comparison</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 01-provider-selection -p vapora-llm-router
</code></pre>
<p><strong>Key concepts</strong>:</p>
<ul>
<li>Provider routing rules</li>
<li>Cost per 1M tokens</li>
<li>Fallback strategy</li>
<li>Task type matching</li>
</ul>
<p><strong>Time</strong>: 5-10 minutes</p>
<hr />
<h4 id="swarm-coordination"><a class="header" href="#swarm-coordination">Swarm Coordination</a></h4>
<p><strong>File</strong>: <code>crates/vapora-swarm/examples/01-agent-registration.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Swarm coordinator creation</li>
<li>Agent registration with capabilities</li>
<li>Swarm statistics</li>
<li>Load balancing basics</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 01-agent-registration -p vapora-swarm
</code></pre>
<p><strong>Key concepts</strong>:</p>
<ul>
<li><code>SwarmCoordinator</code> - manages agent pool</li>
<li>Agent capabilities filtering</li>
<li>Load distribution calculation</li>
<li><code>success_rate / (1 + current_load)</code> scoring</li>
</ul>
<p><strong>Time</strong>: 5-10 minutes</p>
<hr />
<h4 id="knowledge-graph"><a class="header" href="#knowledge-graph">Knowledge Graph</a></h4>
<p><strong>File</strong>: <code>crates/vapora-knowledge-graph/examples/01-execution-tracking.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Recording execution history</li>
<li>Querying executions by agent/task type</li>
<li>Cost analysis per provider</li>
<li>Success rate calculations</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 01-execution-tracking -p vapora-knowledge-graph
</code></pre>
<p><strong>Key concepts</strong>:</p>
<ul>
<li><code>ExecutionRecord</code> - timestamp, duration, success, cost</li>
<li>Temporal queries (last 7/14/30 days)</li>
<li>Provider cost breakdown</li>
<li>Success rate trends</li>
</ul>
<p><strong>Time</strong>: 5-10 minutes</p>
<hr />
<h4 id="backend-health-check"><a class="header" href="#backend-health-check">Backend Health Check</a></h4>
<p><strong>File</strong>: <code>crates/vapora-backend/examples/01-health-check.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Backend service health status</li>
<li>Dependency verification</li>
<li>Monitoring endpoints</li>
<li>Troubleshooting guide</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 01-health-check -p vapora-backend
</code></pre>
<p><strong>Prerequisites</strong>:</p>
<ul>
<li>Backend running: <code>cd crates/vapora-backend &amp;&amp; cargo run</code></li>
<li>SurrealDB running: <code>docker run -d surrealdb/surrealdb:latest</code></li>
</ul>
<p><strong>Key concepts</strong>:</p>
<ul>
<li>Health endpoint status</li>
<li>Dependency checklist</li>
<li>Prometheus metrics endpoint</li>
<li>Startup verification</li>
</ul>
<p><strong>Time</strong>: 5-10 minutes</p>
<hr />
<h4 id="error-handling"><a class="header" href="#error-handling">Error Handling</a></h4>
<p><strong>File</strong>: <code>crates/vapora-shared/examples/01-error-handling.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Custom error types</li>
<li>Error propagation with <code>?</code></li>
<li>Error context</li>
<li>Display and Debug implementations</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 01-error-handling -p vapora-shared
</code></pre>
<p><strong>Key concepts</strong>:</p>
<ul>
<li><code>Result&lt;T&gt;</code> pattern</li>
<li>Error types (InvalidInput, NotFound, Unauthorized)</li>
<li>Error chaining</li>
<li>User-friendly messages</li>
</ul>
<p><strong>Time</strong>: 5-10 minutes</p>
<hr />
<h3 id="phase-2-intermediate-examples-integration"><a class="header" href="#phase-2-intermediate-examples-integration">Phase 2: Intermediate Examples (Integration)</a></h3>
<p>Combine 2-3 systems to solve realistic problems.</p>
<h4 id="learning-profiles"><a class="header" href="#learning-profiles">Learning Profiles</a></h4>
<p><strong>File</strong>: <code>crates/vapora-agents/examples/02-learning-profile.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Building expertise profiles from execution history</li>
<li>Recency bias weighting (recent 7 days weighted 3× higher)</li>
<li>Confidence scaling based on sample size</li>
<li>Task type specialization</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 02-learning-profile -p vapora-agents
</code></pre>
<p><strong>Key metrics</strong>:</p>
<ul>
<li>Success rate: percentage of successful executions</li>
<li>Confidence: increases with sample size (0-1.0)</li>
<li>Recent trend: last 7 days weighted heavily</li>
<li>Task type expertise: separate profiles per task type</li>
</ul>
<p><strong>Real scenario</strong>:
Agent Alice has 93.3% success rate on coding (28/30 executions over 30 days), with confidence 1.0 from ample data.</p>
<p><strong>Time</strong>: 10-15 minutes</p>
<hr />
<h4 id="agent-selection-scoring"><a class="header" href="#agent-selection-scoring">Agent Selection Scoring</a></h4>
<p><strong>File</strong>: <code>crates/vapora-agents/examples/03-agent-selection.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Ranking agents for task assignment</li>
<li>Scoring formula: <code>(1 - 0.3*load) + 0.5*expertise + 0.2*confidence</code></li>
<li>Load balancing prevents over-allocation</li>
<li>Why confidence matters</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 03-agent-selection -p vapora-agents
</code></pre>
<p><strong>Scoring breakdown</strong>:</p>
<ul>
<li>Availability: <code>1 - (0.3 * current_load)</code> - lower load = higher score</li>
<li>Expertise: <code>0.5 * success_rate</code> - proven capability</li>
<li>Confidence: <code>0.2 * confidence</code> - trust the data</li>
</ul>
<p><strong>Real scenario</strong>:
Three agents competing for coding task:</p>
<ul>
<li>Alice: 0.92 expertise, 30% load → score 0.71</li>
<li>Bob: 0.78 expertise, 10% load → score 0.77 (selected despite lower expertise)</li>
<li>Carol: 0.88 expertise, 50% load → score 0.59</li>
</ul>
<p><strong>Time</strong>: 10-15 minutes</p>
<hr />
<h4 id="budget-enforcement"><a class="header" href="#budget-enforcement">Budget Enforcement</a></h4>
<p><strong>File</strong>: <code>crates/vapora-llm-router/examples/02-budget-enforcement.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Per-role budget limits (monthly/weekly)</li>
<li>Three-tier enforcement: Normal → Caution → Exceeded</li>
<li>Automatic fallback to cheaper providers</li>
<li>Alert thresholds</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 02-budget-enforcement -p vapora-llm-router
</code></pre>
<p><strong>Budget tiers</strong>:</p>
<ul>
<li><strong>0-50%</strong>: Normal - use preferred provider (Claude)</li>
<li><strong>50-80%</strong>: Caution - monitor spending closely</li>
<li><strong>80-100%</strong>: Near threshold - use cheaper alternative (GPT-4)</li>
<li><strong>100%+</strong>: Exceeded - use fallback only (Ollama)</li>
</ul>
<p><strong>Real scenario</strong>:
Developer role with $300/month budget:</p>
<ul>
<li>Spend $145 (48% used) - in Normal tier</li>
<li>All tasks use Claude (highest quality)</li>
<li>If reaches $240+ (80%), automatically switch to cheaper providers</li>
</ul>
<p><strong>Time</strong>: 10-15 minutes</p>
<hr />
<h4 id="cost-tracking"><a class="header" href="#cost-tracking">Cost Tracking</a></h4>
<p><strong>File</strong>: <code>crates/vapora-llm-router/examples/03-cost-tracking.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Token usage recording per provider</li>
<li>Cost calculation by provider and task type</li>
<li>Report generation</li>
<li>Cost per 1M tokens analysis</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 03-cost-tracking -p vapora-llm-router
</code></pre>
<p><strong>Report includes</strong>:</p>
<ul>
<li>Total cost (cents or dollars)</li>
<li>Cost by provider (Claude, GPT-4, Gemini, Ollama)</li>
<li>Cost by task type (coding, testing, documentation)</li>
<li>Average cost per task</li>
<li>Cost efficiency (tokens per dollar)</li>
</ul>
<p><strong>Real scenario</strong>:
4 tasks processed:</p>
<ul>
<li>Claude (2 tasks): 3,500 tokens → $0.067</li>
<li>GPT-4 (1 task): 4,500 tokens → $0.130</li>
<li>Gemini (1 task): 4,500 tokens → $0.053</li>
<li>Total: $0.250</li>
</ul>
<p><strong>Time</strong>: 10-15 minutes</p>
<hr />
<h4 id="task-assignment"><a class="header" href="#task-assignment">Task Assignment</a></h4>
<p><strong>File</strong>: <code>crates/vapora-swarm/examples/02-task-assignment.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Submitting tasks to swarm</li>
<li>Load-balanced agent selection</li>
<li>Capability filtering</li>
<li>Swarm statistics</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 02-task-assignment -p vapora-swarm
</code></pre>
<p><strong>Assignment algorithm</strong>:</p>
<ol>
<li>Filter agents by required capabilities</li>
<li>Score each agent: <code>success_rate / (1 + current_load)</code></li>
<li>Assign to highest-scoring agent</li>
<li>Update swarm statistics</li>
</ol>
<p><strong>Real scenario</strong>:
Coding task submitted to swarm with 3 agents:</p>
<ul>
<li>agent-1: coding ✓, load 20%, success 92% → score 0.77</li>
<li>agent-2: coding ✓, load 10%, success 85% → score 0.77 (selected, lower load)</li>
<li>agent-3: code_review only ✗ (filtered out)</li>
</ul>
<p><strong>Time</strong>: 10-15 minutes</p>
<hr />
<h4 id="learning-curves"><a class="header" href="#learning-curves">Learning Curves</a></h4>
<p><strong>File</strong>: <code>crates/vapora-knowledge-graph/examples/02-learning-curves.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Computing learning curves from daily data</li>
<li>Success rate trends over 30 days</li>
<li>Recency bias impact</li>
<li>Performance trend analysis</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 02-learning-curves -p vapora-knowledge-graph
</code></pre>
<p><strong>Metrics tracked</strong>:</p>
<ul>
<li>Daily success rate (0-100%)</li>
<li>Average execution time (milliseconds)</li>
<li>Recent 7-day success rate</li>
<li>Recent 14-day success rate</li>
<li>Weighted score with recency bias</li>
</ul>
<p><strong>Trend indicators</strong>:</p>
<ul>
<li>✓ IMPROVING: Agent learning over time</li>
<li>→ STABLE: Consistent performance</li>
<li>✗ DECLINING: Possible issues or degradation</li>
</ul>
<p><strong>Real scenario</strong>:
Agent bob over 30 days:</p>
<ul>
<li>Days 1-15: 70% success rate, 300ms/execution</li>
<li>Days 16-30: 70% success rate, 300ms/execution</li>
<li>Weighted score: 72% (no improvement detected)</li>
<li>Trend: STABLE (consistent but not improving)</li>
</ul>
<p><strong>Time</strong>: 10-15 minutes</p>
<hr />
<h4 id="similarity-search"><a class="header" href="#similarity-search">Similarity Search</a></h4>
<p><strong>File</strong>: <code>crates/vapora-knowledge-graph/examples/03-similarity-search.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Semantic similarity matching</li>
<li>Jaccard similarity scoring</li>
<li>Recommendation generation</li>
<li>Pattern recognition</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">cargo run --example 03-similarity-search -p vapora-knowledge-graph
</code></pre>
<p><strong>Similarity calculation</strong>:</p>
<ul>
<li>Input: New task description ("Implement API key authentication")</li>
<li>Compare: Against past execution descriptions</li>
<li>Score: Jaccard similarity (intersection / union of keywords)</li>
<li>Rank: Sort by similarity score</li>
</ul>
<p><strong>Real scenario</strong>:
New task: "Implement API key authentication for third-party services"
Keywords: ["authentication", "API", "third-party"]</p>
<p>Matches against past tasks:</p>
<ol>
<li>"Implement user authentication with JWT" (87% similarity)</li>
<li>"Implement token refresh mechanism" (81% similarity)</li>
<li>"Add API rate limiting" (79% similarity)</li>
</ol>
<p>→ Recommend: "Use OAuth2 + API keys with rotation strategy"</p>
<p><strong>Time</strong>: 10-15 minutes</p>
<hr />
<h3 id="phase-3-advanced-examples-full-stack"><a class="header" href="#phase-3-advanced-examples-full-stack">Phase 3: Advanced Examples (Full-Stack)</a></h3>
<p>End-to-end integration of all systems.</p>
<h4 id="agent-with-llm-routing"><a class="header" href="#agent-with-llm-routing">Agent with LLM Routing</a></h4>
<p><strong>File</strong>: <code>examples/full-stack/01-agent-with-routing.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Agent executes task with intelligent provider selection</li>
<li>Budget checking before execution</li>
<li>Cost tracking during execution</li>
<li>Provider fallback strategy</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">rustc examples/full-stack/01-agent-with-routing.rs -o /tmp/example &amp;&amp; /tmp/example
</code></pre>
<p><strong>Workflow</strong>:</p>
<ol>
<li>Initialize agent (developer-001)</li>
<li>Set task (implement authentication, 1,500 input + 800 output tokens)</li>
<li>Check budget ($250 remaining)</li>
<li>Select provider (Claude for quality)</li>
<li>Execute task</li>
<li>Track costs ($0.069 total)</li>
<li>Update learning profile</li>
</ol>
<p><strong>Time</strong>: 15-20 minutes</p>
<hr />
<h4 id="swarm-with-learning-profiles"><a class="header" href="#swarm-with-learning-profiles">Swarm with Learning Profiles</a></h4>
<p><strong>File</strong>: <code>examples/full-stack/02-swarm-with-learning.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Swarm coordinates agents with learning profiles</li>
<li>Task assignment based on expertise</li>
<li>Load balancing with learned preferences</li>
<li>Profile updates after execution</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">rustc examples/full-stack/02-swarm-with-learning.rs -o /tmp/example &amp;&amp; /tmp/example
</code></pre>
<p><strong>Workflow</strong>:</p>
<ol>
<li>Register agents with learning profiles
<ul>
<li>alice: 92% coding, 60% testing, 30% load</li>
<li>bob: 78% coding, 85% testing, 10% load</li>
<li>carol: 90% documentation, 75% testing, 20% load</li>
</ul>
</li>
<li>Submit tasks (3 different types)</li>
<li>Swarm assigns based on expertise + load</li>
<li>Execute tasks</li>
<li>Update learning profiles with results</li>
<li>Verify assignments improved for next round</li>
</ol>
<p><strong>Time</strong>: 15-20 minutes</p>
<hr />
<h3 id="phase-5-real-world-examples"><a class="header" href="#phase-5-real-world-examples">Phase 5: Real-World Examples</a></h3>
<p>Production scenarios with business value analysis.</p>
<h4 id="code-review-pipeline"><a class="header" href="#code-review-pipeline">Code Review Pipeline</a></h4>
<p><strong>File</strong>: <code>examples/real-world/01-code-review-workflow.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Multi-agent code review workflow</li>
<li>Cost optimization with tiered providers</li>
<li>Quality vs cost trade-off</li>
<li>Business metrics (ROI, time savings)</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">rustc examples/real-world/01-code-review-workflow.rs -o /tmp/example &amp;&amp; /tmp/example
</code></pre>
<p><strong>Three-stage pipeline</strong>:</p>
<p><strong>Stage 1</strong> (Ollama - FREE):</p>
<ul>
<li>Static analysis, linting</li>
<li>Dead code detection</li>
<li>Security rule violations</li>
<li>Cost: $0.00/PR, Time: 5s</li>
</ul>
<p><strong>Stage 2</strong> (GPT-4 - $10/1M):</p>
<ul>
<li>Logic verification</li>
<li>Test coverage analysis</li>
<li>Performance implications</li>
<li>Cost: $0.08/PR, Time: 15s</li>
</ul>
<p><strong>Stage 3</strong> (Claude - $15/1M, 10% of PRs):</p>
<ul>
<li>Architecture validation</li>
<li>Design pattern verification</li>
<li>Triggered for risky changes</li>
<li>Cost: $0.20/PR, Time: 30s</li>
</ul>
<p><strong>Business impact</strong>:</p>
<ul>
<li>Volume: 50 PRs/day</li>
<li>Cost: $0.60/day ($12/month)</li>
<li>vs Manual: 40+ hours/month ($500+)</li>
<li><strong>Savings: $488/month</strong></li>
<li>Quality: 99%+ accuracy</li>
</ul>
<p><strong>Time</strong>: 15-20 minutes</p>
<hr />
<h4 id="documentation-generation"><a class="header" href="#documentation-generation">Documentation Generation</a></h4>
<p><strong>File</strong>: <code>examples/real-world/02-documentation-generation.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Automated doc generation from code</li>
<li>Multi-stage pipeline (analyze → write → check)</li>
<li>Cost optimization</li>
<li>Keeping docs in sync with code</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">rustc examples/real-world/02-documentation-generation.rs -o /tmp/example &amp;&amp; /tmp/example
</code></pre>
<p><strong>Pipeline</strong>:</p>
<p><strong>Phase 1</strong> (Ollama - FREE):</p>
<ul>
<li>Parse source files</li>
<li>Extract API endpoints, types</li>
<li>Identify breaking changes</li>
<li>Cost: $0.00, Time: 2min for 10k LOC</li>
</ul>
<p><strong>Phase 2</strong> (Claude - $15/1M):</p>
<ul>
<li>Generate descriptions</li>
<li>Create examples</li>
<li>Document parameters</li>
<li>Cost: $0.40/endpoint, Time: 30s</li>
</ul>
<p><strong>Phase 3</strong> (GPT-4 - $10/1M):</p>
<ul>
<li>Verify accuracy vs code</li>
<li>Check completeness</li>
<li>Ensure clarity</li>
<li>Cost: $0.15/doc, Time: 15s</li>
</ul>
<p><strong>Business impact</strong>:</p>
<ul>
<li>Docs in sync instantly (vs 2 week lag)</li>
<li>Per-endpoint cost: $0.55</li>
<li>Monthly cost: ~$11 (vs $1000+ manual)</li>
<li><strong>Savings: $989/month</strong></li>
<li>Quality: 99%+ accuracy</li>
</ul>
<p><strong>Time</strong>: 15-20 minutes</p>
<hr />
<h4 id="issue-triage"><a class="header" href="#issue-triage">Issue Triage</a></h4>
<p><strong>File</strong>: <code>examples/real-world/03-issue-triage.rs</code></p>
<p><strong>What it demonstrates</strong>:</p>
<ul>
<li>Intelligent issue classification</li>
<li>Two-stage escalation pipeline</li>
<li>Cost optimization</li>
<li>Consistent routing rules</li>
</ul>
<p><strong>Run</strong>:</p>
<pre><code class="language-bash">rustc examples/real-world/03-issue-triage.rs -o /tmp/example &amp;&amp; /tmp/example
</code></pre>
<p><strong>Two-stage pipeline</strong>:</p>
<p><strong>Stage 1</strong> (Ollama - FREE, 85% accuracy):</p>
<ul>
<li>Classify issue type (bug, feature, docs, support)</li>
<li>Extract component, priority</li>
<li>Route to team</li>
<li>Cost: $0.00/issue, Time: 2s</li>
</ul>
<p><strong>Stage 2</strong> (Claude - $15/1M, 15% of issues):</p>
<ul>
<li>Detailed analysis for unclear issues</li>
<li>Extract root cause</li>
<li>Create investigation</li>
<li>Cost: $0.05/issue, Time: 10s</li>
</ul>
<p><strong>Business impact</strong>:</p>
<ul>
<li>Volume: 200 issues/month</li>
<li>Stage 1: 170 issues × $0.00 = $0.00</li>
<li>Stage 2: 30 issues × $0.08 = $2.40</li>
<li>Manual triage: 20 hours × $50 = $1,000</li>
<li><strong>Savings: $997.60/month</strong></li>
<li>Speed: Seconds vs hours</li>
</ul>
<p><strong>Time</strong>: 15-20 minutes</p>
<hr />
<h2 id="learning-paths"><a class="header" href="#learning-paths">Learning Paths</a></h2>
<h3 id="path-1-quick-overview-30-minutes"><a class="header" href="#path-1-quick-overview-30-minutes">Path 1: Quick Overview (30 minutes)</a></h3>
<ol>
<li>Run <code>01-simple-agent</code> (agent basics)</li>
<li>Run <code>01-provider-selection</code> (LLM routing)</li>
<li>Run <code>01-error-handling</code> (error patterns)</li>
</ol>
<p><strong>Takeaway</strong>: Understand basic components</p>
<hr />
<h3 id="path-2-system-integration-90-minutes"><a class="header" href="#path-2-system-integration-90-minutes">Path 2: System Integration (90 minutes)</a></h3>
<ol>
<li>Run all Phase 1 examples (30 min)</li>
<li>Run <code>02-learning-profile</code> + <code>03-agent-selection</code> (20 min)</li>
<li>Run <code>02-budget-enforcement</code> + <code>03-cost-tracking</code> (20 min)</li>
<li>Run <code>02-task-assignment</code> + <code>02-learning-curves</code> (20 min)</li>
</ol>
<p><strong>Takeaway</strong>: Understand component interactions</p>
<hr />
<h3 id="path-3-production-ready-2-3-hours"><a class="header" href="#path-3-production-ready-2-3-hours">Path 3: Production Ready (2-3 hours)</a></h3>
<ol>
<li>Complete Path 2 (90 min)</li>
<li>Run Phase 5 real-world examples (45 min)</li>
<li>Study <code>docs/tutorials/</code> (30-45 min)</li>
</ol>
<p><strong>Takeaway</strong>: Ready to implement VAPORA in production</p>
<hr />
<h2 id="common-tasks"><a class="header" href="#common-tasks">Common Tasks</a></h2>
<h3 id="i-want-to-understand-agent-learning"><a class="header" href="#i-want-to-understand-agent-learning">I want to understand agent learning</a></h3>
<p><strong>Read</strong>: <code>docs/tutorials/04-learning-profiles.md</code></p>
<p><strong>Run examples</strong> (in order):</p>
<ol>
<li><code>02-learning-profile</code> - See expertise calculation</li>
<li><code>03-agent-selection</code> - See scoring in action</li>
<li><code>02-learning-curves</code> - See trends over time</li>
</ol>
<p><strong>Time</strong>: 30-40 minutes</p>
<hr />
<h3 id="i-want-to-understand-cost-control"><a class="header" href="#i-want-to-understand-cost-control">I want to understand cost control</a></h3>
<p><strong>Read</strong>: <code>docs/tutorials/05-budget-management.md</code></p>
<p><strong>Run examples</strong> (in order):</p>
<ol>
<li><code>01-provider-selection</code> - See provider pricing</li>
<li><code>02-budget-enforcement</code> - See budget tiers</li>
<li><code>03-cost-tracking</code> - See detailed reports</li>
</ol>
<p><strong>Time</strong>: 25-35 minutes</p>
<hr />
<h3 id="i-want-to-understand-multi-agent-workflows"><a class="header" href="#i-want-to-understand-multi-agent-workflows">I want to understand multi-agent workflows</a></h3>
<p><strong>Read</strong>: <code>docs/tutorials/06-swarm-coordination.md</code></p>
<p><strong>Run examples</strong> (in order):</p>
<ol>
<li><code>01-agent-registration</code> - See swarm setup</li>
<li><code>02-task-assignment</code> - See task routing</li>
<li><code>02-swarm-with-learning</code> - See full workflow</li>
</ol>
<p><strong>Time</strong>: 30-40 minutes</p>
<hr />
<h3 id="i-want-to-see-business-value"><a class="header" href="#i-want-to-see-business-value">I want to see business value</a></h3>
<p><strong>Run examples</strong> (real-world):</p>
<ol>
<li><code>01-code-review-workflow</code> - $488/month savings</li>
<li><code>02-documentation-generation</code> - $989/month savings</li>
<li><code>03-issue-triage</code> - $997/month savings</li>
</ol>
<p><strong>Takeaway</strong>: VAPORA saves $2,474/month for typical usage</p>
<p><strong>Time</strong>: 40-50 minutes</p>
<hr />
<h2 id="running-examples-with-parameters"><a class="header" href="#running-examples-with-parameters">Running Examples with Parameters</a></h2>
<p>Some examples support command-line arguments:</p>
<pre><code class="language-bash"># Budget enforcement with custom budget
cargo run --example 02-budget-enforcement -p vapora-llm-router -- \
--monthly-budget 50000 --verbose
# Learning profile with custom sample size
cargo run --example 02-learning-profile -p vapora-agents -- \
--sample-size 100
</code></pre>
<p>Check example documentation for available options:</p>
<pre><code class="language-bash"># View example header
head -20 crates/vapora-agents/examples/02-learning-profile.rs
</code></pre>
<hr />
<h2 id="troubleshooting"><a class="header" href="#troubleshooting">Troubleshooting</a></h2>
<h3 id="example-not-found"><a class="header" href="#example-not-found">"example not found"</a></h3>
<p>Ensure you're running from workspace root:</p>
<pre><code class="language-bash">cd /path/to/vapora
cargo run --example 01-simple-agent -p vapora-agents
</code></pre>
<hr />
<h3 id="cannot-find-module"><a class="header" href="#cannot-find-module">"Cannot find module"</a></h3>
<p>Ensure workspace is synced:</p>
<pre><code class="language-bash">cargo update
cargo build --examples --workspace
</code></pre>
<hr />
<h3 id="example-fails-at-runtime"><a class="header" href="#example-fails-at-runtime">Example fails at runtime</a></h3>
<p>Check prerequisites:</p>
<p><strong>Backend examples</strong> require:</p>
<pre><code class="language-bash"># Terminal 1: Start SurrealDB
docker run -d -p 8000:8000 surrealdb/surrealdb:latest
# Terminal 2: Start backend
cd crates/vapora-backend &amp;&amp; cargo run
# Terminal 3: Run example
cargo run --example 01-health-check -p vapora-backend
</code></pre>
<hr />
<h3 id="want-verbose-output"><a class="header" href="#want-verbose-output">Want verbose output</a></h3>
<p>Set logging:</p>
<pre><code class="language-bash">RUST_LOG=debug cargo run --example 02-learning-profile -p vapora-agents
</code></pre>
<hr />
<h2 id="next-steps"><a class="header" href="#next-steps">Next Steps</a></h2>
<p>After exploring examples:</p>
<ol>
<li><strong>Read tutorials</strong>: <code>docs/tutorials/README.md</code> - step-by-step guides</li>
<li><strong>Study code snippets</strong>: <code>docs/examples/</code> - quick reference</li>
<li><strong>Explore source</strong>: <code>crates/*/src/</code> - understand implementations</li>
<li><strong>Run tests</strong>: <code>cargo test --workspace</code> - verify functionality</li>
<li><strong>Build projects</strong>: Create your first VAPORA integration</li>
</ol>
<hr />
<h2 id="quick-reference"><a class="header" href="#quick-reference">Quick Reference</a></h2>
<h3 id="build-all-examples"><a class="header" href="#build-all-examples">Build all examples</a></h3>
<pre><code class="language-bash">cargo build --examples --workspace
</code></pre>
<h3 id="run-specific-example"><a class="header" href="#run-specific-example">Run specific example</a></h3>
<pre><code class="language-bash">cargo run --example &lt;name&gt; -p &lt;crate&gt;
</code></pre>
<h3 id="clean-build-artifacts"><a class="header" href="#clean-build-artifacts">Clean build artifacts</a></h3>
<pre><code class="language-bash">cargo clean
cargo build --examples
</code></pre>
<h3 id="list-examples-in-crate"><a class="header" href="#list-examples-in-crate">List examples in crate</a></h3>
<pre><code class="language-bash">ls -la crates/&lt;crate&gt;/examples/
</code></pre>
<h3 id="view-example-documentation"><a class="header" href="#view-example-documentation">View example documentation</a></h3>
<pre><code class="language-bash">head -30 crates/&lt;crate&gt;/examples/&lt;name&gt;.rs
</code></pre>
<h3 id="run-with-output"><a class="header" href="#run-with-output">Run with output</a></h3>
<pre><code class="language-bash">cargo run --example &lt;name&gt; -- 2&gt;&amp;1 | tee output.log
</code></pre>
<hr />
<h2 id="resources"><a class="header" href="#resources">Resources</a></h2>
<ul>
<li><strong>Main docs</strong>: See <code>docs/</code> directory</li>
<li><strong>Tutorial path</strong>: <code>docs/tutorials/README.md</code></li>
<li><strong>Code snippets</strong>: <code>docs/examples/</code></li>
<li><strong>API documentation</strong>: <code>cargo doc --open</code></li>
<li><strong>Project examples</strong>: <code>examples/</code> directory</li>
</ul>
<hr />
<p><strong>Total examples</strong>: 23 Rust + 4 Marimo notebooks</p>
<p><strong>Estimated learning time</strong>: 2-3 hours for complete understanding</p>
<p><strong>Next</strong>: Start with Path 1 (Quick Overview) →</p>
</main>
<nav class="nav-wrapper" aria-label="Page navigation">
<!-- Mobile navigation buttons -->
<a rel="prev" href="../integrations/provisioning-integration.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../tutorials/index.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
<div style="clear: both"></div>
</nav>
</div>
</div>
<nav class="nav-wide-wrapper" aria-label="Page navigation">
<a rel="prev" href="../integrations/provisioning-integration.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../tutorials/index.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
</nav>
</div>
<script>
window.playground_copyable = true;
</script>
<script src="elasticlunr.min.js"></script>
<script src="mark.min.js"></script>
<script src="searcher.js"></script>
<script src="clipboard.min.js"></script>
<script src="highlight.js"></script>
<script src="book.js"></script>
<!-- Custom JS scripts -->
</div>
</body>
</html>