Skip to main content

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 /orgmemory_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

cartha_sdk-0.2.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

cartha_sdk-0.2.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file cartha_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: cartha_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cartha_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 704d4aa771382c6c66b17c7a606194e91ba28d417b6edc0ffb407d9b70844fe3
MD5 c7fe532c11e21c38ac848e42b59567ca
BLAKE2b-256 8837a4f7205bba28b86a0db2a90e722d61103777bbf177e1c4f8b926eb20cfcb

See more details on using hashes here.

Provenance

The following attestation bundles were made for cartha_sdk-0.2.0.tar.gz:

Publisher: publish-sdk-python.yml on maulik-jadav/nexus

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

File details

Details for the file cartha_sdk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cartha_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cartha_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30f7677ec835109bf7e6d0da7ccf1f80d8e77209937c49c4e5e9cd05f3d086bf
MD5 e01de98de2e1445a9015ceda9d64e941
BLAKE2b-256 44e28792fbbe7a984feb2276beeb599c734a80bd66aae21dc1a1bf6c0a93c87e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cartha_sdk-0.2.0-py3-none-any.whl:

Publisher: publish-sdk-python.yml on maulik-jadav/nexus

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page