Metadata-Version: 2.4
Name: slashml-memory
Version: 1.1.0
Summary: Official HTTP Python SDK for / ml (https://api.slashml.ai)
Author: SlashML Inc.
License: Apache-2.0
Project-URL: Homepage, https://slashml.ai
Project-URL: Repository, https://github.com/slashml-ai/ml-memory
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24.0
Dynamic: license-file

# `/ ml` (`slashml-memory`) Python SDK

Official HTTP Python SDK for **`/ ml` (`https://api.slashml.ai`)**.

## Installation

```bash
pip install slashml-memory
export SLASHML_API_KEY="sml_live_..."
```

## Quickstart

### 1. Native `/ ml` Memory Client (`SlashMLMemory` / `MemoryClient`)

```python
from slashml import SlashMLMemory

client = SlashMLMemory(api_key="sml_live_...")

# Ingest text or source code
client.ingest(
    documents=[
        {"id": "doc_1", "text": "Production PostgreSQL runs on port 5432 with pgBouncer on 6432."}
    ],
    user_id="alice",
)

# Query stored memories
hits = client.query("Which port does pgBouncer listen on?", user_id="alice", top_k=3)
print(hits["results"][0])

# Delete documents by ID
client.forget(["doc_1"], user_id="alice")
```

### 2. 1-Line `Mem0` Drop-In Replacement (`Memory` & `MemoryClient`)

Replace `from mem0 import MemoryClient` or `from mem0 import Memory` with `from slashml import MemoryClient, Memory`:

```python
# Before: from mem0 import MemoryClient
from slashml import MemoryClient

client = MemoryClient(api_key="sml_live_...")

client.add(
    [{"role": "user", "content": "Always use uv and pytest -q for Python checks."}],
    user_id="developer_1",
)

results = client.search("How should I run Python tests?", user_id="developer_1")

# 3. Evaluate an agent turn or tool action
decision = client.intervene(
    "pip install pytest",
    hook_event_name="PreToolUse",
    tool_name="Bash",
    user_id="developer_1",
)
```

### 3. Inline Redaction & Per-Agent Read/Write Access Control

```python
from slashml import Memory

admin = Memory(api_key="sml_live_...")

# Configure workspace defaults & bind a read-only, GDPR-masked support agent
admin.set_redaction_policy(
    redact_policy="tier1_secrets",
    redact_scope="recall_only",
    access_mode="read_write",
)
admin.configure_agent(
    agent_id="support_triage_bot",
    access_mode="read_only",
    redact_policy="gdpr",
    redact_scope="recall_only",
)

# Scoped agent client automatically attaches X-SlashML-Agent-Id
triage = Memory(api_key="sml_live_...", agent_id="support_triage_bot")
masked = triage.redact(text="Billing contact is alice@acme.io")
recalled = triage.search("Who is the billing contact?", user_id="developer_1")
```

### 4. CLI & Ambient Hook Installation

```bash
python -m slashml.mcp_server --install-hooks --api-key "$SLASHML_API_KEY" --agent-id "coding_agent" --redact-policy "soc2_coding"
```

### 5. Swarm Memory, Delegated Tokens & Runtime Guardrails

Mint scoped worker tokens, share live findings within a `run_id`, promote validated findings to durable project memory, and wrap any Python tool or agent framework (`LangGraph`, `CrewAI`, `OpenAI Agents SDK`) with synchronous pre-execution guardrails and agent-scoped output redaction:

```python
from slashml import (
    MemoryClient,
    guard_tools,
    SlashMLGuardedToolNode,
    SlashMLCrewGuard,
    SlashMLAgentHooks,
)

coord = MemoryClient(api_key="sml_live_...", project_id="proj_payments")
worker_tok = coord.mint_worker_token(
    "worker-1",
    tier="worker",
    run_id="run_42",
    project_id="proj_payments",
    redact_policy="soc2_coding",
)["token"]

worker = MemoryClient(api_key=worker_tok, project_id="proj_payments", run_id="run_42")

def run_sql(sql: str) -> str:
    return execute_query(sql)

# 1-line synchronous PreToolUse guardrail + automatic output redaction
safe_run_sql = guard_tools(run_sql, client=worker)

# Promote validated run findings to durable project memory, then revoke worker tokens
coord.promote_run("run_42", target_project_id="proj_payments", discard_unpromoted=True)
coord.revoke_agent_tokens("worker-1")
```

## License

Apache-2.0

<!-- mcp-name: io.github.slashml-ai/ml-memory -->


