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.2.tar.gz (37.7 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.2-py3-none-any.whl (39.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nocturnusai-0.2.2.tar.gz
  • Upload date:
  • Size: 37.7 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.2.tar.gz
Algorithm Hash digest
SHA256 e14ad1b2223b2e840dd32d9b59941c93bb58599a2df08bf66160cc4e79676786
MD5 b469b6fdb157ed952286c84a63a03893
BLAKE2b-256 dae2acc57d41096f5076e2a66430b65543e0940b415255644d0a4422686d5b10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nocturnusai-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 39.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bab031738822b7e7b8ad43af9891175e2c4bb0a879e60c42c4d694a46def930c
MD5 a6b5bee102fd4df363e8a891f7fe6d43
BLAKE2b-256 a97d02554decede778fa71e29c317bd31b3ef861a54f425eaaf0712795672a03

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