LLM Configuration
Doggy provides a graphical LLM configuration management system supporting flexible configuration across multiple vendors, models, and roles, with runtime dynamic switching — a unified model foundation for AI features.
Overview
The LLM configuration system lives in src/Service/Platform/Llm/, drawing on Symfony AI Bundle's Platform design philosophy:
- Multiple vendors: OpenAI, Azure, Anthropic, Ollama, custom OpenAI-compatible gateways
- Graphical management: Dynamic management via admin UI (not YAML config)
- Role separation: Config decoupled from use; roles bind to models
- Key encryption: API keys encrypted at rest, never exposed to the frontend
Data Model
LlmProvider (Vendor Config)
| Field | Type | Description |
|---|---|---|
| name | string | Display name, e.g. "GPT-4o" |
| provider | string | Vendor: openai / anthropic / azure / ollama / custom |
| model | string | Model name: gpt-4o / claude-3-5-sonnet / ... |
| apiKey | encrypted | API key (encrypted at rest) |
| apiEndpoint | string | Endpoint URL (optional) |
| options | JSON | Extra params: temperature, max_tokens, top_p, etc. |
| isEnabled | boolean | Enabled flag |
| sortOrder | int | Sort order |
LlmRole (Role/Purpose)
| Field | Type | Description |
|---|---|---|
| code | string | Role code: view_editor / entity_generation / workflow_analysis / query_assistant / chat / coding |
| label | string | Display name |
| providerId | UUID | Bound model config |
| systemPrompt | text | System prompt for this role |
| options | JSON | Role-level param overrides |
| isEnabled | boolean | Enabled flag |
Role Planning
| Role code | Purpose | Recommended model |
|---|---|---|
| view_editor | View designer AI assistant | gpt-4o / claude-3.5-sonnet |
| entity_generation | AI-assisted entity generation | gpt-4o-mini |
| workflow_analysis | Workflow analysis & suggestions | gpt-4o |
| query_assistant | Natural language → data query | gpt-4o-mini |
| chat | General AI chat assistant | gpt-4o-mini |
| coding | Code generation (Twig/JS/PHP) | gpt-4o / claude-3.5-sonnet |
Call Chain
LlmRouter::chatByRole(roleCode, messages, opts)
├─ Query LlmRole(code) → get bound LlmProvider
├─ LlmGatewayFactory::create(provider) → instantiate adapter
├─ Decrypt API key (LlmEncryptor)
└─ Call LLM API (tool calling, streaming supported)LlmGatewayFactory
Auto-routes adapters based on LlmProvider.provider:
| provider | Adapter | Description |
|---|---|---|
| openai | OpenAiGateway | OpenAI-compatible API |
| anthropic | AnthropicGateway | Anthropic Claude API |
| azure | AzureGateway | Azure OpenAI |
| ollama | OllamaGateway | Local Ollama |
| custom | CustomGateway | Custom OpenAI-compatible gateway |
Failover
LlmRouter supports chatByRoleWithFallback, automatically degrading to a backup model when the primary vendor fails.
Admin UI
Entry: System Settings → LLM Config (/admin/platform/llm-config)
List Page
- Vendor card display; one vendor can have multiple model variants
- Shows roles/usages bound to each model directly
- Toggle enable/disable
- Drag-and-drop sorting
Edit Form
- Name, vendor, model, API key (encrypted), endpoint
- Role management (
LlmRoleType): role code, system prompt, model binding
Key Encryption
LlmEncryptor encrypts/decrypts API keys with the platform encryption key. Keys live only on the server; the frontend never sees the raw key:
// Storing
$encrypted = $llmEncryptor->encrypt($apiKey);
// Calling
$apiKey = $llmEncryptor->decrypt($provider->getApiKey());Integration with the AI Assistant
The AI assistant (see AI Assistant) reuses the LlmRole/LlmProvider system:
Frontend → POST /api/admin/ai/chat
→ LlmRouter.chatByRole(roleCode, messages)
→ Query LlmRole → LlmGatewayFactory → LLM API- API keys live only on the server (encrypted in DB)
- Model switching happens in the admin UI — no code changes needed
- Multi-vendor routing is automatic via LlmGatewayFactory
Related Files
| File | Responsibility |
|---|---|
src/Service/Platform/Llm/LlmGatewayInterface.php | Gateway interface |
src/Service/Platform/Llm/LlmGatewayFactory.php | Adapter factory |
src/Service/Platform/Llm/LlmRouter.php | Role routing + failover |
src/Service/Platform/Llm/ModelRegistry.php | Model registry |
src/Service/Platform/LlmEncryptor.php | API key encryption |
src/Entity/Platform/LlmProvider.php | Vendor config entity |
src/Entity/Platform/LlmRole.php | Role config entity |
src/Controller/Admin/Platform/LlmConfigController.php | Admin UI controller |