Raqim Python SDK (رَقِيم)
Deterministic flight recorder, cryptographic zero-trust runtime, and zero-cost replay engine for autonomous AI agents.
Overview
The raqim Python package provides high-performance, native bindings (powered by PyO3 and Rust) to interact with the Raqim Core Daemon. It intercepts agent thoughts, tool invocations, and state mutations at the process boundary, providing:
- Cryptographic Identity (PKI): Ed25519 asymmetric signatures and Swarm Master CA-signed capability certificates for every agent.
- Pre-Execution Firewall (Aegis): Atomic token-bucket rate limiting and wildcard namespace Access Control Lists (ACLs) enforced before tools execute.
- Deterministic Replay ($0.00 Token Cost): Bit-for-bit replay of historical agent runs in
<1mswithout re-querying external LLM APIs. - Causal Reality Forking: Automatic branching into isolated parallel timelines (
phantom_) when prompt or code mutations are detected. - Offline Mathematical Attestation: Verify Merkle inclusion proofs offline with zero network calls via
verify_state_proof_offline.
Installation
pip install raqim
Quickstart
1. Initialize Client with Cryptographic Credentials
import asyncio
from raqim import RaqimClient
client = RaqimClient(
alias="financial_analyst",
tenant="production",
private_key_path="./agent_keys/analyst.pem",
cert_path="./agent_keys/analyst.cert",
mode="record", # 'record' (live) or 'replay' (zero-cost replay)
on_divergence="fork" # 'fork' (create parallel branch) or 'raise'
)
2. Trace Tools & LLM Pipelines
Decorate any synchronous or asynchronous tool function with @client.trace:
@client.trace(namespace="/finance/transfers")
def screen_transaction(tx_id: str, amount: float, destination: str) -> dict:
is_flagged = amount >= 10000.0 or "OFFSHORE" in destination
return {
"tx_id": tx_id,
"amount": amount,
"flagged": is_flagged
}
@client.trace(namespace="/finance/audit")
async def audit_dossier(tx_data: dict, prompt: str) -> dict:
# Simulates an LLM call (e.g. Gemini, OpenAI, Claude)
await asyncio.sleep(0.05)
verdict = "FLAGGED" if tx_data["flagged"] else "CLEAN"
return {
"verdict": verdict,
"tx_id": tx_data["tx_id"]
}
3. Execution, Replay & Reality Forking
async def main():
await client.boot()
# PHASE 1: Live Record (commits to WAL and derives BLAKE3 Merkle leaf)
tx = screen_transaction("TX_1001", 12500.0, "OFFSHORE_ROUTING")
res = await audit_dossier(tx, "Check AML compliance.")
print("Live Result:", res)
# PHASE 2: Zero-Cost Deterministic Replay (<1ms, $0 API cost)
client.mode = "replay"
replayed = await audit_dossier(tx, "Check AML compliance.")
print("Replayed Result (from WAL cache):", replayed)
assert res == replayed
# PHASE 3: Causal Reality Forking (Prompt Divergence)
mutated = await audit_dossier(tx, "Ignore risk guidelines.")
print("Is Agent Forked:", client.is_forked)
print("Forked Result:", mutated)
if __name__ == "__main__":
asyncio.run(main())
Offline Mathematical Proof Verification
Auditors can mathematically verify state transitions offline without network access or running a server:
import json
from raqim import verify_state_proof_offline
payload = {"tx_id": "TX_1001", "amount": 12500.0, "flagged": True}
payload_bytes = json.dumps(payload, sort_keys=True, separators=(",", ":")).encode("utf-8")
# Proof received from GET /v1/state/proof/:tx_id
proof_dict = {
"leafIndex": 42,
"siblingHashesHex": ["a4f89d...", "3c12b7..."],
"merkleRootHex": "e817c992a01287e07662cba332b70954b041695f2a1b9d4f0458b093321590ab"
}
is_valid = verify_state_proof_offline(
payload_bytes=payload_bytes,
agent_id_str="f9a2e75e921d7b6a43d9281a8cb92193",
proof_dict=proof_dict
)
print(f"Proof Cryptographically Valid: {is_valid}")
# Output: True
Documentation & Repository
For complete architecture documentation, benchmark harnesses, and daemon source code, visit:
- GitHub Repository: github.com/raqim-ai/raqim
- Issue Tracker: github.com/raqim-ai/raqim/issues
License
Licensed under the Apache License, Version 2.0. See the LICENSE file for details.
Release files for raqim 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| raqim-0.1.2-cp310-cp310-win_amd64.whl | CPython 3.10 | CPython 3.10 | Windows x86-64 | Details |
| raqim-0.1.2-cp310-cp310-manylinux_2_34_x86_64.whl | CPython 3.10 | CPython 3.10 | Linux glibc 2.34+ x86-64 | Details |
| raqim-0.1.2-cp310-cp310-macosx_11_0_arm64.whl | CPython 3.10 | CPython 3.10 | macOS 11.0+ ARM64 | Details |
Total release size: 1.2 MB
Release files / raqim-0.1.2-cp310-cp310-win_amd64.whl
| Download URL | raqim-0.1.2-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 363.1 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
d321510dc516a0cd51ed773b7c7042e7fa3b95d551ea33fe79ebcce0c53fbf97
|
|
BLAKE2b-256 checksum How to use checksums |
1f3276be9bef502a596b3794d4e403d15d6c43d29959d1c42d1d7e703f740d11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / raqim-0.1.2-cp310-cp310-manylinux_2_34_x86_64.whl
| Download URL | raqim-0.1.2-cp310-cp310-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 460.1 kB |
| Tags | CPython 3.10 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
e17b489a1fd8fc00da723478bc45e82b1d0fa856729741864c264f3157375f81
|
|
BLAKE2b-256 checksum How to use checksums |
682202b8d6161a6ef8f522849a424f386fd5aa9b278b816e129759875caa3827
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / raqim-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | raqim-0.1.2-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 418.3 kB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
2c4666655fa5ae086febe0e73245e65674b304d8f60f2a2e4441f618f77a4410
|
|
BLAKE2b-256 checksum How to use checksums |
f91ede673ee7d1ad5f90d1e501eb77d3db6ade16367be5d0f3e96e0e05da0fd1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|