VCPToolBox is a model-agnostic AI middleware server that transforms standard OpenAI-compatible API requests into context-enriched, tool-enabled interactions. It implements a three-pillar architecture—AI inference, tool execution, and persistent memory—to enable autonomous agent behavior, sophisticated RAG-based knowledge retrieval, and distributed plugin orchestration.
Core Capabilities:
Scope: This page covers high-level architecture, request flow, and subsystem interactions. For implementation details:
Sources: README.md1-57 server.js1-100
VCPToolBox implements a layered architecture centered on three core pillars: AI inference, tool execution, and persistent memory. The system receives HTTP requests at /v1/chat/completions, processes them through multiple transformation stages, and orchestrates interactions between AI models, plugins, and knowledge bases.
Analysis: This diagram shows VCPToolBox's layered architecture. The Core Server Layer handles authentication via Bearer tokens and IP blacklisting server.js292-303 routes requests through ChatCompletionHandler modules/chatCompletionHandler.js242-253 and orchestrates the PluginManager Plugin.js The Plugin Ecosystem provides five plugin types with different execution models. The Memory & Intelligence Layer implements TagMemo Wave v5 RAG Plugin/RAGDiaryPlugin/ meta-thinking chains, and dream introspection. The Storage Layer uses SQLite for structured data VectorStore/knowledge_base.sqlite USearch for vector indexes *.usearch files and the file system for documents. All components interact with External AI Services for inference and embeddings.
Sources: server.js1-303 modules/chatCompletionHandler.js242-253 Plugin.js KnowledgeBaseManager.js README.md42-310 Diagram 1 from system overview
VCPToolBox's architecture centers on three synergistic pillars:
The ChatCompletionHandler class modules/chatCompletionHandler.js242 manages all backend AI interactions through a unified interface supporting OpenAI, Claude, Gemini, and custom endpoints.
Key Components:
apiRetries and apiRetryDelay configurationthinking: {type: "enabled"} injection for GLM/Qwen/DeepSeek models when ChinaModel1Cot=truePlugins extend AI capabilities through six execution protocols: static, preprocessor, synchronous, asynchronous, service, and hybrid. The system parses <<<[TOOL_REQUEST]>>> delimiters in AI responses and orchestrates plugin invocations.
Key Components:
plugin-manifest.json, lifecycle management, and routing to local vs distributed executors「始」...「末」 delimiters and fallback to <start>...</end> syntaxregister_tools, execute_tool, and internal_request_file message handlers for distributed pluginsThe Rust-powered Vexus-Lite engine rust-vexus-lite/ provides atomic-precision semantic search through the TagMemo Wave v5 algorithm.
Key Components:
<!-- VCP_RAG_BLOCK_START -->...<!-- VCP_RAG_BLOCK_END --> blocks into system/assistant messages based on [[dbName::modifiers]] syntaxSources: README.md42-389 server.js72-95 modules/chatCompletionHandler.js242-301 Plugin.js KnowledgeBaseManager.js dailynote.md1-120
The following diagram details the transformation pipeline from client request to AI response, mapping each stage to specific code entities.
Sources: modules/chatCompletionHandler.js254-700 server.js500-600 modules/messageProcessor.js14-52 Diagram 4 from high-level system overview
VCPToolBox implements a hierarchical configuration system with hot-reload via chokidar file watching:
| Configuration File | Purpose | Hot Reload Mechanism |
|---|---|---|
config.env | Global settings, API keys, ports, model routing | Manual restart (pm2 restart) |
Plugin/*/config.env | Plugin-specific overrides merged with global config | Automatic via PluginManager.reloadPlugins() |
rag_params.json | TagMemo V5 magic numbers (k, tagWeight, EPA thresholds) | Automatic via RAGDiaryPlugin internal watcher |
agent_map.json | Agent alias → Agent/*.txt file mappings | Automatic via agentManager.loadAgentMap() modules/agentManager.js36-50 |
preprocessor_order.json | Execution sequence for message preprocessors | Automatic via PluginManager manifest watcher |
TVStxt/*.txt | Advanced variable definitions ({{Tar*}}, {{Var*}}) | Automatic via tvsManager.loadTVSFile() modules/tvsManager.js |
Hot Reload Flow:
chokidar detects plugin-manifest.json changes Plugin.jsPluginManager.reloadPlugins() calls shutdown() on all local plugins (preserves distributed plugins)plugins, staticPlugins, messagePreprocessors, servicesPlugin/*/ directories and reinitializes pluginsplugins-reloaded event via WebSocket to connected clients WebSocketServer.jsSources: config.env.example1-465 server.js67-228 modules/agentManager.js1-150 modules/tvsManager.js Plugin.js Diagram 6 from system overview
Four security layers protect different endpoints:
Bearer Token Authentication - Main API (/v1/*)
process.env.Key in auth middleware server.js466-503handleApiError() on 401 responses server.js261-289Basic Authentication - Admin Panel (/AdminPanel, /admin_api)
process.env.AdminUsername / AdminPassword server.js111-112/AdminPanel/login.html, /AdminPanel/VCPLogo2.png, etc. server.js323-337IP Blacklist System - Automatic threat mitigation
ip_blacklist.json server.js81-84127.0.0.1 and ::1 never auto-banned server.js268-271/admin_api/ip-blacklist endpointsVCPToolCode System - Per-tool authorization
Plugin/UserAuth/code.bin modules/captchaDecoder.js24-35ToolExecutor if VCPToolCode=true modules/vcpLoop/toolExecutor.jsplugin-manifest.json requireAdmin flagIP Tracking for Distributed Plugins:
WebSocketServer.findServerByIp() maps IPs to known distributed servers WebSocketServer.jsFileFetcherServer uses IP tracking for transparent file proxying FileFetcherServer.jsSources: server.js78-503 modules/captchaDecoder.js1-50 modules/vcpLoop/toolExecutor.js README.md1195-1213
A web-based management interface served at /AdminPanel provides:
config.env with comment preservation admin_api/configdailynote/ directory admin_api/knowledge-browserThe panel uses Basic Auth with cookie-based session management server.js316-453
Sources: server.js316-459 README.md1018-1055 Diagram 5 from high-level system overview
Structured Storage:
VectorStore/knowledge_base.sqlite config.env.example122files, chunks, tags, knowledge_chunks tables KnowledgeBaseManager.jsVector Storage:
VectorStore/index_global_tag.usearch, index_diary_*.usearch config.env.example122-124Full-Text Search:
jieba-rs tokenizer for Chinese segmentation dailynote.md40-41| Protocol | Use Case | Implementation |
|---|---|---|
| HTTP/1.1 | Client requests, backend AI API calls | express.json() body parser server.js236 |
| SSE (Server-Sent Events) | Streaming AI responses to clients | res.write() in StreamHandler modules/handlers/streamHandler.js |
| WebSocket | Distributed plugin RPC, admin panel live updates | ws library in WebSocketServer WebSocketServer.js1-50 |
| stdio (JSON-RPC) | Sandboxed plugin IPC via child_process.spawn() | PluginManager._executeStdioPlugin() Plugin.js |
| HTTP/2 | Optional for backend AI APIs supporting multiplexing | Via fetch() API |
RotatingLogger modules/logger.js14-130
DebugLog/archive/YYYY-MM-DD/server.log, error.log, debug.logchokidar - File system event monitoring
WebSocket Push Notifications
VCPLog plugin streams to admin panel vcpInfoHandler.jsVCPInfo broadcasts system events to clients vcpInfoHandler.jsplugins-reloaded event on hot-reload WebSocketServer.jsSources: server.js1-237 package.json Dockerfile1-50 docker-compose.yml modules/logger.js1-150 KnowledgeBaseManager.js1-100 WebSocketServer.js1-50 README.md359-707 dailynote.md9-43
A typical /v1/chat/completions request flows through these stages:
| Phase | Code Entity | Purpose |
|---|---|---|
| 1. Authentication | app.use() middleware server.js292-303 | Validate Authorization: Bearer Key against process.env.Key |
| 2. Route Dispatch | app.post('/v1/chat/completions') server.js | Extract requestId, create AbortController, register in activeRequests Map |
| 3. Context Control | contextManager.pruneMessages() modules/contextManager.js | Trim message array to contextTokenLimit token budget |
| 4. Model Redirection | modelRedirectHandler.redirectModelForBackend() modelRedirectHandler.js | Map client model IDs to backend model IDs per redirect config |
| 5. Role Division (Initial) | roleDivider.process(..., skipCount=1) modules/roleDivider.js47 | Split messages by <<<[ROLE_DIVIDE_XXX]>>> tags (skips first system message) |
| 6. VCPTavern Priority | pluginManager.executeMessagePreprocessor('VCPTavern') modules/chatCompletionHandler.js398-406 | Inject preset blocks from VCPTavern/presets/*.json |
| 7. Variable Replacement | messageProcessor.resolveAllVariables() modules/messageProcessor.js14-239 | Resolve placeholders in priority order: {{Agent*}} → {{Tar*}} → {{Var*}} → {{VCPPluginName}} |
| 8. Preprocessor Pipeline | Sequential executeMessagePreprocessor() calls modules/chatCompletionHandler.js443-478 | Run RAGDiaryPlugin, MultiModalProcessor, etc. per preprocessor_order.json |
| 9. Media Processing | ImageProcessor cache + multimodal API modules/chatCompletionHandler.js479-523 | Convert image_url to base64, cache in imageCache/, or call MultiModalModel API |
| 10. AI Invocation | fetchWithRetry(API_URL, processedBody) modules/chatCompletionHandler.js99-144 | POST to backend with retry logic (3 retries, 200ms delay) |
| 11. Tool Loop | ToolCallParser + ToolExecutor modules/chatCompletionHandler.js608-748 | Detect <<<[TOOL_REQUEST]>>>, execute plugin, inject result, recurse (max 5 loops) |
| 12. RAG Refresh | _refreshRagBlocksIfNeeded() modules/chatCompletionHandler.js146-240 | Update <!-- VCP_RAG_BLOCK_START --> blocks if RAGMemoRefresh=true |
| 13. Response Handling | StreamHandler or NonStreamHandler modules/handlers/ | Stream SSE chunks or return JSON based on req.body.stream flag |
For detailed sequence diagrams and stage-by-stage analysis, see Request Processing Pipeline.
Sources: modules/chatCompletionHandler.js254-800 server.js500-700 modules/messageProcessor.js14-239 modules/contextManager.js modules/roleDivider.js47-280 Diagram 2 from system overview
VCPToolBox supports horizontal scaling through a star-topology network:
Key Mechanisms:
register_tools with plugin manifests WebSocketServer.jsPluginManager checks isDistributed flag and routes accordingly Plugin.jsFileFetcherServer retrieves remote files via WebSocket for tool parameters FileFetcherServer.jsSources: README.md507-633 WebSocketServer.js VCPDistributedServer.js Diagram 1 from high-level system overview
This overview establishes the foundational understanding needed to explore VCPToolBox's subsystems in detail. For next steps:
Refresh this wiki