omi-backend-patterns
Omi Backend Patterns Skill
This skill provides guidance for working with the Omi backend, including conversation processing, memory extraction, chat system, and LangGraph integration.
When to Use
Use this skill when:
- Working on backend Python code in
backend/ - Implementing new API endpoints
- Processing conversations or extracting memories
- Working with the LangGraph chat system
- Integrating with Firestore, Pinecone, or Redis
Key Patterns
Conversation Processing
The conversation processing pipeline follows this flow:
- Audio arrives via WebSocket (
/v4/listen) - Transcription via Deepgram/Soniox/Speechmatics
- Conversation creation in Firestore (status: "in_progress")
- Processing trigger via
POST /v1/conversationsor timeout - LLM extraction of structured data:
- Title and overview
- Action items
- Calendar events
- Memories (user facts)
- Storage in Firestore and Pinecone
Key Function: utils/conversations/process_conversation.py::process_conversation()
Memory Extraction
Memories are extracted from conversations using LLM:
from utils.llm.conversation_processing import _extract_memories
memories = await _extract_memories(
transcript=transcript,
existing_memories=existing_memories,
)
Categories: personal, health, work, relationships, preferences
Chat System Architecture
The chat system uses LangGraph for routing:
- Classification:
requires_context()determines path - Simple Path: Direct LLM response (no context needed)
- Agentic Path: Full tool access with LangGraph ReAct agent
- Persona Path: Persona app responses
Key File: utils/retrieval/graph.py
Module Hierarchy
CRITICAL: Always follow the import hierarchy:
database/- Data access (lowest)utils/- Business logicrouters/- API endpointsmain.py- Application entry
Never import from higher levels in lower levels!
Database Patterns
- Firestore: Primary database for conversations, memories, users
- Pinecone: Vector embeddings for semantic search
- Redis: Caching (speech profiles, enabled apps, user names)
- GCS: Binary files (audio, photos, speech profiles)
API Endpoint Patterns
- Use FastAPI routers in
routers/ - Keep routers thin - business logic in
utils/ - Use dependency injection for auth
- Return consistent error formats
Common Tasks
Adding a New API Endpoint
- Create router function in appropriate
routers/*.py - Add business logic in
utils/ - Use database functions from
database/ - Follow error handling patterns
- Add to router in
main.py
Processing Conversations
- Use
process_conversation()fromutils/conversations/process_conversation.py - Handle extraction results
- Store in Firestore and Pinecone
- Trigger app webhooks if needed
Adding a Chat Tool
- Create tool function in
utils/retrieval/tools/ - Use
@tooldecorator from LangChain - Add to tool loading in
utils/retrieval/tools/app_tools.py - Tool will be available in agentic chat path
Related Documentation
The docs/ folder is the single source of truth for all user-facing documentation, deployed at docs.omi.me.
- Backend Deep Dive:
docs/doc/developer/backend/backend_deepdive.mdx- View online - Chat System:
docs/doc/developer/backend/chat_system.mdx- View online - Data Storage:
docs/doc/developer/backend/StoringConversations.mdx- View online - Transcription:
docs/doc/developer/backend/transcription.mdx- View online - Backend Setup:
docs/doc/developer/backend/Backend_Setup.mdx- View online - Backend Architecture:
.cursor/rules/backend-architecture.mdc
Related Cursor Resources
Rules
.cursor/rules/backend-architecture.mdc- System architecture and module hierarchy.cursor/rules/backend-api-patterns.mdc- FastAPI router patterns.cursor/rules/backend-database-patterns.mdc- Database storage patterns.cursor/rules/backend-llm-patterns.mdc- LLM integration patterns.cursor/rules/backend-testing.mdc- Testing patterns.cursor/rules/backend-imports.mdc- Import rules.cursor/rules/memory-management.mdc- Memory management
Subagents
.cursor/agents/backend-api-developer/- Uses this skill for API development.cursor/agents/backend-llm-engineer/- Uses this skill for LLM integration.cursor/agents/backend-database-engineer/- Uses this skill for database work
Commands
/backend-setup- Uses this skill for setup guidance/backend-test- Uses this skill for testing patterns/backend-deploy- Uses this skill for deployment patterns
More from basedhardware/omi
local-dev
Start local development environment — backend, macOS app, or Flutter mobile in iOS simulator. Use when: 'run the app', 'start backend', 'run simulator', 'flutter run', 'local dev', 'start dev environment', 'run mobile app'.
45rotate-key
Rotate an API key or secret across all locations — local .env files, macOS Keychain, GCP Secret Manager, Kubernetes deployments, and Codemagic CI. Use when: 'rotate key', 'update key', 'key leaked', 'replace secret', 'new API key', 'update GEMINI key', 'rotate secret'.
26self-improvement
Meta-skill for analyzing PRs, issues, and user interactions to improve Cursor rules and skills automatically
14debug-mode
Debug mode workflows and best practices for troubleshooting bugs, regressions, and performance issues. Use when debugging tricky issues that standard agent interactions struggle with.
13docs-automation
Automate documentation updates when API endpoints, functions, or architecture change. Detects code changes that require doc updates, generates API reference from FastAPI routers, updates architecture diagrams, and syncs between internal and external docs.
13omi-flutter-patterns
Flutter Dart BLE device communication state management Provider backend integration localization cross-platform iOS Android
13