Skip to main content

Python SDK for NocturnusAI — a logic-based inference engine and knowledge database

Project description

NocturnusAI Python SDK

Python SDK for NocturnusAI.

The primary use case is context reduction for agent applications:

  1. ingest raw text or turns
  2. build a smaller working set
  3. narrow by goal
  4. reuse diffs on later turns

Lower-level fact, rule, inference, and memory APIs are still available when you need backend mechanics.

Install

pip install nocturnusai
pip install "nocturnusai[langchain]"   # optional LangChain tools

Context-first quick start

from nocturnusai import SyncNocturnusAIClient

with SyncNocturnusAIClient("http://localhost:9300") as client:
    ctx = client.ingest_and_optimize(
        text="""
        user: Customer says they are enterprise and blocked on SLA credits.
        tool: CRM says account is Acme Corp with a 2M ARR contract.
        tool: Billing note says renewal is due next month.
        """,
        goals=[{"predicate": "eligible_for_sla", "args": ["acme_corp"]}],
        max_facts=12,
        session_id="ticket-42",
    )

    diff = client.diff_context(
        session_id="ticket-42",
        goals=[{"predicate": "eligible_for_sla", "args": ["acme_corp"]}],
        max_facts=12,
    )

    client.clear_context_session("ticket-42")
    print(ctx.total_facts_included, len(diff.added))

Key context methods

  • context_window() -> POST /memory/context
  • optimize_context() -> POST /context/optimize
  • diff_context() -> POST /context/diff
  • summarize_context() -> POST /context/summary
  • clear_context_session() -> POST /context/session/clear
  • ingest_and_optimize() -> extract text, assert, then optimize

Lower-level logic methods

from nocturnusai import SyncNocturnusAIClient

with SyncNocturnusAIClient("http://localhost:9300") as client:
    client.assert_fact("parent", ["alice", "bob"])
    client.assert_rule(
        head={"predicate": "grandparent", "args": ["?x", "?z"]},
        body=[
            {"predicate": "parent", "args": ["?x", "?y"]},
            {"predicate": "parent", "args": ["?y", "?z"]},
        ],
    )
    print(client.infer("grandparent", ["?who", "bob"]))

LangChain integration

from nocturnusai import SyncNocturnusAIClient
from nocturnusai.langchain import get_nocturnusai_tools

client = SyncNocturnusAIClient("http://localhost:9300")
tools = get_nocturnusai_tools(client)

MCP helper

from nocturnusai.mcp import NocturnusAIMCPClient

async with NocturnusAIMCPClient("http://localhost:9300") as mcp:
    await mcp.initialize()
    tools = await mcp.list_tools()
    result = await mcp.call_tool("context", {"maxFacts": 10, "minSalience": 0.1})
    print(result.text)

Start the server

# Docker
docker run -p 9300:9300 ghcr.io/auctalis/nocturnusai:latest

# or installer
curl -fsSL https://raw.githubusercontent.com/Auctalis/nocturnusai/main/install.sh | bash

Docs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nocturnusai-0.2.1.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

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

nocturnusai-0.2.1-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file nocturnusai-0.2.1.tar.gz.

File metadata

  • Download URL: nocturnusai-0.2.1.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nocturnusai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d4e0e6daa51bd67e080add08e4dc28d5102874a3fdfcfb6013423e65a772e716
MD5 0b55d3e07841e5ddf313864b61226afd
BLAKE2b-256 2b8fe921deef1992bce975fc1977bc870e7f4fd22319306e8113962075d3aaed

See more details on using hashes here.

File details

Details for the file nocturnusai-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: nocturnusai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nocturnusai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a70fc466a6f61b182297c1d29ef503c4ae1978b54c3120dee535be33dfe4a801
MD5 3707c8d66d4e781943441a13ab930b82
BLAKE2b-256 518e9c869351bbcc4ede1433d35a474951ccfc8fae8de3c696fed4007c836fb2

See more details on using hashes here.

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