Cartha SDK (Python)
Instrument AI agents with memory, traces, costs, and policies on Cartha.
Install
pip install cartha-sdk
Requires Python 3.10+.
From source (development):
pip install "git+https://github.com/maulik-jadav/nexus.git#subdirectory=nexus/packages/sdk-python"
# or from a local clone:
pip install -e nexus/packages/sdk-python
Quickstart
export CARTHA_API_KEY="cartha_..." # from the dashboard → Keys
export CARTHA_API_BASE="https://cartha.in" # your Cartha deployment
import cartha
cartha.init() # picks up CARTHA_* env vars
@cartha.trace()
def run_agent(prompt: str):
return "..."
@cartha.trace() works on sync and async functions. Every call registers the
agent, sends heartbeats, and records a full trace (start → steps → finish),
including failures.
Memory
import cartha
# async agents
await cartha.remember(user_id="u1", content="Prefers dark mode", scope="user")
hits = await cartha.recall(user_id="u1", context="UI preferences", scope=["user", "team"])
# sync code
cartha.remember_sync(user_id="u1", content="Prefers dark mode", scope="user")
Scopes: agent (private) · user (all agents serving that user) ·
team (same team_id) · org (everyone in your org).
Nested agents (multi-agent loops)
By default, @cartha.trace() auto-nests: if a traced agent calls another
traced agent, the child run links via parent_trace_id. No env plumbing
required for in-process sub-agents.
@cartha.trace(id="parent")
async def orchestrator(user_id: str):
await cartha.ops.delegate(to_agent_id="worker", task_description="handle")
return await worker(user_id)
@cartha.trace(id="worker") # nests under orchestrator automatically
async def worker(user_id: str):
...
Cost per completed task
Share a task_id across retries so the dashboard rolls failed redoes into one outcome:
tid = cartha.task_context()
for attempt in range(3):
try:
await run_agent(..., cartha_task_id=tid)
break
except Exception:
continue
Memory denial mode
Org setting (PATCH /org → memory_denial_mode):
denied_hint(default): recall returns explicit denials without content so agents don't invent over a hole.silent: empty hits only (no existence leak).
Advanced
The full instrumentation API lives in cartha.ops (tool calls, cost events,
A2A delegation, policy checks, run nesting):
from cartha import ops
Legacy alias: older code may from nexus import ops. That still works for
compatibility, but new code should use cartha.
Trace diff: GET /api/v1/traces/diff?left=…&right=… finds the first
diverging step between two runs (also on the dashboard).
Publishing (maintainers)
Releases are published from GitHub Actions when you push a tag matching
sdk-python-v* (for example sdk-python-v0.1.0).
Manual upload (emergency / first release):
cd nexus/packages/sdk-python
python -m pip install --upgrade build twine
python -m build
# TestPyPI first (recommended):
python -m twine upload --repository testpypi dist/*
# Production PyPI:
python -m twine upload dist/*
Use a PyPI API token (pypi-...), not your account password.
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 cartha_sdk-0.3.0.tar.gz.
File metadata
- Download URL: cartha_sdk-0.3.0.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fcf3ebf1dfafe37299763b93fdbb6105d29f651fff2f2451b7e0a31404ed7f7
|
|
| MD5 |
0b04bda66ce63b5f85a92ec816029bd1
|
|
| BLAKE2b-256 |
6c6937586bb31289275031d014cfe59100f881c697de945c79c78d9a5ec025b4
|
Provenance
The following attestation bundles were made for cartha_sdk-0.3.0.tar.gz:
Publisher:
publish-sdk-python.yml on maulik-jadav/nexus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cartha_sdk-0.3.0.tar.gz -
Subject digest:
4fcf3ebf1dfafe37299763b93fdbb6105d29f651fff2f2451b7e0a31404ed7f7 - Sigstore transparency entry: 2199598510
- Sigstore integration time:
-
Permalink:
maulik-jadav/nexus@b3b45a6aec57ffc04a5e0a507412ab37c298eddf -
Branch / Tag:
refs/tags/sdk-python-v0.3.0 - Owner: https://github.com/maulik-jadav
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk-python.yml@b3b45a6aec57ffc04a5e0a507412ab37c298eddf -
Trigger Event:
push
-
Statement type:
File details
Details for the file cartha_sdk-0.3.0-py3-none-any.whl.
File metadata
- Download URL: cartha_sdk-0.3.0-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
745aa22a3da3b965d941bdd5082cbc22b3d24d672957d84fa97ed6e43d9481fb
|
|
| MD5 |
250eadb053f4743f5c77086fe149fb46
|
|
| BLAKE2b-256 |
072c53173435ea3b56dc207ddb50509d09dd30f973f173dc9fa58c9dea58680c
|
Provenance
The following attestation bundles were made for cartha_sdk-0.3.0-py3-none-any.whl:
Publisher:
publish-sdk-python.yml on maulik-jadav/nexus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cartha_sdk-0.3.0-py3-none-any.whl -
Subject digest:
745aa22a3da3b965d941bdd5082cbc22b3d24d672957d84fa97ed6e43d9481fb - Sigstore transparency entry: 2199598576
- Sigstore integration time:
-
Permalink:
maulik-jadav/nexus@b3b45a6aec57ffc04a5e0a507412ab37c298eddf -
Branch / Tag:
refs/tags/sdk-python-v0.3.0 - Owner: https://github.com/maulik-jadav
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk-python.yml@b3b45a6aec57ffc04a5e0a507412ab37c298eddf -
Trigger Event:
push
-
Statement type: