Skip to main content

Ejentum Python SDK

PyPI Version License: MIT Latency

The official Python SDK for Ejentum: Deterministic Reasoning-Augmented Retrieval (RAR) Cognitive Infrastructure.

Ejentum indexes 300+ deterministic mental models and cognitive scaffolds. In less than 80ms, it retrieves and injects the optimal reasoning scaffold into your LLM prompt, eliminating hallucinated leaps, sycophantic shortcuts, and premature convergence in production AI agents.


Official Resources


Installation

pip install ejentum

Zero dependencies required. Uses Python standard library only. Optional framework integrations for OpenAI, Anthropic, LangChain, LangGraph, and CrewAI.


Authentication

Export your API key in your environment (or pass api_key="..." directly to the client):

export EJENTUM_API_KEY="ej_live_your_key_here"

Need an API key? Get instant access at ejentum.com/pricing.


Quickstart

1. Basic Scaffold Retrieval

from ejentum import Ejentum

client = Ejentum()

# Retrieve the deterministic cognitive scaffold for any query (<80ms)
scaffold = client.scaffold("diagnose PostgreSQL high CPU and lock contention")
print(scaffold)

2. Auto-Augment a Prompt

# Automatically prepends the scaffold instruction block to your task prompt
prompt = "Design a failover strategy for our payment processing service."
augmented_prompt = client.augment(prompt, mode="reasoning")

print(augmented_prompt)
# Output:
# Apply the cognitive scaffold below, then answer the user's task.
# [COGNITIVE SCAFFOLD]
# ... [Deterministic Causal / Resiliency Scaffold] ...
# [END SCAFFOLD]
# Design a failover strategy for our payment processing service.

3. Recursive Multi-Hop Cognitive DAG (depth=2)

For complex agent workflows, generate a recursive Directed Acyclic Graph (DAG) across the 933-edge synergy graph with an automated 4-stage execution plan:

# Retrieve 2-hop topological execution plan and compound scaffold
graph_plan = client.graph("Migrate 50M rows across sharded PostgreSQL database", depth=2)

print("Root Operator:", graph_plan["dag"]["root"])
print("Execution Stages:", len(graph_plan["dag"]["execution_plan"]))
for stage in graph_plan["dag"]["execution_plan"]:
    print(f"  Stage {stage['stage']} ({stage['phase']}): {stage['abilities']}")

# Injects 4-stage cognitive scaffold (prerequisites -> root -> compounding multipliers -> fallbacks)
scaffold = graph_plan["graph_scaffold"]

Perform lightning-fast full-text keyword searches with BM25 ranking across the 311 ability catalog:

# Sub-1ms SQLite FTS5 query
results = client.fts_search("deadlock circular dependency sequence", limit=3)

for match in results["results"]:
    print(f"[{match['ability_id']}] {match['ability_name']} ({match['domain']}) - Rank: {match['rank']}")

Drop-in Wrappers

OpenAI Drop-in

Wrap your existing OpenAI() client. All chat.completions.create calls will automatically fetch and inject the optimal Ejentum scaffold before invoking OpenAI:

from openai import OpenAI
from ejentum import wrap_openai

# Wrap your existing client in 1 line:
client = wrap_openai(OpenAI())

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": "Diagnose silent failure in checkout webhooks"}
    ],
    ejentum_mode="reasoning"  # Optional: defaults to "reasoning"
)

print(response.choices[0].message.content)

Anthropic Drop-in

from anthropic import Anthropic
from ejentum import wrap_anthropic

client = wrap_anthropic(Anthropic())

response = client.messages.create(
    model="claude-3-7-sonnet-20250219",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Refactor auth token refresh to prevent race condition"}
    ]
)

print(response.content[0].text)

LangChain and Agent Loop Integration

from ejentum import Ejentum
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

ejentum = Ejentum()

def scaffold_runnable(inputs):
    scaffold = ejentum.scaffold(inputs["task"])
    return {
        "system_scaffold": f"Apply this scaffold:\n{scaffold}",
        "task": inputs["task"]
    }

