Skip to content

Supermemory-Cartesia SDK#744

Open
sreedharsreeram wants to merge 1 commit intomainfrom
cartesia-supermemory
Open

Supermemory-Cartesia SDK#744
sreedharsreeram wants to merge 1 commit intomainfrom
cartesia-supermemory

Conversation

@sreedharsreeram
Copy link
Copy Markdown
Contributor

@sreedharsreeram sreedharsreeram commented Feb 17, 2026

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?

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.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
🔵 In progress
View logs
supermemory-mcp b5add5a Feb 17 2026, 03:12 PM

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Feb 17, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
supermemory-app e501b0d Commit Preview URL

Branch Preview URL
Apr 14 2026, 08:04 PM

Copy link
Copy Markdown
Contributor Author


How to use the Graphite Merge Queue

Add the label Main to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sreedharsreeram sreedharsreeram force-pushed the cartesia-supermemory branch 2 times, most recently from de3ca2a to 22aeaaf Compare February 17, 2026 19:39
@sreedharsreeram sreedharsreeram changed the title initial commit Supermemory-Cartesia SDK Feb 17, 2026
@sreedharsreeram sreedharsreeram marked this pull request as ready for review February 17, 2026 22:55
@graphite-app graphite-app bot requested a review from Dhravya February 17, 2026 22:55
@sreedharsreeram sreedharsreeram force-pushed the cartesia-supermemory branch 2 times, most recently from d2d0d8d to 6bcf26f Compare February 20, 2026 06:39
@Dhravya
Copy link
Copy Markdown
Member

Dhravya commented Feb 25, 2026

@sreedharsreeram Waiting for the demo!

@Dhravya Dhravya requested a review from sohamd22 March 3, 2026 23:19
@claude
Copy link
Copy Markdown

claude bot commented Apr 14, 2026

Claude finished @sreedharsreeram's task in 1m 26s —— View job


Reviewing PR #744: Supermemory-Cartesia SDK

  • Fetch PR diff and existing review comments
  • Analyze code for bugs, security issues, and logic errors
  • Check boundary conditions and edge cases
  • Review error handling and async patterns
  • Provide review summary

Overview: Adds a Python SDK package (supermemory_cartesia) that wraps Cartesia Line voice agents with persistent memory retrieval and storage capabilities via the Supermemory API.

Issues found: None blocking.

I reviewed the implementation across all 8 files. Key observations:

  1. Previous Sentry bug is fixed - The _messages_sent_count increment issue flagged in earlier reviews has been properly addressed at agent.py:429 with self._messages_sent_count = 1 after storing the first user message.

  2. Error handling is solid - Memory retrieval failures don't break voice flow (agent.py:367-372). The 10-second timeout on memory retrieval (agent.py:164-167) is appropriate for real-time voice interactions.

  3. Background task management - Tasks are tracked in _background_tasks set with done callbacks (agent.py:146, 418-419). This prevents garbage collection of pending tasks.

  4. Security - API keys are handled properly (env var or explicit param, never logged). User messages are truncated in logs (agent.py:354, 425). No injection vectors exist since memory tags are system-controlled.

  5. Defensive programming - Extensive hasattr and type checks for Cartesia event compatibility (agent.py:264-286, 288-335). Graceful handling of missing supermemory or line dependencies (agent.py:18-26).

The code is clean, well-documented, and follows good practices for a fire-and-forget analytics SDK.

Score: 9/10

The implementation is production-ready. The only reason it's not 10/10 is the untracked nature of asyncio.create_task() calls—while the tasks are held in a set to prevent GC, if the parent SupermemoryCartesiaAgent instance is garbage collected, pending storage tasks could be cancelled. This is acceptable for non-critical storage operations but could be addressed with a more robust task management pattern if needed in the future.

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview: Adds a Python SDK for integrating Supermemory with Cartesia Line voice agents, enabling persistent memory retrieval and storage during voice conversations.

Issues found: None blocking.

The Sentry-flagged bug regarding _messages_sent_count not being incremented for first messages has been fixed (see agent.py:417). The untracked background task concern is a valid note but acceptable for fire-and-forget storage operations in this context.

Code quality observations:

  • Clean separation of concerns (agent wrapper, utilities, exceptions)
  • Proper error handling with graceful degradation (memory failures don't break the voice flow)
  • Good defensive programming with hasattr checks for Cartesia event compatibility
  • Appropriate timeout (10s) on memory retrieval to prevent blocking voice interactions

Score: 9/10

The implementation is solid and ready to ship. The only reason it's not 10/10 is the untracked asyncio.create_task() calls—while acceptable for analytics, adding task references with done callbacks would be the ideal pattern for production robustness.

Comment on lines +86 to +96
config: Optional[MemoryConfig] = None,
base_url: Optional[str] = None,
):
"""Initialize the Supermemory Cartesia agent wrapper.

Args:
agent: The inner Cartesia Line agent to wrap.
api_key: Supermemory API key (or SUPERMEMORY_API_KEY env var).
container_tag: Primary container tag for memory scoping (e.g., user ID).
custom_id: Required. Custom ID to store all conversation messages in the same document.
Useful for grouping multi-turn conversations (e.g., call ID, conversation ID).
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The agent's __init__ method does not accept the session_id parameter used throughout the documentation, causing a TypeError. The documentation also incorrectly marks the required custom_id as optional.
Severity: CRITICAL

Suggested Fix

Update the documentation in apps/docs/integrations/cartesia.mdx to use the correct custom_id parameter instead of the non-existent session_id parameter in all code examples. Also, update the parameter table in the documentation to mark custom_id as required.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/cartesia-sdk-python/src/supermemory_cartesia/agent.py#L79-L96

Potential issue: The `SupermemoryCartesiaAgent` constructor signature in `agent.py` does
not accept a `session_id` parameter. However, the primary integration documentation in
`apps/docs/integrations/cartesia.mdx` exclusively uses `session_id` in all its code
examples. Additionally, the documentation incorrectly marks the `custom_id` parameter as
optional, when the code enforces it as a required, non-empty string. Any user following
the documentation will encounter an immediate `TypeError: __init__() got an unexpected
keyword argument 'session_id'` when trying to instantiate the agent, making the
integration unusable as documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants