Skip to main content

nlght-ai

The layer between your app and your LLM — workflows, tools, memory, any provider.

Tests Coverage PyPI

E2E scope note. The test badge covers the cloud model-client e2e suite (tests/e2e); each provider skips itself when its API key is absent. The local Ollama model-client suite (tests/local_e2e) is intentionally not run in CI — no Ollama daemon is available there — so its absence/skip is expected. It is verified locally against a running ollama serve with pytest tests/local_e2e -m local_e2e.


What it does

Client (OpenAI / Ollama API)
        ↓
  Protocol Detection
        ↓
  Trigger Resolution
        ↓
  Workflow Executor  ──→  Steps  ──→  Tools / Playbooks / LLM
        ↓
  Signal Emitter (streaming or batch)
        ↓
Client Response

A workflow is a sequence of steps. Each step receives a context with the current messages, an LLM client, a tool catalog, a playbook catalog, and optionally a session store (Hive Mind). Steps can call the LLM, use tools, read and write session memory, and emit results back to the caller — all without touching HTTP or protocol specifics.


Features

Feature Description
OpenAI-compatible API Drop-in replacement endpoint — works with any OpenAI client
Ollama API Native Ollama protocol support
Multi-provider Ollama, Anthropic Claude, OpenAI, Google Gemini
Workflow engine Stateless step machine with configurable routing
Tool system Register custom tools, call them from steps
Playbook catalog YAML-defined agent capabilities, loaded from filesystem
Session memory Hive Mind: tiered stores for directives, conversation, facts, working memory
Session routing Configurable SessionKeyResolver per protocol adapter
PostgreSQL persistence Workflow metadata and resource registry via SQLAlchemy
Ports & Adapters Clean hexagonal architecture — core has zero framework dependencies

Install

Install uv, then add nlght-ai to your project:

uv add nlght-ai

Optional extras:

uv add 'nlght-ai[anthropic]'   # Anthropic Claude
uv add 'nlght-ai[openai]'      # OpenAI / Azure OpenAI
uv add 'nlght-ai[google]'      # Google Gemini
uv add 'nlght-ai[hive-mind]'   # File-backed session memory
uv add 'nlght-ai[docker]'      # Docker OS runtime
uv add 'nlght-ai[web-search]'  # Web search tool

This declares nlght-ai in the project, so later uv sync and uv run commands keep it installed. For a standalone CLI that is independent of any project environment, use uv tool install nlght-ai instead.


Quickstart

1. Configure — create .config/platform.yaml:

licensing:
  license_key: YOUR-LICENSE-KEY   # free developer licenses available

protocol_adapters:
  - name: openai-http
    kind: openai
    enabled: true
    config:
      base_path: /v1
      model_provider: ollama
      session_key_resolver:
        resolver: header
        key: x-session-id

gateways:
  - name: http-gateway
    kind: http
    enabled: true
    config:
      host: 0.0.0.0
      port: 8000

integrations:
  persistence:
    workflows:
      backend: postgres
      url: postgresql+asyncpg://user:pass@localhost/nlght
  model_providers:
    - name: ollama
      kind: ollama-local
      config:
        base_url: http://localhost:11434
        default_model: llama3.2

2. Start PostgreSQL (matches the url above — for local development):

docker run -d --name nlght-postgres \
  -e POSTGRES_USER=user -e POSTGRES_PASSWORD=pass -e POSTGRES_DB=nlght \
  -p 5432:5432 postgres:16

3. Migrate the database (initial setup and after every upgrade):

uv run nlght-ai migrate

4. Start:

uv run nlght-ai serve
# NLGHT_CONFIG=./my-config.yaml uv run nlght-ai serve

5. Call:

curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "llama3.2", "messages": [{"role": "user", "content": "Hello!"}]}'

Writing a Step

from typing import ClassVar
from nlght.core.workflow.step import StepBase, StepResult, WorkflowStepContext

class SummarizeStep(StepBase):
    TYPE: ClassVar[str] = "summarize"

    async def run(self, ctx: WorkflowStepContext) -> StepResult:
        if ctx.llm is None:
            return StepResult(ctx=ctx, verdict="failed")
        system = "Summarize the conversation in three bullet points."
        await ctx.llm.call(messages=[{"role": "system", "content": system}] + ctx.messages)
        return StepResult(ctx=ctx, verdict="done")

