Index
SAM AI
The AI All-Knowing Intelligence Framework for Odoo 18
What is SAM AI?
SAM AI is a comprehensive intelligent framework for Odoo 18 that combines AI-powered conversations, visual workflow automation, knowledge graph memory, and multi-user relationship management into a unified, extensible platform.
Three-Layer Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ฟ PLATFORMS (Specialized Features) โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ SAM โ โ Memory โ โ Automator โ โ
โ โ Creative โ โ System โ โ (Workflows) โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ง AI_SAM (Framework - Core Intelligence) โ
โ โข Canvas Engine (Universal Platform) โ
โ โข Claude API Integration โ
โ โข Context Builder (All-Knowing Brain) โ
โ โข Controllers & APIs โ
โ โข Token Counter & Cost Tracking โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐พ AI_BRAIN (Data Layer - Foundation) โ
โ โข All Data Models (40+) โ
โ โข Conversation Storage โ
โ โข User Profiles โ
โ โข Workflow Definitions โ
โ โข Node Registry โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Core Features
๐ค AI Chat Interface
Context-aware conversations with Claude AI, integrated throughout Odoo. SAM knows everything about your system and adapts to each user's relationship level.
๐ฅ Multi-User Profiles
Relationship-based AI interactions that evolve from stranger to close friend. Trust scores, learned preferences, and personal facts for each user.
๐จ Universal Canvas
Polymorphic workflow/mind-map platform. ONE canvas core supporting MANY platform skins (SAM Creative, Automator, Memory, custom).
๐พ Memory System
Graph database (Apache AGE) + Vector database (ChromaDB) for knowledge storage, semantic search, and intelligent context retrieval.
๐ Workflow Automation
Node-based workflows with 1,500+ service connectors. Visual workflow builder with execution tracking and N8N JSON import/export.
๐ฏ Power Prompts
Context-aware AI modes (dev, sales, marketing, support) that inject specialized capabilities based on user needs.
Technology Stack
Cost Optimization Intelligence System
SAM AI now includes a powerful Cost Optimization Intelligence System that automatically reduces your AI API costs by up to 43% through smart provider selection, waste detection, A/B testing, and budget management.
How It Works
๐ฏ Smart Provider Selection
ai.cost.optimizer recommends the best AI provider based on:
- Task complexity & context size
- Quality requirements (low/medium/high)
- Historical performance data
- Cost-per-quality ratio
- Your budget constraints
Example:
Simple query โ Claude Haiku ($0.008) vs Complex analysis โ Claude Sonnet 4 ($0.045)
๐ Waste Detection
ai.token.analytics analyzes every API call for waste:
- Redundant Context (unused models/fields)
- Oversized Context (>2x message size)
- Duplicate Queries (same prompt repeatedly)
- Wrong Model (expensive model for simple task)
- Unnecessary History (unused conversation)
Savings Identified:
$0.05 per call ร 300 calls = $15/month saved!
๐งช A/B Testing
ai.provider.benchmark compares providers scientifically:
- 80% control / 20% challenger split
- Tracks cost, quality, speed, reliability
- Statistical analysis after 7 days
- Automatic switching recommendations
- Quality protection (no quality loss)
Example Result:
Haiku: $0.008 @ 75 quality vs Sonnet: $0.045 @ 90 quality โ 5x cheaper!
๐ Budget Management
ai.cost.budget prevents overspending:
- Daily, Weekly, Monthly budgets
- Alerts at 50%, 75%, 90%, 100%
- Auto-switch to cheaper providers at 90%
- Spending forecasts (predict monthly cost)
- Optional hard limit at 100%
Alert Example:
"Budget 75% used. Forecast: $105/month (over $100 budget)"
Getting Started
Step 1: Set Up a Budget
block_at_threshold: False to observe spending patterns
without disrupting service. Enable blocking later if needed.
Step 2: Review Cost Breakdown
Step 3: Compare Providers
Step 4: Get Savings Recommendations
Common Use Cases
Use Case 1: Monthly Budget with Auto-Switching
- Create Monthly Budget: Set $100/month limit with alerts at 50%, 75%, 90%, 100%
- Enable Auto-Switch: At 90% budget, automatically recommend switching to Claude Haiku
- Monitor Alerts: Receive email notifications with cost breakdown and optimization tips
- Review Monthly: At month end, review cost report and adjust budget for next period
Use Case 2: A/B Test New Provider
- Start A/B Test: System automatically uses 80% Claude Sonnet 4 (control), 20% Claude Haiku (challenger)
- Wait 7 Days: Let the system collect performance data (cost, quality, speed)
-
Analyze Results: Run
analyze_ab_test()to see if Haiku saves money without quality loss - Make Decision: If Haiku is 5x cheaper with only 15-point quality drop, consider switching for simple queries
Use Case 3: Detect and Fix Waste
- Review Token Usage: Check recent API calls for waste detection flags
-
Identify Waste: Find calls with
waste_detected=Trueand reviewwaste_reason - Apply Fix: Enable context caching, reduce context size, or deduplicate queries
-
Measure Impact: Compare
could_have_saved_usdbefore and after fix
What Happens Automatically
Before API Call
- Checks active budget
- Estimates cost
- Warns if over threshold
- Recommends cheaper provider if at 90%
- Blocks if budget exhausted (optional)
After API Call
- Logs benchmark data (cost, quality, speed)
- Analyzes for waste (5 detection rules)
- Updates provider comparison stats
- Increments budget spend
- Sends alerts if threshold reached
Expected Savings Breakdown
BASELINE MONTHLY COST: $150/month (without optimization)
AFTER COST OPTIMIZATION:
Phase 1: Smart Provider Selection -$30/month (20% savings)
โข Context-aware model selection
โข Budget-aware routing
โข Quality vs cost tradeoffs
Phase 2: Provider Benchmarking -$20/month (13% savings)
โข A/B testing finds better alternatives
โข Quality scoring prevents bad switches
โข Performance tracking
Phase 3: Budget Management -$15/month (10% savings)
โข Alerts prevent overspending
โข Auto-switching at threshold
โข Waste elimination awareness
TOTAL SAVINGS: -$65/month (43% reduction!)
NEW MONTHLY COST: $85/month
ANNUAL SAVINGS: $780/year
Troubleshooting
Budget Not Checking
Solution: Verify budget is active (
active=True) and dates are correct (start_date โค today โค end_date)
Waste Not Detected
Solution: Manually run
usage_record.analyze_waste() on existing records. Waste detection runs on-demand, not automatically.
Provider Comparison Empty
compare_providers() returns empty listSolution: Wait until benchmark data exists (generated after API calls). Minimum 5-10 API calls needed for comparison.
Budget Alerts Not Sending
Solution: Check Odoo notification settings. Alerts use
user.notify_warning() which requires Odoo mail configuration.
Advanced Features
Custom Provider Fallback
Per-User Budgets
Quality-Based Routing
Next Steps
- Create Your First Budget: Go to Settings โ Technical โ Cost Optimization โ Budgets โ Create
- Monitor for 1 Week: Let the system collect benchmark data and detect waste patterns
-
Review Cost Report: Run
generate_cost_report()to see savings recommendations - Enable A/B Testing: Let system test cheaper alternatives (automatic 80/20 split)
- Optimize Based on Data: Switch providers or adjust budgets based on real performance data