Skip to main content

smaran-cartesia

Memory-enhanced voice agents with Smaran and Cartesia Line.

Installation

pip install smaran-cartesia

Quick Start

import os
from line.llm_agent import LlmAgent, LlmConfig
from line.voice_agent_app import VoiceAgentApp
from smaran_cartesia import SmaranCartesiaAgent

async def get_agent(env, call_request):
    user_id = call_request.metadata.get("user_id", "default-user")

    base_agent = LlmAgent(
        model="gemini/gemini-2.5-flash-preview-09-2025",
        config=LlmConfig(
            system_prompt="You are a helpful voice assistant with memory.",
            introduction="Hello! Great to talk with you again!"
        )
    )

    memory_agent = SmaranCartesiaAgent(
        agent=base_agent,
        api_key=os.getenv("SMARAN_API_KEY"),
        base_url=os.getenv("SMARAN_URL"),
        user_id=user_id,
        session_id=call_request.call_id,
    )

    return memory_agent

app = VoiceAgentApp(get_agent=get_agent)

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

Configuration

Parameters

Parameter Type Required Description
agent LlmAgent Yes The Cartesia Line agent to wrap
user_id str Yes User identifier memories are scoped to
session_id str Yes Conversation/call ID, used to group saved messages
api_key str No Smaran API key (or set SMARAN_API_KEY env var)
base_url str No Smaran API base URL (or set SMARAN_URL env var)
config MemoryConfig No Advanced configuration

Advanced Configuration

from smaran_cartesia import SmaranCartesiaAgent

memory_agent = SmaranCartesiaAgent(
    agent=base_agent,
    user_id="user-123",
    session_id="conversation-456",
    config=SmaranCartesiaAgent.MemoryConfig(
        search_limit=5,           # Max memories to recall per turn
        system_prompt="Based on previous conversations:\n\n",
        save_memory=True,         # Save new memories after each turn
    ),
)

How It Works

  1. Intercepts events — listens for UserTurnEnded events from Cartesia Line
  2. Recalls memories — queries Smaran's /v1/recall API with the user's message
  3. Enriches context — injects recalled facts into the agent's system prompt
  4. Saves messages — sends conversation turns to Smaran's /v1/memories API in the background, non-blocking
  5. Passes to agent — forwards the enriched event to the wrapped LlmAgent

Architecture

Cartesia Line uses an event-driven architecture:

User Speaks (Audio)
    ↓
[Ink STT] → Automatic speech recognition
    ↓
UserTurnEnded Event {content: "user message", history: [...]}
    ↓
┌──────────────────────────────────────────────┐
│   SMARAN CARTESIA AGENT (Wrapper)             │
│                                                │
│  process(env, event):                         │
│    1. Intercept UserTurnEnded                 │
│    2. Extract user message                    │
│    3. Recall from Smaran                      │
│    4. Inject recalled memories into prompt    │
│    5. Pass to wrapped LlmAgent                │
│    6. Save conversation (async background)    │
└──────────────────────────────────────────────┘
    ↓
AgentSendText Event {text: "response"}
    ↓
[Sonic TTS] → Ultra-fast speech synthesis
    ↓
Audio Output

Comparison with the Pipecat SDK

Aspect Pipecat Cartesia Line
Integration pattern Extends FrameProcessor Wrapper around LlmAgent
Event handling process_frame() method process() method
Events LLMContextFrame UserTurnEnded, CallStarted
Context object LLMContext.get_messages() event.history

Development

git clone https://github.com/Ayushpani/smaran
cd smaran/packages/cartesia-sdk-python
pip install -e ".[dev]"
pytest

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smaran_cartesia-0.1.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smaran_cartesia-0.1.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file smaran_cartesia-0.1.1.tar.gz.

File metadata

  • Download URL: smaran_cartesia-0.1.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for smaran_cartesia-0.1.1.tar.gz
Algorithm Hash digest
SHA256 963819978d62cde77e1a9cec383c00e5f063d1eb68c4ccbcdca3578ff6a1434c
MD5 24606df31faa541b4664311b578c832e
BLAKE2b-256 20fe7afe3a7fc97fa124e1ddec9cdd88b18d4b2b0a0d8eab3dd6bf6390e08075

See more details on using hashes here.

Provenance

The following attestation bundles were made for smaran_cartesia-0.1.1.tar.gz:

Publisher: publish-cartesia-sdk-python.yml on Ayushpani/smaran

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smaran_cartesia-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for smaran_cartesia-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d371df88c8842d3864e2dcc0c482b8313bfcaf72eef1f7ca2a0c105ac85f1da0
MD5 78bb67e7d75c9963ccbf4babd2c948e6
BLAKE2b-256 238225a5905b37b205aa44aa79ad8d7812f080b7ec093ddaa93cd4299f9bf84c

See more details on using hashes here.

Provenance

The following attestation bundles were made for smaran_cartesia-0.1.1-py3-none-any.whl:

Publisher: publish-cartesia-sdk-python.yml on Ayushpani/smaran

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page