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:
- Pre-Execution Intent Verification: Other frameworks let tools run immediately. NKit's
SafetyGatepauses and evaluates an agent's intent before execution, blocking misaligned goals or destructive actions automatically (with an optional HITL fallback). - The
Why Log: Classic logging tells you "Agent executed queryDROP TABLE users". NKit'sWhyLogcreates a structured JSONL audit trail capturing the exact chain of thought that led to that hallucinated conclusion. - 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 10MBaudit.jsonllog 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:
local_agent.py: A fully local agent using Ollama and the WhyLog.safe_file_agent.py: Demonstrates the SafetyGate isolating an agent within a sandbox.multi_agent_research.py: Multi-agent task orchestration tracked via Observer.enterprise_audit_demo.py: An enterprise use-case mimicking a logistics compliance workflow.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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f290c5d2ea3b5ee11445c8a832a18734848a196fdd8b43b45142700764a7d954
|
|
| MD5 |
8e3b0d687d142a3e248145a2a428363d
|
|
| BLAKE2b-256 |
add6f791e2b7508bc65ff8732514525d828a87b4002ef5d893ed82373c045503
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b55eabe5f028b88baa4fe1e1e1c9d51ba781786226751286a92df97d361e4780
|
|
| MD5 |
93f0791e7fe499465bd6a19f29c31cc4
|
|
| BLAKE2b-256 |
dcfcfb00ee323c3908a544278f33adc39495b13f7e0ecfd9220b17a6125c4b83
|