Project Philosophy
Project Philosophy
Overview
LevPRO AI runtime is built on a philosophy of local-first, minimal-dependency, and architecture-aware design. Every decision serves the goal of running sophisticated AI agents entirely on local hardware without cloud dependencies or framework bloat.
Local AI-First Approach
Why Local?
- Privacy - Your data never leaves your machine
- Control - Full control over what runs and how
- Cost - No API calls, no monthly subscriptions
- Latency - No network round trips
- Reliability - Works offline, no service dependencies
Local-First Principles
Never (by default):
- Send prompts to external APIs
- Rely on cloud services
- Use APIs with rate limits or costs
- Trust external services with sensitive data
Opt-in exceptions (explicit config + host MCP):
- Network/HTTP capability tools only via host
mcp.json(stdio or HTTP MCP servers) — Core does not ship a built-inhttp_fetch/[net]package - No cloud LLM APIs; any network use is user-controlled through MCP servers and local-first by default
Always:
- Process locally (LLM inference via llama-server)
- Store locally (sessions, memory; optional workspace root for skills)
- Control locally (config, MCP allowlists,
ApprovalGateforrequires_approvaltools) - Own your data
Use of llama.cpp
Why llama.cpp?
- Open source - MIT license, no restrictions
- Efficient - Highly optimized C++ implementation
- Portable - Works on Windows, Linux, macOS
- Quantization - Supports multiple quantization levels
- GPU support - CUDA, ROCm, Metal
- Active development - Regular updates
llama.cpp Integration
HTTP Server:
- OpenAI-compatible
/v1/chat/completions - Native
/tokenizeendpoint /healthfor monitoring- Standard HTTP (no special protocol)
Launch Parameters:
- Context size (ctx-size)
- GPU layers (n-gpu-layers)
- Batch sizes (batch-size, ubatch-size)
- CPU threads (threads, threads-batch)
- Flash attention (flash-attn)
- Cache types (cache-type-k/v)
Why HTTP?
- Language-agnostic (Python, Go, C++, etc.)
- Standardized (OpenAI compatibility)
- Easy to monitor and restart
- No language binding required
Use of Markdown Memory
Why Markdown?
- Human-readable - Read without special tools
- Portable - Works everywhere, no format dependencies
- Version control - Git-friendly
- Searchable - Easy to index and search
- Toolable - Easy to parse and process
- Backed up - Simple copy for backup
Memory Design Principles
Structure:
- Organized by category
- Separated by user
- Indexed for fast retrieval
- Versioned (Git)
Content:
- Plain text with Markdown formatting
- No binary formats
- No proprietary databases
- No encryption (unless user wants)
Retrieval:
- 3-stage indexed RAG (BM25 or hybrid → LLM select → load)
- Default
memory.search_mode: bm25— no embeddings required - Optional
memory.search_mode: hybrid— BM25 + locally computed embeddings (stored as JSON undermemory_data/.embeddings/, via llama-server embed endpoint; falls back to BM25 when unavailable) - Token-budget aware
Why Not Vector Databases?
- Overkill - BM25 index search is sufficient for most local knowledge bases
- Complexity - No separate vector DB process or proprietary storage
- Cost - No specialized hardware or cloud embedding APIs
- Latency - File-based RAG index + optional local embeddings is fast for typical knowledge-base sizes
- Simplicity - Embeddings are plain JSON files alongside Markdown; easy to inspect, backup, and version
When to enable hybrid search:
- Semantic similarity matters beyond keyword overlap
- Larger knowledge bases where BM25 alone misses relevant files
- Still local-only: embeddings computed and stored on disk, not in a cloud vector service
Avoiding Mandatory Cloud Services
No Cloud Dependencies
Current design:
- No mandatory external API calls or cloud LLM services
- No network dependencies required beyond local llama-server (optional HTTP tools via host MCP)
- Zero cloud services required
- Zero authentication services
What this means:
- Works fully offline with default config (core + llama-server only)
- No account required
- No data collection
- No privacy concerns from cloud inference
- No dependency on external service uptime for the agent loop
llama-server Requirements
Minimal external dependency:
- Only needs llama-server binary
- No cloud registration
- No API keys
- No authentication
What you need:
- llama.cpp build with HTTP support
- GGUF model file
- That's it
Minimizing Dependencies
Dependency Philosophy
Rule of thumb:
- If Python standard library can do it, use it
- If it's essential, use well-maintained packages
- Never add dependencies for convenience
Current Dependencies
Monorepo layout (2.0): Core stays lean. Capability tools come from MCP (local-ai-mcp hard dep + host mcp.json). Optional extras are memory, ensemble, skills, monitor, and autotune — wired in app.py when installed and config-enabled.
local-ai-core dependencies:
llama-tools— planner/doctor stack (transitive:gguf,psutil,py-cpuinfo,httpx,pyyaml)local-ai-mcp— lazy MCP bridge (stdio + HTTP)httpx— async HTTP client to llama-serverjsonschema— JSON Schema validation for tool argspyyaml— YAML configurationjinja2— per-agentprompt_filestemplate stackjson-repair— salvageable tool-call JSON inToolParsercascade (no regex extraction)
Optional validation:
pydantic— optional stricter config validation when installed (config/pydantic_models.py)
Optional extras (separate packages):
local-ai-memory,local-ai-ensemble,local-ai-skills,local-ai-monitor,local-ai-autotune,local-ai-quantize(viallama-tools[quantize])
Embed via SessionRunner or use built-in interfaces (local-ai cli, local-ai serve-stdio, local-ai health).
Why These?
- Well-maintained - Active development
- Well-tested - Production-grade
- Community-supported - Bug fixes, contributions
- No forks - Use upstream, not forks
- No enterprise - No proprietary dependencies
Avoiding Frameworks
No LangChain:
- Too heavy for simple use cases
- Cloud dependencies
- Proprietary components
- Bloated dependencies
No LlamaIndex:
- Overkill for local use
- External dependencies
- Heavy memory footprint
No LangGraph:
- Unnecessary complexity
- State management already handled
- No distributed features needed
Modular Monorepo Principles
Optional by Default
Pattern:
- Core ships with native recovery tools, session persistence, supervised llama-server, ReAct loop, and MCP bridge
- Extended stacks (memory, ensemble, skills, monitor, autotune) are separate pip packages activated by install + config flag
- Capability tools come from host
mcp.jsonvia hard-deplocal-ai-mcp - Protocol interfaces with null implementations (
NullMemoryRetriever,NullSkillsRetriever) keep core tests and minimal installs working without optional deps - Single
AppContext/SessionRunner/AgentLoop— no duplicated agent logic across interfaces or extras
Why:
- Minimal install for embedding and CI
- Clear security boundaries (DirectoryGuard, MCP
requires_approval, host-owned mcp.json) - Users pay dependency and complexity cost only for features they enable
Project Scaling Principles
Design for Growth
Current scale:
- Single or multi-model (ensemble) via optional
[ensemble]extra - Capability tools via MCP (
mcp.json); native recovery tools in Core - Markdown memory (optional
[memory]extra) with L0–L3 runtime state and indexed RAG inmemory_data/ - Built-in crash/OOM
GracefulDegradationtiers in core; optional[monitor]extra adds proactive RAM/VRAM polling
Future considerations:
- Database memory (optional, alongside file-based L0–L3)
- Distributed execution across instances
- Richer multi-agent coordination
Scaling Guidelines
Horizontal scaling:
- Multiple instances of app
- Shared state via filesystem
- Session isolation
Vertical scaling:
- More RAM for larger models
- More GPU for faster inference
- More CPU for parallel processing
Tool scaling:
- Register tools dynamically
- Validate each tool
- Rate limit if needed
Memory scaling:
- Category-based organization
- User-based isolation
- Index-based retrieval
Backward Compatibility
Configuration:
- Forward-compatible (extra keys ignored)
- Backward-compatible (old configs work)
- Migration paths documented
API:
- Versioned endpoints
- Deprecation warnings
- Migration guides
Storage:
- Versioned format
- Migration scripts
- No breaking changes
Documentation as Code
Self-documenting:
- Type hints everywhere
- Docstrings for public APIs
- Examples in code
External documentation:
- Architecture docs
- API reference
- User guides
- Examples
Decision Rationale
Why Not SQLite?
- File-based is sufficient - JSON works for our needs
- No locking complexity - Avoid database locking
- Easier to backup - Simple file copy
- No migrations - Schema changes are code changes
- Debugging - Readable data without tools
Why Not JSON-RPC?
- HTTP is standard - Everyone knows HTTP
- Browser compatibility - Works in browsers
- Proxy support - Works through proxies
- Firewall friendly - Port 80/443
- Standard tools - curl, Postman, etc.
Why Not gRPC?
- HTTP is simpler - Easier to debug
- Language agnostic - Any language can consume
- Standard tools - curl, wget, etc.
- No code generation - Less build complexity
- Better error messages - HTTP status codes
Trade-offs Acknowledged
Simplicity vs. Features
We chose:
- Simple, understandable code
- Fewer features initially
- Easy to maintain
- Easy to extend
We accept:
- Manual configuration
- Less automation
- More manual work
Performance vs. Clarity
We chose:
- Clear, readable code
- Explicit over implicit
- Easy to understand
We accept:
- Some performance overhead
- More verbose code
- Less abstraction
Flexibility vs. Type Safety
We chose:
- Type hints for clarity
- Runtime validation
- JSON Schema for tools
We accept:
- Some runtime errors
- Manual validation needed
- Type checking not compile-time
Future Considerations
When to Evolve
Add features when:
- Clear need exists
- Well-understood use case
- Minimal impact on existing
- Backward compatible
Don't add features when:
- Solving non-existent problems
- Adding complexity for edge cases
- Breaking existing functionality
- Introducing new dependencies unnecessarily
Evolution Path
Phase 1 (Current — 2.0 monorepo):
- Pip monorepo under
packages/with optional extras wired via protocols andcreate_app() - Local agent with MCP tools + native recovery; optional extras: memory, ensemble, skills, monitor, autotune, quantize
- Markdown memory: L0–L3 runtime state + indexed RAG in
memory_data/; BM25 default, optional hybrid local embeddings - Multi-model ensemble (
EnsembleRouter); multi-agent orchestration via host MCP if needed - Built-in
GracefulDegradation(crash/OOM tier recovery); optional[monitor]for proactive RAM/VRAM pressure - GGUF quantization via
llama-tools quantize/local-ai-quantize - MTP speculative decoding via
llama.models.*.mtp - Per-agent Jinja
prompt_files(host-owned); mode-aware bundledsystem.md/system_native.mdfallback when omitted - Message archive +
load_message; large tool results externalized to L3 +load_tool_result - Optional
workspaceroot for skills storage (no Core workspace file index; project FS via MCP) - Session checkpoint/resume (
--resume), token-budget context trim - CLI:
local-ai cli,local-ai serve-stdio,local-ai serve-http([http]),local-ai health - Standalone planner tools:
llama-tools doctor,plan,inspect,benchmark,quantize - SessionRunner embedding for host applications
Phase 2 (Future):
- Optional database-backed memory (alongside file-based L0–L3)
- Deeper multi-agent coordination beyond single-level delegation
- Distributed execution preparation (shared filesystem state, session isolation)
Phase 3 (Later):
- Federated or distributed local inference
- Cross-instance knowledge sync without cloud APIs
Core Values
- Local-first - Privacy and control
- Minimal dependencies - Less complexity
- Type safety - Catch errors early
- Async-first - Non-blocking design
- Security - Sandbox everything
- Simplicity - Easy to understand
- Extensibility - Easy to add features
- Documentation - Well-documented
Summary
LevPRO AI runtime embodies a philosophy of pragmatic minimalism - building sophisticated AI agents with minimal dependencies, maximum local control, and careful architectural decisions. Every component serves a clear purpose, and every trade-off is intentional.
The goal is not to replace cloud-based AI solutions, but to provide an alternative that respects user privacy, reduces costs, and works entirely offline.