prompt = ChatPromptTemplate.from_messages([
    ("system", "{system_scaffold}"),
    ("user", "{task}")
])

chain = scaffold_runnable | prompt | ChatOpenAI(model="gpt-4o")
result = chain.invoke({"task": "Plan a zero-downtime database migration for 50M rows."})

Advanced Architecture (v1.8.0)

Multi-Agent Handshake Engine

Prevent agent communication collapse, circular delegation, and assumption compounding with deterministic runtime contracts:

from ejentum import HandshakeEngine, AgentRole, get_preset_topology

engine = HandshakeEngine(topology=get_preset_topology("hierarchical_triage"))
contract = engine.propose(
    sender_role=AgentRole.COORDINATOR,
    recipient_role=AgentRole.SPECIALIST,
    task_scope="Verify database schema migrations against lock contention limits"
)
print("Contract Verified:", contract.status)

Temporal Policy Guard

Enforce strict ordering constraints, required prerequisites, and forbidden actions across multi-step execution traces:

from ejentum import TemporalGuard, RequirePriorRule, ForbidFollowingRule

guard = TemporalGuard(rules=[
    RequirePriorRule(action="execute_transaction", required_prior="acquire_idempotency_lock"),
    ForbidFollowingRule(action="delete_record", forbidden_following="read_record")
])

Enterprise Checkpoint Storage

State management with swappable backends:

from ejentum import create_checkpoint_store

# Supported: memory, file, redis, s3, gcs
store = create_checkpoint_store("memory")
store.save_checkpoint("session_123", {"step": 4, "state": "verified"})

API Reference

Ejentum(api_key=None, base_url="https://api.ejentum.com/logicv1/", timeout=10.0)

  • scaffold(query: str, mode="reasoning") -> str: Returns the raw cognitive scaffold string for system prompt injection.
  • graph(query: str, depth: int = 1) -> dict: Returns the Cognitive DAG across the 933-edge synergy graph. Supports depth=1 and depth=2 (4-stage recursive execution plan).
  • fts_search(query: str, limit: int = 4) -> dict: Executes sub-millisecond SQLite FTS5 full-text keyword search and BM25 ranking.
  • augment(prompt: str, mode="reasoning") -> str: Prepends the cognitive scaffold instruction block directly to your prompt string.
  • augment_messages(messages: list[dict], mode="reasoning") -> list[dict]: Augments an OpenAI/Anthropic messages list in-place or prepends to the system message.
  • feedback(ability_id: str, outcome="success", score=1.0, query="", comment="") -> dict: Submits execution telemetry to calibrate adaptive retrieval weights.
  • get_ability(query: str, mode="reasoning") -> dict: Returns the full metadata payload including ability_id and matched domain.

License

MIT (c) Ejentum.com

Metadata

Release files for ejentum 1.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ejentum 1.8.0
File Size Uploaded Provenance Actions
ejentum-1.8.0.tar.gz 67.0 kB Without provenance Details for ejentum-1.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ejentum 1.8.0
File Interpreter ABI Platform Actions
ejentum-1.8.0-py3-none-any.whl Python 3 none any Details for ejentum-1.8.0-py3-none-any.whl

Total release size: 125.7 kB

Release files / ejentum-1.8.0.tar.gz

Download URL ejentum-1.8.0.tar.gz
Size 67.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ffdf200249bd314bd417d6f1487469bdf51fff35a798326c0cf39ab78175fb7a
BLAKE2b-256 checksum
How to use checksums
d4babf38b966218e2843d9676620ba1206b2c3a6d57329142771eda8b995e0ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / ejentum-1.8.0-py3-none-any.whl

Download URL ejentum-1.8.0-py3-none-any.whl
Size 58.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
452c623312a7265c2279634a3e460aaf8c1e2340eb63e5c41e654d9edaf362da
BLAKE2b-256 checksum
How to use checksums
a708de132617b66898b986d93e8cba25ad003a2de8e9dde540b13d3147b5f384
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for ejentum 1.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page