using System.Text.Json;using Agent.Core.ToolCalling;using Lilith.Agent.ScenarioSystem;namespace Lilith.Agent;public partial class Lilith{ public void RegisterScenarioTools(ToolRegistry registry) { registry.Register(new AgentTool( "scenario_run", "Runs a Version9 scenario from backend/load/Scenario_<Name>.xml by executing its <Step> prompts as normal chat turns (tools allowed). Returns the final assistant message from the scenario.", args => RunScenarioTool(args), new { type = "object", properties = new { scenario_name = new { type = "string", description = "Scenario name without prefix, e.g. 'OnBoot' loads Scenario_OnBoot.xml." } }, required = new[] { "scenario_name" } }, ToolCategory.Self )); } private string RunScenarioTool(string argumentsJson) { try { using var doc = JsonDocument.Parse(argumentsJson); var root = doc.RootElement; string scenarioName = root.TryGetProperty("scenario_name", out var n) ? (n.GetString() ?? "") : ""; if (string.IsNullOrWhiteSpace(scenarioName)) return "Error: scenario_name is required."; string xml = ScenarioFileService.LoadScenarioXml(scenarioName); var scenario = ScenarioXmlParser.Parse(xml); // Execute scenario steps as chat turns; return final assistant message. var branch = this.GetScenarioBranch(); string? last = ScenarioExecutor .RunChatStepsAsync(branch, scenario.Steps, scenario.Id, scenario.Title) .GetAwaiter().GetResult(); return string.IsNullOrWhiteSpace(last) ? "Completed." : last; } catch (Exception ex) { return $"Error: {ex.Message}"; } }}
Documentation
Lilith (Version 3)
Version 3 Lilith agent library. Entry point: Lilith.cs with partials under Boot/, Chat/, Ollama/, and SystemPrompt/.
Build the solution or run python ../Build-v3.py from this tree.