How navuluribalaji/nkit works
Project Type and Purpose
• This is a Python library (package) for building “agents” around large language models (LLMs).
• It provides an Agent façade that handles prompts, async/sync calls, built-in tools (web search, file I/O, time), logging, error handling, retries, and tool registration.
File Structure
• Top-level packages:
• nanoagents/ – the original internal implementation
• nkit/ – the public API with Agent, chain, memory, tools, utils
• Key modules:
• Agent orchestration: nbagents.py (Agent class, run/run_async)
• Chain logic: chain.py, chain/ directory (step sequencing)
• LLM adapter: llm_adapter.py (sync vs async LLM calls)
• Memory: memory.py, memory/ directory (context storage)
• Prompt: prompt.py (templates, formatting)
• Tools: tools.py, tools/ (Tool class, registry, built-ins)
• Utils: utils.py (helpers for async detection, retries, logging setup)
• Config/build files: pyproject.toml, .github/workflows/ci.yml, scripts/test_poetry.ps1
README Insights
• Core features: async support, built-in tools, logging, error handling, tool registry, agent configuration.
• Usage: Agent instantiation → run/run_async → LLM calls + tool calls → output.
• Dependencies: requests, aiohttp, asyncio, logging.
Components
a. Main Components
• Client/User (invokes Agent API)
• Agent (Agent class façade)
• Chain Manager (Chain class)
• Prompt Manager (Prompt templates)
• LLM Adapter (sync/async wrapper)
• Tool Registry & Built-in Tools
• Memory Store
• Logger (cross-cutting)
• External Services:
– LLM Service (OpenAI/other)
– DuckDuckGo API
– File System
b. Relationships & Data Flows
1. Client → Agent.run()/run_async()
2. Agent → Prompt Manager formats user query
3. Agent → Chain Manager drives multi-step reasoning
4. Chain → LLM Adapter → External LLM Service
5. Chain → Tool Registry → Specific Tool
• WebSearchTool → DuckDuckGo API
• FileTools → File System
• TimeTool → System clock
6. Chain/Agent → Memory Store (read/write context)
7. All components → Logger for events, errors, retries
8. Agent returns final output to Client
c. Architectural Patterns & Principles
• Facade Pattern: Agent class hides internal complexity
• Strategy/Adapter Pattern: LLM Adapter isolates sync vs async calls
• Registry Pattern: Tool registration and auto-discovery
• Chain of Responsibility: Chain Manager sequences LLM calls and tool calls
• Cross-cutting Concerns: Logging and error handling injected throughout
d. Key Technologies
• Python 3.9+ with asyncio
• requests / aiohttp for HTTP calls
• logging module for configurable logs
• pyproject.toml + poetry for packaging