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.4.tar.gz (40.0 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.4-py3-none-any.whl (42.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nocturnusai-0.2.4.tar.gz
  • Upload date:
  • Size: 40.0 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.4.tar.gz
Algorithm Hash digest
SHA256 1bee7992cda02d9c3f99362670f081aad96fee13a6c10a9cb5a88c093b73b140
MD5 fad31b158f0767649f75dbba6a71bc82
BLAKE2b-256 c1b334094039b37685400d5380b336efa348325c032f097379281463c7d5d8fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nocturnusai-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 42.0 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a5c6c8ef93ab386ca78fbd4c82063701ba4af2efd472fbe045a9e7382f5344ed
MD5 61ebe380560b1ace0a6732c3026f1a29
BLAKE2b-256 18b34527b8146d14179ece139adaf8b9c80811436acc3eedd4812a69c1045a92

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