Files
Luna/Documentation/Luna AI Assistant/Configuration.md
T
darman 9929941748 Add project documentation and reference materials
Include Luna AI Assistant design docs covering channels, configuration,
core architecture, memory, scheduler, and skills. Add reference docs
from OpenClaw and ZeroClaw projects, plus Mistral and OpenAI API specs.
2026-04-04 04:14:06 +02:00

3.4 KiB

Configuration

Overview

Luna uses the standard .NET Options pattern for managing application settings. The configuration system relies on IOptions<T> and IOptionsMonitor<T> 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<AgentOptions>.Get(name).

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.

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.

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.

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:

{
  "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)