mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-07 02:58:11 +00:00
### TL;DR
Added Python SDK for integrating Supermemory with Cartesia Line voice agents, enabling persistent memory capabilities.
### What changed?
Created a new Python SDK package (`supermemory_cartesia`) that provides:
- `SupermemoryCartesiaAgent` wrapper class that enhances Cartesia Line agents with memory capabilities
- Memory retrieval and storage functionality that integrates with the Supermemory API
- Utility functions for memory formatting, deduplication, and time formatting
- Custom exception classes for error handling
- Comprehensive documentation and type hints
The implementation includes:
- Memory enrichment for user queries
- Automatic storage of conversation history
- Configurable memory retrieval modes (profile, query, full)
- Background processing to avoid blocking the main conversation flow
### How to test?
```python
from supermemory_cartesia import SupermemoryCartesiaAgent
from line.llm_agent import LlmAgent, LlmConfig
import os
# Create base LLM agent
base_agent = LlmAgent(
model="gemini/gemini-2.5-flash-preview-09-2025",
config=LlmConfig(
system_prompt="You are a helpful assistant.",
introduction="Hello!"
)
)
# Wrap with Supermemory
memory_agent = SupermemoryCartesiaAgent(
agent=base_agent,
api_key=os.getenv("SUPERMEMORY_API_KEY"),
user_id="user-123",
)
# Use memory_agent in your Cartesia Line application
```
### Why make this change?
This SDK enables Cartesia Line voice agents to maintain persistent memory across conversations, enhancing user experience by:
1. Providing contextual awareness of past interactions
2. Remembering user preferences and important information
3. Reducing repetition in conversations
4. Creating more personalized and natural voice interactions
The integration is designed to be lightweight and non-blocking, ensuring that memory operations don't impact the responsiveness of voice interactions.
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
"""Custom exceptions for Supermemory Cartesia integration."""
|
|
|
|
from typing import Optional
|
|
|
|
|
|
class SupermemoryCartesiaError(Exception):
|
|
"""Base exception for all Supermemory Cartesia errors."""
|
|
|
|
def __init__(self, message: str, original_error: Optional[Exception] = None):
|
|
super().__init__(message)
|
|
self.message = message
|
|
self.original_error = original_error
|
|
|
|
def __str__(self) -> str:
|
|
if self.original_error:
|
|
return f"{self.message}: {self.original_error}"
|
|
return self.message
|
|
|
|
|
|
class ConfigurationError(SupermemoryCartesiaError):
|
|
"""Raised when there are configuration issues (e.g., missing API key, invalid params)."""
|
|
|
|
|
|
class MemoryRetrievalError(SupermemoryCartesiaError):
|
|
"""Raised when memory retrieval operations fail."""
|
|
|
|
|
|
class MemoryStorageError(SupermemoryCartesiaError):
|
|
"""Raised when memory storage operations fail."""
|
|
|
|
|
|
class APIError(SupermemoryCartesiaError):
|
|
"""Raised when Supermemory API requests fail."""
|
|
|
|
def __init__(
|
|
self,
|
|
message: str,
|
|
status_code: Optional[int] = None,
|
|
response_text: Optional[str] = None,
|
|
original_error: Optional[Exception] = None,
|
|
):
|
|
super().__init__(message, original_error)
|
|
self.status_code = status_code
|
|
self.response_text = response_text
|
|
|
|
def __str__(self) -> str:
|
|
parts = [self.message]
|
|
if self.status_code:
|
|
parts.append(f"Status: {self.status_code}")
|
|
if self.response_text:
|
|
parts.append(f"Response: {self.response_text}")
|
|
if self.original_error:
|
|
parts.append(f"Cause: {self.original_error}")
|
|
return " | ".join(parts)
|
|
|
|
|
|
class NetworkError(SupermemoryCartesiaError):
|
|
"""Raised when network operations fail."""
|