Skip to main content

A nano, minimalistic, and lightweight library for building ReACT-based AI agents.

Project description

NKit โ€” Production Safety Layer for Agentic AI

Live observability, pre-execution safety, and audit trails for any agent framework.

NKit is a nano, minimalistic, production-ready framework for building ReAct agents, or wrapping your existing ones. It focuses natively on ensuring that agents are safe, compliant, and observable before they execute destructive actions, solving the biggest blockers to enterprise AI adoption.


๐Ÿ›‘ Why NKit? (The Missing Safety Layer)

Most agent frameworks focus on chaining together LLM queries but treat production safety as an afterthought. NKit was built specifically to solve three critical problems:

  1. Pre-Execution Intent Verification: Other frameworks let tools run immediately. NKit's SafetyGate pauses and evaluates an agent's intent before execution, blocking misaligned goals or destructive actions automatically (with an optional HITL fallback).
  2. The Why Log: Classic logging tells you "Agent executed query DROP TABLE users". NKit's WhyLog creates a structured JSONL audit trail capturing the exact chain of thought that led to that hallucinated conclusion.
  3. Live Decision Streaming: NKit ditches post-mortem log scraping in favor of a real-time event bus (LiveObserver), allowing developers and compliance teams to monitor decisions live.

โšก Quick Start

from nkit.agent import Agent
from nkit.llms import OllamaLLM
from nkit.observer import LiveObserver

# 1. Start live observer
observer = LiveObserver()

@observer.on("tool.before")
def watch_intent(e):
    print(f"Agent attempting {e['tool_name']} because: {e['why']}")

# 2. Hook up local LLM
llm = OllamaLLM(model="llama3")

# 3. Mount and run
agent = Agent(llm=llm.complete, observer=observer)
agent.run("Summarize the current market trends")

๐Ÿ— Core Concepts

  • Observer (nkit.observer): Intercepts the core ReAct loop allowing developers to use asynchronous @observer.on() listeners to monitor the start, thoughts, tool pre-execution, and results of actions dynamically.
  • SafetyGate (nkit.safety): Pre-execution middleware that heuristically and conditionally blocks path-escapes, destructive keywords, and untrained domain accesses. Supports HITL (Human-in-the-loop) approvals.
  • WhyLog (nkit.audit): Extensively formats the trace-history into a rotating 10MB audit.jsonl log file, embedding the thought-process behind every single external action.

๐Ÿง  Supported LLM Providers

NKit provides pure, bloat-free urllib-based LLM adapters ensuring you aren't dragging in multi-megabyte SDKs just to query an API:

  • OllamaLLM: Calls localhost (llama3, phi3, mistral).
  • OpenAILLM: Calls OpenAI (gpt-4o) with native exponential backoff.
  • AnthropicLLM: Calls Anthropic (claude-3-opus).
  • OpenRouterLLM: Universal model passthrough to api.openrouter.ai.

๐Ÿ“š Examples

Explore the /examples directory to see NKit in action:

  1. local_agent.py: A fully local agent using Ollama and the WhyLog.
  2. safe_file_agent.py: Demonstrates the SafetyGate isolating an agent within a sandbox.
  3. multi_agent_research.py: Multi-agent task orchestration tracked via Observer.
  4. enterprise_audit_demo.py: An enterprise use-case mimicking a logistics compliance workflow.
  5. framework_wrapper_demo.py: Wraps a mock LangChain agent into the NKit LiveObserver to prove interoperability.

โœ… Production Checklist

Out of the box, NKit provides:

  • Pre-Execution Safety Interceptors & Human-in-The-Loop.
  • Asynchronous real-time observation streaming.
  • Centralized, stateful Audit Logging (WhyLogs).
  • Hard bounds on executions: 30s Tool Timeouts, 10KB Result Sizing, Max Retries limiting.
  • Security-principled path sandboxing and String parsing.

๐Ÿ—บ Architecture

 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚   User Prompt   โ”‚ โ”€โ”€โ”€โ”€โ–ถ โ”‚  Agent / Crew   โ”‚ โ”€โ”€โ”€โ”€โ–ถ โ”‚   LLM Adapter   โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                   โ”‚
                                   โ–ผ
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” (Triggers agent.reasoning)
                         โ”‚  Live Observer  โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                   โ”‚
                                   โ–ผ
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” (Evaluates Risk & HITL)
                         โ”‚   Safety Gate   โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                   โ”‚
                                   โ–ผ
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” (Logs the "Why")
                         โ”‚     WhyLog      โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                   โ”‚
                                   โ–ผ
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” (Timeout bounds & limits)
                         โ”‚ Tool Execution  โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿค Contributing

NKit adheres strictly to SOLID design principles. No single module should become a God class. Features must be injected as plugins via interfaces. If extending NKit, remember its north star: Security, safety, and observability above all else. Pull requests are welcome!

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

nkit_agents-0.2.1.tar.gz (105.8 kB view details)

Uploaded Source

Built Distribution

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

nkit_agents-0.2.1-py3-none-any.whl (132.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nkit_agents-0.2.1.tar.gz
  • Upload date:
  • Size: 105.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for nkit_agents-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f290c5d2ea3b5ee11445c8a832a18734848a196fdd8b43b45142700764a7d954
MD5 8e3b0d687d142a3e248145a2a428363d
BLAKE2b-256 add6f791e2b7508bc65ff8732514525d828a87b4002ef5d893ed82373c045503

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nkit_agents-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 132.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for nkit_agents-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b55eabe5f028b88baa4fe1e1e1c9d51ba781786226751286a92df97d361e4780
MD5 93f0791e7fe499465bd6a19f29c31cc4
BLAKE2b-256 dcfcfb00ee323c3908a544278f33adc39495b13f7e0ecfd9220b17a6125c4b83

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