A Python library providing key functional primitives for research in multimodal language models, agentic AI, and knowledge graphs, featuring unified model invocation, multi-agent collaboration and debate, knowledge graph lifecycle management, and multimodal generation.
npcpy is built around the NPC Context-Agent-Tool three-layer architecture, providing complete abstractions from low-level model invocation to high-level agent orchestration.
At the model invocation layer, the unified get_llm_response() interface supports local backends (Ollama, llama.cpp, OMLX, LM Studio) and cloud backends (Gemini, OpenAI), with streaming output, JSON/Pydantic structured output, and more.
The agent system offers four agent types: NPC (persona agent defined by name and primary_directive), Agent (with built-in tools like sh, python, edit_file, web_search), ToolAgent (mountable custom tool functions), and CodingAgent (auto-executing LLM-returned code blocks).
For multi-agent collaboration, Team orchestrates multiple NPCs; NPCArray provides NumPy-style vectorized operations with .infer() for parallel inference, .chain() for chain-of-thought refinement, and .consensus() for consensus aggregation; the multi-agent debate mechanism generates personalized prompts containing other agents' responses for each agent per round, supporting iterative multi-turn debates.
The knowledge graph and memory layer implements a full lifecycle: kg_initial() for corpus-based initialization, kg_evolve_incremental() for incremental evolution, kg_sleep_process() for consolidation and pruning, kg_dream_process() for speculative connection generation, plus Sememolution population-based evolution.
The multimodal and fine-tuning layer supports image/audio/video generation (via Ollama, diffusers, OpenAI, Gemini), along with SFT, RL, diffusion model fine-tuning (DiffusionConfig), and genetic algorithm evolution.
For workflows and serving, Jinx implements multi-step prompt pipelines based on Jinja templates, Skills support progressive paragraph disclosure, and start_flask_server() deploys NPC teams as REST APIs, integrating with the Incognide GUI frontend. Additional utilities include OCR, Scikit-learn ML functions, and database persistence (NPCSQL).
Installation: pip install npcpy (optional extras: lite, local, yap, all)
Organization: NPC-Worldwide Author: Christopher Agostino (PyPI: caug37)