Register and wire it up in your entrypoint, then reference it in a workflow definition stored in the database.


Session Memory (Hive Mind)

Hive Mind gives each session four persistent stores:

  • DirectiveStore — behavioral rules, set by tools or steps
  • ConversationStore — turn summaries across requests
  • SessionResultStore — promoted, validated session facts and evaluation outcomes; never raw LLM responses (survives restarts)
  • WorkingMemory — transient task-scoped atoms, cleared after each task

Two coordinators — simple (in-memory) and filesystem (file-backed):

integrations:
  persistence:
    hive_mind:
      provider:
        kind: filesystem
        config:
          base_dir: ./.sessions

Use SystemPromptBuilder with an explicit PromptInputPolicy to select the session context that enters the prompt:

from nlght.core.hive_mind.system_prompt import PromptInputPolicy, SystemPromptBuilder

builder = SystemPromptBuilder()
system = builder.build(
    mental_model=model,
    ego="You are a helpful assistant.",
    input_policy=PromptInputPolicy(
        include_directive_store=True,
        include_conversation_store=True,
        include_working_memory=True,
        include_session_result_store=True,
    ),
)

Demo

The Demo Showcase introduces six complete workflows across grounding, tools, routing, session memory, and isolated runtime execution. Setup, migration, and run requirements are maintained by the demo repository linked there.


Model Providers

Provider Extra Config kind
Ollama (local) (none) ollama-local
Anthropic Claude [anthropic] anthropic
OpenAI [openai] openai
Google Gemini [google] google

Architecture

nlght-ai follows a strict hexagonal (ports & adapters) architecture:

  • core/ — domain logic, zero framework dependencies, no I/O
  • ports/ — Protocol interfaces for every external concern
  • adapters/inbound/ — HTTP (FastAPI), protocol detectors
  • adapters/outbound/ — Model clients, persistence, tools, Hive Mind, OS runtime
  • application/ — Use-case services wiring ports together
  • bootstrap/ — DI container, startup, config loading

See the nlght-ai documentation for the full user documentation.


Requirements

  • Python 3.11+
  • PostgreSQL (for workflow metadata and resource registry)
  • A model provider (Ollama recommended for local development)

Development

Dependencies are pinned in uv.lock for a reproducible environment. With mise (see mise.toml — pins Python 3.13 and uv):

mise install
uv sync
uv run pytest -q -m "not e2e and not integration"
uv run ruff check src tests

The default dev group installs nlght-ai[all], so local development and CI exercise every portable runtime capability. Accelerator-specific embedding-cpu and embedding-cuda remain explicit machine choices.

uv sync --locked (used in CI) fails instead of silently re-resolving if pyproject.toml and uv.lock have drifted apart — run uv lock after changing dependencies and commit the updated lockfile.

Metadata

Release files for nlght-ai 0.1.3

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

Source distribution (sdist)

Source distribution for nlght-ai 0.1.3
File Size Uploaded Provenance Actions
nlght_ai-0.1.3.tar.gz 715.2 kB With provenance Details for nlght_ai-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nlght-ai 0.1.3
File Interpreter ABI Platform Actions
nlght_ai-0.1.3-py3-none-any.whl Python 3 none any Details for nlght_ai-0.1.3-py3-none-any.whl

Total release size: 1.6 MB

Release files / nlght_ai-0.1.3.tar.gz

Download URL nlght_ai-0.1.3.tar.gz
Size 715.2 kB
Tags Source
SHA-256 checksum
How to use checksums
fbeaa0c19b699b35e2822db8acb5df5421b5a80405b50ebb622994e13a9acb92
BLAKE2b-256 checksum
How to use checksums
1dc3a41424f05698a139910d4e32c37fca305479f1c2291636d69f0cfc12236e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.

Transparency log

Release files / nlght_ai-0.1.3-py3-none-any.whl

Download URL nlght_ai-0.1.3-py3-none-any.whl
Size 932.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
91f4919b33acc5b0e2ce9d96eca43b8a0e71039d3462696e93541c6309b20147
BLAKE2b-256 checksum
How to use checksums
877f1be7abcf92ada7355146f341a0cde953d803694f16f25391d839956e237f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.

Transparency log

Security for nlght-ai 0.1.3

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nlght_ai-0.1.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.

Transparency log

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