In-AI Assistant Architecture
The In-AI Assistant provides natural language control and diagnostics for LocalLLMServerManager. Local engines run image, audio, and text generation on your graphics card. These local engines can consume all available video memory. Therefore, the assistant routes requests to an external API endpoint. The assistant uses a LiteLLM proxy connected to Google Cloud Vertex AI Gemini Flash.
External Proxy Design
External routing keeps the assistant operational during heavy local generation tasks. The assistant requires zero megabytes of local GPU memory.
Architectural Overview
Component Layers
1. Presentation Layer (UI/UX)
AiAssistantViewModel:
- Manages reactive state with
CommunityToolkit.Mvvm. - Maintains
AvailableModelCapabilities(ObservableCollection<AiModelCapabilityInfo>). - Synchronizes
SelectedModelCapabilitywith the activeSelectedModel. - Manages
StagedAttachments(ObservableCollection<AiChatMessageAttachment>). - Supports image paste actions from the system clipboard.
- Supports dual execution: direct C# service calls in desktop mode and REST/SSE fallback in web mode.
- Manages reactive state with
AiAssistantTabControl.axaml:
- Implements a responsive chat interface styled with
DesignTokens.axaml. - Features an interactive composer bar with:
- Model Selector Dropdown: Displays models with compact capability badges (
👁️,⚡,1M). - Attachment Button (📎): Opens a file picker for images (
PNG,JPG,WEBP,GIF). - Clipboard Paste: Captures
Ctrl+Vkey events on the text input to stage images directly. - Staged Image Tray: Shows image preview thumbnails with removal buttons (
✕). - Status Indicators: Shows tool execution cards and streaming token text.
- Model Selector Dropdown: Displays models with compact capability badges (
- Implements a responsive chat interface styled with
2. Model Discovery and Exclusion Layer
The discovery engine queries remote endpoints to identify model capabilities.
LiteLLM Discovery Protocol
- The service requests
GET {baseUrl}/model/info. - LiteLLM returns rich capability metadata:
max_input_tokensandmax_output_tokens.supports_visionandsupports_function_calling.litellm_providerand deployment mode.
- If
/model/infofails, the service falls back toGET {baseUrl}/v1/models. - The fallback inspects model identifiers to infer vision and tool capabilities.
Local Model Exclusion Rules
LiteLLM can route requests to local engines. However, assistant requests must not use local GPU memory.
Exclusion Rule Logic
Do not filter models by IP address. LiteLLM frequently runs on local addresses (127.0.0.1) or local area network IPs. Filter models strictly by provider name or model identifier prefix.
- Excluded Providers:
ollamalocalllama.cppvllm_local
- Excluded ID Prefixes:
ollama/local/llama/ollama_chat/
- Exclusion Toggle: Set query parameter
includeLocal=trueonGET /api/ai/modelsto include local models.
3. Web API Endpoints Layer
- AiAssistantEndpoints.cs:
GET /api/ai/status: Reports assistant installation status and active endpoint.POST /api/ai/validate: Validates credentials with round-trip latency checks.GET /api/ai/models: ReturnsList<AiModelCapabilityInfo>. Acceptsendpoint,apiKey, andincludeLocalparameters.POST /api/ai/chat: Executes chat completions. Accepts multimodal message attachments.GET /api/ai/prompts: Returns loaded system prompt sections.POST /api/ai/prompts/reload: Flushes prompt memory caches immediately.
4. Orchestration and Multimodal Pipeline
- IAiAssistantService & AiAssistantService:
- Built on
Microsoft.Extensions.AIabstractions. - Serializes
AiChatMessageAttachmentinstances intoMicrosoft.Extensions.AI.ImageContent. - Supports binary byte buffers and base64 data URIs.
- Wraps
OpenAI.Chat.ChatClientwithFunctionInvokingChatClient. - Automatically executes native C# tools and returns results to the language model.
- Streams tokens asynchronously via
StreamChatAsync.
- Built on
5. Living Prompts System
- IPromptManagementService & PromptManagementService:
- Loads markdown files from the
Prompts/directory:system-prompt.md: Defines tone and operational boundaries.capabilities.md: Defines hardware sizing and multimodal capabilities.workflows.md: Defines execution steps for image, video, and audio tasks.app-control.md: Defines safety rules for app tool calls.
- Caches prompt content in memory.
- Provides immediate cache invalidation through
InvalidateCache().
- Loads markdown files from the
6. Application Integration Bridge (App Control)
- IAiAppTools & AiAppTools:
- Exposes 12 native C# tools for autonomous LLM function calling:
GetGpuVramTelemetryAsync: Reads live GPU memory usage.CheckServicesHealthAsync: Checks backend engine health.ListInstalledModelsAsync: Lists installed local Ollama models.StartAiEngineAsync: Starts ComfyUI, Forge, or Ollama.StopAiEngineAsync: Stops running backend engines.UnloadVramAsync: Flushes models from video memory.GetAppSettingsAsync: Reads application settings.UpdateAppSettingAsync: Updates configuration values.CalculateHardwareFitAsync: Calculates model memory fit.GenerateImageAsync: Triggers local image generation workflows.SynthesizeSpeechAsync: Generates speech with Kokoro TTS.QueryAppDocumentationAsync: Searches local documentation guides.
- Exposes 12 native C# tools for autonomous LLM function calling:
