MadMax
MadMax copied to clipboard
Real-time voice AI agent with persistent memory, built on Gemini Live API and Python
๐ MadMax Live Agent
A voice agent for devices, powered by Google Gemini Live API with a local wake-word detector and long-term memory.
Capabilities:
- ๐ฃ๏ธ Realtime Speech-to-Speech dialogue via Gemini Live API
- ๐ Fresh information from the internet via Google Search (grounding)
- ๐ฐ Budget-friendly: offline mode with local wake-word (Vosk) and auto-shutdown timer
- ๐ง Managed long-term memory based on JSON files: people, places, facts, goals, experience, episodes, reflections and persona
- ๐ ๏ธ Tool calling in live mode
Technical highlights:
- ๐ Transactional memory isolation: backup + rollback on errors, single-use guard
- ๐งช LLM Surgeon: automatic memory conflict resolution via LLM
- ๐ Auto-save all sessions to daily markdown
- ๐ Automatic recovery of missed sessions
- โฑ๏ธ Graceful shutdown with configurable timeouts
- ๐ Latency diagnostics for all LLM calls in logs
In development:
- ๐ท Photo and video stream processing
- ๐งน Smart long-term memory cleanup
- ๐ค Integration with ROS2 modules for robot control
- ๐ง Other integrations and improvements
๐ Key Features
๐ฌ Realtime Voice Loop
- Local wake-word detection via Vosk (no LLM costs)
- Instant transition to live mode on the wake word
- Speech-to-Speech dialogue with minimal latency
๐ง Post-Session Memory Pipeline
- Automatic extraction: facts, goals, experience, episodes, reflections and persona after every session
- LLM Surgeon: memory conflict resolution (UPDATE / MERGE / APPEND / IGNORE) via a separate LLM call
- Rebuild of
active_context.jsonfor upcoming dialogues - Automatic recovery of unprocessed sessions
๐ญ Agent Persona (Max)
- Name, gender and communication style are set in
agent_instructions.md SOUL.mdโ philosophical persona manifesto: attitude toward the world, inclinations, shadow, meta-reflection, written by the agent itself after hours of testing conversations- Automatic extraction of reflections and persona traits from dialogues into
reflections.json
๐๏ธ Architecture
1๏ธโฃ Sleep Mode
Agent is offline; microphone is monitored locally via Vosk. No LLM costs.
2๏ธโฃ Active Session
After the wake word audio switches to Gemini Live API. Dialogue runs in realtime.
3๏ธโฃ Post-Session Processing
After a session ends:
- Save transcript to
memory_engine/daily/YYYY-MM-DD.md - Call
process_missing_sessions(day_date)โ process all unprocessed sessions of the day - Call
build_memory_context()โ rebuild active context
๐พ Memory Structure
๐ Daily Markdown Logs
Every session is saved to memory_engine/daily/YYYY-MM-DD.md with metadata:
session_idstarted_atandended_at(ISO 8601 with timezone offset)- Dialogue transcript
Source of truth for post-session processing.
๐งฉ Active Context
File memory_engine/active_context.json:
{
"last_context": "...",
"summary_yesterday": "...",
"summary_today": "...",
"reply_count_today": 0,
"summary_reply_count": 0,
"long_term_injections": []
}
Used as the working context for upcoming live sessions.
๐๏ธ Long-Memory Storage
Directory memory_engine/memory/:
people.jsonโ information about peopleplaces.jsonโ places and locationsfacts.jsonโ facts and knowledgegoals.jsonโ goals and tasksexperience.jsonโ experience and skillsreflections.jsonโ reflections and insightsepisodes.log.jsonlโ episode chronologyprocessed_sessions.jsonโ registry of processed sessions (prevents reprocessing the same session)
โ๏ธ Configuration
- Google AI Studio API Key in
.env - Key parameters in
config.py - Memory settings in
memory_config.py
๐ Project Structure
MadMax/
โโโ main.py # Entry point
โโโ config.py # Configuration
โโโ agent_instructions.md # Agent system prompt (Max)
โโโ SOUL.md # Agent persona and philosophy
โโโ core/
โ โโโ orchestrator.py # Agent lifecycle (sleep / live / post-session)
โ โโโ audio_io.py # Audio I/O and Vosk wake-word
โ โโโ gemini_client.py # Gemini Live API client
โ โโโ agent_tools.py # Memory tools for live mode
โ โโโ session_transcript_logger.py # Session transcript persistence
โ โโโ errors.py # Exceptions
โ โโโ state.py # Session state
โโโ memory_engine/
โ โโโ active_context_builder.py # active_context.json builder
โ โโโ long_memory_extractor_agent.py # Memory extraction from transcripts
โ โโโ long_memory_apply.py # Memory operations + LLM Surgeon
โ โโโ long_memory_normalize.py # Normalization and fuzzy matching
โ โโโ long_memory_ops.py # Operation schemas and validation
โ โโโ long_memory_query_service.py # Long-term memory search
โ โโโ summarize_context_agent.py # Day summarization
โ โโโ llm_client_utils.py # LLM timeout and diagnostics
โ โโโ memory_config.py # Memory paths and constants
โ โโโ entity_policies.py # Entity link policies
โ โโโ time_policy.py # Timestamp policy
โ โโโ daily/ # Daily markdown logs
โ โโโ memory/ # Long-memory JSON files + backups
โโโ live_api_docs/ # Gemini Live API documentation
๐ Quick Start
# 1. Clone and enter directory
cd MadMax
# 2. Create virtual environment
python3 -m venv venv
source venv/bin/activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Download wake-word model (~40 MB)
./setup.sh
# 5. Configure environment
# Create .env file (or export variables):
# GOOGLE_API_KEY=your_key_here
# 6. Run the agent
python main.py
Requirements:
- Linux
- Python 3.11+
- Microphone and speakers
- Google AI Studio API Key
๐ ๏ธ Roadmap
โ Already implemented
- Function Calling for memory โ live agent calls
memory_lookup_person,memory_lookup_goal,memory_lookup_experience,memory_recent_episodesduring dialogue - Google Search (grounding) โ agent receives fresh information from the internet in realtime
- Transactional memory isolation โ backup before write, rollback on errors, single-use guard for
apply_payload - LLM Surgeon โ automatic memory conflict resolution via a separate LLM call with batching
- Fail-fast error handling โ explicit logs on corrupted JSON, graceful
CancelledError, latency diagnostics
๐ฏ Planned
๐งน Smart long-term memory cleanup
Goal: Automatic removal of stale or irrelevant data from memory.
Planned logic:
- Fact prioritization โ relevance score based on access frequency and freshness
- Old episode archival โ move rarely used episodes to cold storage
- Automatic duplicate merging โ find and merge similar facts/goals
- Temporary goal expiration โ auto-complete or archive goals with expired deadlines
- Configurable retention rules โ set data lifetime for different categories
Result: Memory stays relevant, does not grow uncontrollably, and is not cluttered with duplicates and outdated information.
๐ง Refactoring & Type Safety
- Pydantic for structured payloads instead of
dict[str, Any]
๐๏ธ Technical Debt
Consciously accepted trade-offs that are known and documented:
| Issue | Impact | Why we kept it |
|---|---|---|
Any instead of Pydantic for operation payloads |
No type safety, IDE does not suggest fields | It works, changing it requires rewriting 5+ modules |
Tight coupling: GeminiLiveClient imports AudioIO |
Hard to test, risk of circular dependency | No DI container, Protocols require refactoring |
| No CI/CD | No automatic type checking and tests | Project is developed locally, pytest is run manually |
๐ค Agentic Engineering
Important: A significant part of this project was written using Agentic Engineering in pair-programming mode.
๐ Current Status
The project consists of three stable loops:
- Live conversation loop โ realtime Speech-to-Speech dialogue with the user (Google Search, tool calling, Vosk wake-word)
- Post-session memory loop โ automatic extraction, deduplication and knowledge persistence (people, places, facts, goals, experience, episodes, reflections, persona)
- Reliability loop โ transactional isolation (backup + rollback), graceful shutdown, LLM timeouts, recovery of missed sessions
The voice agent is ready for daily use as-is. The main constraints are architectural debt (see section above), not functional issues.