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
- Intercepts events — listens for
UserTurnEndedevents from Cartesia Line - Recalls memories — queries Smaran's
/v1/recallAPI with the user's message - Enriches context — injects recalled facts into the agent's system prompt
- Saves messages — sends conversation turns to Smaran's
/v1/memoriesAPI in the background, non-blocking - 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
963819978d62cde77e1a9cec383c00e5f063d1eb68c4ccbcdca3578ff6a1434c
|
|
| MD5 |
24606df31faa541b4664311b578c832e
|
|
| BLAKE2b-256 |
20fe7afe3a7fc97fa124e1ddec9cdd88b18d4b2b0a0d8eab3dd6bf6390e08075
|
Provenance
The following attestation bundles were made for smaran_cartesia-0.1.1.tar.gz:
Publisher:
publish-cartesia-sdk-python.yml on Ayushpani/smaran
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smaran_cartesia-0.1.1.tar.gz -
Subject digest:
963819978d62cde77e1a9cec383c00e5f063d1eb68c4ccbcdca3578ff6a1434c - Sigstore transparency entry: 2726176802
- Sigstore integration time:
-
Permalink:
Ayushpani/smaran@b5637da37565cc834235b490bd1766703be1b92d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Ayushpani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-cartesia-sdk-python.yml@b5637da37565cc834235b490bd1766703be1b92d -
Trigger Event:
push
-
Statement type:
File details
Details for the file smaran_cartesia-0.1.1-py3-none-any.whl.
File metadata
- Download URL: smaran_cartesia-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d371df88c8842d3864e2dcc0c482b8313bfcaf72eef1f7ca2a0c105ac85f1da0
|
|
| MD5 |
78bb67e7d75c9963ccbf4babd2c948e6
|
|
| BLAKE2b-256 |
238225a5905b37b205aa44aa79ad8d7812f080b7ec093ddaa93cd4299f9bf84c
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smaran_cartesia-0.1.1-py3-none-any.whl -
Subject digest:
d371df88c8842d3864e2dcc0c482b8313bfcaf72eef1f7ca2a0c105ac85f1da0 - Sigstore transparency entry: 2726176895
- Sigstore integration time:
-
Permalink:
Ayushpani/smaran@b5637da37565cc834235b490bd1766703be1b92d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Ayushpani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-cartesia-sdk-python.yml@b5637da37565cc834235b490bd1766703be1b92d -
Trigger Event:
push
-
Statement type: