Boot/Lilith.Boot.cscsharp

Documentation

Boot

Startup and readiness for the Lilith chat session.

Lilith.Boot.cs

  • BootAsync — initializes Ollama, prints the console banner, runs the opening greeting, and validates chat history.
  • GreetAsync — sends the initial “greet the user” prompt through the chat pipeline.
  • EnsureChatReadiness — confirms the Ollama client, system message, and context window are ready before user input.
using Agent.Core.Logging;using Agent.Core.Ollama;namespace Lilith.Agent;public partial class Lilith{    public bool IsBooted { get; private set; }    public async Task BootAsync(bool startServerIfNotRunning = true)    {        IsBooted = false;        await InitializeOllamaAsync(startServerIfNotRunning);        Logger.WriteLine("System", $"=== Lilith AI Chat ({Credentials.Model} via Ollama) ===", LogColors.Cyan);        Logger.WriteLine("System", "Type your message and press Enter. Type 'exit' to quit.\n", LogColors.Cyan);        await GreetAsync();        EnsureChatReadiness();        Logger.WriteLine("System", "", LogColors.White);        IsBooted = true;    }    public async Task GreetAsync() => await ChatAsync("Please greet the user.");    private void EnsureChatReadiness()    {        if (_client is null)        {            throw new InvalidOperationException("Ollama client was not initialized.");        }        if (History.Count == 0 || !string.Equals(History[0].Role, "system", StringComparison.OrdinalIgnoreCase))        {            throw new InvalidOperationException("Chat history was not seeded with a system prompt.");        }        if (string.IsNullOrWhiteSpace(History[0].Content))        {            throw new InvalidOperationException("System prompt content is missing.");        }        if (ContextMax <= 0)        {            throw new InvalidOperationException("Model context window was not initialized.");        }    }}