Skip to content

Supermemory-Cartesia SDK#744

Merged
graphite-app[bot] merged 1 commit intomainfrom
cartesia-supermemory
Apr 15, 2026
Merged

Supermemory-Cartesia SDK#744
graphite-app[bot] merged 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 Updated (UTC)
✅ Deployment successful!
View logs
supermemory-app e672af6 Apr 15 2026, 04:31 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
Comment thread packages/cartesia-sdk-python/src/supermemory_cartesia/agent.py Outdated
@sreedharsreeram sreedharsreeram force-pushed the cartesia-supermemory branch 2 times, most recently from d2d0d8d to 6bcf26f Compare February 20, 2026 06:39
Comment thread packages/cartesia-sdk-python/src/supermemory_cartesia/agent.py Outdated
@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 23s —— View job


Review Complete

  • Fetch PR diff and existing review comments
  • Review code for bugs, security issues, and logic errors
  • Check if Sentry-flagged documentation issue was fixed
  • Submit review findings

Summary: All previously flagged issues have been resolved. The code is solid with proper error handling, background task management, and graceful degradation. No new bugs or security concerns found.

Score: 10/10 — Ready to ship.

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 thread packages/cartesia-sdk-python/src/supermemory_cartesia/agent.py
Comment thread packages/cartesia-sdk-python/src/supermemory_cartesia/agent.py
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 — this looks good to ship.

All previously flagged issues have been resolved:

  • _messages_sent_count is now properly incremented when storing the first message (agent.py:429)
  • ✅ Documentation correctly uses custom_id parameter throughout (not session_id)
  • custom_id is properly marked as required in the parameter table

Code quality highlights:

  • Clean separation of concerns (agent wrapper, utilities, exceptions)
  • Proper error handling with graceful degradation — memory failures don't break the voice flow
  • Background tasks are properly tracked (_background_tasks set with done callbacks) to prevent GC issues
  • Appropriate 10s timeout on memory retrieval for voice responsiveness
  • System prompt injection uses proper regex escaping and cleanup

Score: 10/10

The implementation is solid and ready to ship.

Comment thread packages/cartesia-sdk-python/src/supermemory_cartesia/agent.py
@graphite-app
Copy link
Copy Markdown

graphite-app bot commented Apr 15, 2026

Merge activity

### 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.
@graphite-app graphite-app bot force-pushed the cartesia-supermemory branch from 304684f to e672af6 Compare April 15, 2026 16:27
@graphite-app graphite-app bot merged commit e672af6 into main Apr 15, 2026
9 of 11 checks passed
Comment on lines +437 to +440
except Exception as e:
logger.error(f"[Supermemory] Error in process: {e}")
async for output in self.agent.process(env, event):
yield output
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: A generic exception handler in process() retries the async generator, causing duplicate outputs if an error occurs mid-stream.
Severity: HIGH

Suggested Fix

Remove the retry logic from the generic except block. The handler should log the error and potentially yield a specific error event or stop processing, but it should not re-invoke self.agent.process(env, event) to avoid duplicating outputs that were already successfully yielded.

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#L437-L440

Potential issue: The `process` method wraps the agent's async generator in a
`try...except Exception` block. If an exception occurs after the generator has already
yielded some output events, the `except` block catches it and retries the entire
`self.agent.process(env, event)` call from the beginning. This re-execution of the
non-idempotent generator causes the initial set of outputs to be yielded a second time,
leading to duplicate downstream events. For a voice agent, this would manifest as
repeated audio responses and inflated API call costs.

Comment on lines +421 to +422
else:
# No history yet, store just the current user message
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 message history counter _messages_sent_count is reset to a hardcoded 1 instead of being incremented, risking duplicate message storage if history is missing for multiple turns.
Severity: LOW

Suggested Fix

The state tracking should be more robust. Instead of hardcoding the counter to 1, ensure it is only initialized once per conversation. A better approach might be to track the history state more explicitly (e.g., using a boolean flag like self._is_initialized) to prevent the initialization logic from running more than once.

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#L421-L422

Potential issue: In the `process` method, when `event.history` is falsy, the code enters
an `else` block that stores the current user message and hardcodes
`self._messages_sent_count` to `1`. This logic assumes the `else` block is only ever
executed on the first turn of a conversation. However, if an external condition causes
`event.history` to be falsy for multiple consecutive turns within the same conversation,
the counter will be repeatedly reset to `1`. When history is eventually populated, this
incorrect counter value will cause previously stored messages to be stored again.

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