# Configuration ## Overview Luna uses the standard .NET Options pattern for managing application settings. The configuration system relies on `IOptions` and `IOptionsMonitor` to provide typed access to settings defined in `appsettings.json`. This approach ensures type safety and allows for easy validation at startup. The configuration is centralized in the `Luna.Configuration` project. Settings are bound during application startup using the `.BindConfiguration().ValidateDataAnnotations().ValidateOnStart()` pattern. ## Options Classes ### AgentOptions These settings define the behavior and identity of AI agents like the [[Core]] agent or the Librarian. Agents retrieve their specific configuration using `IOptionsMonitor.Get(name)`. ```csharp public class AgentOptions { public required string Name { get; set; } public string? DisplayName { get; init; } public string? Description { get; init; } public required string Provider { get; init; } public required string ModelId { get; init; } public required string Instructions { get; init; } public required int MaxContextTokens { get; init; } } ``` ### ProviderOptions Configures the connection details for AI model providers such as Mistral or OpenAI. ```csharp public class ProviderOptions { public required string ApiKey { get; init; } public required string ApiUrl { get; init; } public required string[] Models { get; init; } } ``` ### SessionOptions Controls how [[Memory]] and conversation sessions are managed. It specifically dictates when the session context should be compacted to save tokens. ```csharp public class SessionOptions { public required float ContextTokenThreshold { get; init; } public required int RetainedMessagesAfterCompacting { get; init; } } ``` ### TelegramOptions Specific settings for the Telegram [[Channels]] adapter, including bot authentication and user access control. ```csharp public class TelegramOptions { public required string BotToken { get; init; } public string? WebhookUrl { get; init; } public int PollingTimeoutSeconds { get; init; } = 30; public string[] AllowedUserIds { get; init; } = []; } ``` ## Example Configuration The following `appsettings.json` structure demonstrates how these options are populated: ```json { "Agents": { "Core": { "Name": "Core", "Provider": "Mistral", "ModelId": "mistral-small-latest", "Instructions": "You are Luna, a helpful AI assistant.", "MaxContextTokens": 8192 }, "Librarian": { "Name": "Librarian", "Provider": "Mistral", "ModelId": "mistral-small-latest", "Instructions": "Summarize conversations concisely.", "MaxContextTokens": 4096 } }, "Providers": { "Mistral": { "ApiKey": "YOUR_API_KEY", "ApiUrl": "https://api.mistral.ai", "Models": ["mistral-small-latest"] } }, "Session": { "ContextTokenThreshold": 0.7, "RetainedMessagesAfterCompacting": 5 }, "Channels": { "Telegram": { "BotToken": "YOUR_BOT_TOKEN", "PollingTimeoutSeconds": 30, "AllowedUserIds": [] } } } ``` ## Dependencies The configuration module depends on the following NuGet packages: - Microsoft.Extensions.DependencyInjection.Abstractions - Microsoft.Extensions.FileProviders.Embedded - Microsoft.Extensions.Options - Tomlyn (for parsing embedded TOML resources)