Examples
Real-world examples demonstrating MAIF capabilities.
More Examples on DeepWiki
For a comprehensive list of examples with auto-generated documentation, visit DeepWiki - Examples and Use Cases.
Featured Example
LangGraph Multi-Agent RAG System
Production-ready multi-agent research assistant with cryptographic provenance.
Location: examples/langgraph/
Features:
- Five specialized agents (Init, Retrieve, Synthesize, Fact-Check, Citation)
- Real ChromaDB vector search with 384-dim embeddings
- Gemini API for generation and verification
- LLM-based fact-checking with iterative refinement
- Complete audit trail in MAIF artifacts
- Interactive console interface
- Multi-turn conversation support
Quick Start:
cd examples/langgraph
echo "GEMINI_API_KEY=your_key" > .env
pip install -r requirements_enhanced.txt
python3 create_kb_enhanced.py
python3 demo_enhanced.pyDocumentation: See LangGraph RAG Guide for complete details.
CrewAI Research Crew
Multi-agent research workflow with complete audit trails.
Location: Uses maif.integrations.crewai
Features:
- Two specialized agents (Researcher, Writer)
- Task and step-level provenance tracking
- Persistent agent memory with search
- Complete execution audit trail
- Error handling with logging
Quick Start:
from crewai import Crew, Agent, Task
from maif.integrations.crewai import MAIFCrewCallback
callback = MAIFCrewCallback("session.maif")
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
task_callback=callback.on_task_complete,
step_callback=callback.on_step,
)
result = crew.kickoff()
callback.finalize()Documentation: See CrewAI Research Guide for complete details.
Available Examples
Hello World
The simplest possible MAIF agent. Perfect for understanding the basics.
What you'll learn:
- Creating MAIF artifacts
- Adding text blocks
- Saving and loading
- Basic verification
Time: 5 minutes
Multi-Agent System
Multiple agents collaborating through shared MAIF artifacts.
What you'll learn:
- Agent coordination
- Shared memory patterns
- Provenance tracking
- Multi-agent workflows
Time: 15 minutes
Privacy & Security
Privacy-preserving agent with encryption and anonymization.
What you'll learn:
- AES-GCM encryption
- Differential privacy
- Data anonymization
- Access control
Time: 10 minutes
Streaming Data
High-throughput streaming with memory-mapped I/O.
What you'll learn:
- Streaming operations
- Memory-mapped I/O
- Performance optimization
- Large file handling
Time: 15 minutes
Financial Agent
Privacy-compliant financial transaction analysis.
What you'll learn:
- Regulatory compliance
- Transaction analysis
- Audit trails
- Risk scoring
Time: 20 minutes
Distributed Processing
Distributed agent systems with MAIF synchronization.
What you'll learn:
- Distributed coordination
- State synchronization
- Network protocols
- Fault tolerance
Time: 25 minutes
Quick Start Examples
Hello World Agent (30 seconds)
The simplest possible MAIF agent:
from maif_api import create_maif
# Create agent with memory
memory = create_maif("hello-agent")
# Add content
memory.add_text("Hello, MAIF world!", title="Greeting")
# Save with cryptographic signing
memory.save("hello.maif", sign=True)
print("Your first AI agent memory is ready!")Privacy-Enabled Chat Agent (2 minutes)
A more realistic agent with memory and privacy:
from maif_api import create_maif, load_maif
import os
class PrivateChatAgent:
def __init__(self, agent_id: str):
self.agent_id = agent_id
self.memory_path = f"{agent_id}_memory.maif"
# Load or create memory with privacy
if os.path.exists(self.memory_path):
self.memory = load_maif(self.memory_path)
else:
self.memory = create_maif(agent_id, enable_privacy=True)
def chat(self, message: str, user_id: str) -> str:
# Store message with privacy protection
self.memory.add_text(
f"User {user_id}: {message}",
title="User Message",
encrypt=True,
anonymize=True # Remove PII automatically
)
# Search for relevant context
context = self.memory.search(message, top_k=3)
# Generate response (integrate your LLM here)
response = f"I understand you're asking about: {message}"
# Store response
self.memory.add_text(
f"Agent: {response}",
title="Agent Response",
encrypt=True
)
return response
def save(self):
self.memory.save(self.memory_path, sign=True)
# Usage
agent = PrivateChatAgent("support-bot")
response = agent.chat("How do I reset my password?", "user123")
print(response)
agent.save()Example Categories
By Experience Level
Beginner:
- Hello World - Your first MAIF agent
- Privacy Demo - Basic privacy features
Intermediate:
- Multi-Agent - Agent coordination
- Streaming - High-performance I/O
- Financial Agent - Production patterns
Advanced:
- LangGraph RAG - Complete multi-agent system
- CrewAI Research - Multi-agent workflows with CrewAI
- Distributed - Distributed systems
By Use Case
AI/ML Applications:
- LangGraph RAG - Research assistant with fact-checking
- CrewAI Research - Research and documentation workflow
- Multi-Agent - Collaborative agents
Enterprise:
- Financial Agent - Regulatory compliance
- Privacy Demo - Data protection
Performance:
- Streaming - High throughput
- Distributed - Scale-out architecture
Running the Examples
All examples follow the same pattern:
# 1. Navigate to repository root
cd /path/to/maif
# 2. Install dependencies (if needed)
pip install -e .
# 3. Run the example
python3 examples/<category>/<example_file>.pyFor the LangGraph example:
cd examples/langgraph
pip install -r requirements_enhanced.txt
python3 demo_enhanced.pyExample Structure
Each example includes:
- Complete, runnable code
- Comprehensive error handling
- Performance optimizations
- Security best practices
- Testing and validation
- Detailed documentation
Contributing Examples
Have a great example to share? We welcome contributions!
- Create your example in
examples/<category>/ - Add documentation in
docs/examples/ - Include README with usage instructions
- Submit a pull request
Support
- Documentation: See the User Guide
- API Reference: Check the API docs
- Issues: Report problems on GitHub
Every example is designed to be production-ready. Copy, modify, and deploy with confidence.