215 lines
7.3 KiB
C#
215 lines
7.3 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace ClawdDotNet.Core.Config;
|
|
|
|
public sealed class AgentConfig
|
|
{
|
|
[JsonPropertyName("agentId")]
|
|
public string AgentId { get; set; } = "";
|
|
|
|
[JsonPropertyName("displayName")]
|
|
public string DisplayName { get; set; } = "";
|
|
|
|
[JsonPropertyName("model")]
|
|
public string Model { get; set; } = "anthropic/claude-sonnet-4-5";
|
|
|
|
[JsonPropertyName("systemPrompt")]
|
|
public string SystemPrompt { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Identität des Agenten (aus Identity.md geladen).
|
|
/// Definiert WER der Agent ist: Name, Rolle, Hintergrund.
|
|
/// </summary>
|
|
[JsonIgnore]
|
|
public string Identity { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Seele des Agenten (aus Soul.md geladen).
|
|
/// Definiert WIE der Agent denkt: Persönlichkeit, Werte, Verhaltensmuster.
|
|
/// </summary>
|
|
[JsonIgnore]
|
|
public string Soul { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Lokaler Pfad zum Workspace-Verzeichnis des Agenten.
|
|
/// Wird zur Laufzeit vom Host gesetzt.
|
|
/// </summary>
|
|
/// <summary>
|
|
/// Kurzbeschreibung der Rolle/Aufgabe des Agenten.
|
|
/// Wird aus AgentList.json geladen und bei list_agents angezeigt.
|
|
/// </summary>
|
|
[JsonIgnore]
|
|
public string Description { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Absoluter Pfad zum Agent-Verzeichnis (Agent-XYZ).
|
|
/// Wird zur Laufzeit gesetzt und bleibt stabil auch bei DisplayName-Änderungen.
|
|
/// </summary>
|
|
[JsonIgnore]
|
|
public string AgentDir { get; set; } = "";
|
|
|
|
[JsonIgnore]
|
|
public string WorkspacePath { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Lokaler Pfad zum geteilten Workspace-Verzeichnis (SharedWorkspace).
|
|
/// Wird zur Laufzeit vom Host gesetzt.
|
|
/// </summary>
|
|
[JsonIgnore]
|
|
public string SharedWorkspacePath { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Baut den vollständigen System-Prompt aus Identity + Soul + SystemPrompt zusammen.
|
|
/// </summary>
|
|
[JsonIgnore]
|
|
public string FullSystemPrompt
|
|
{
|
|
get
|
|
{
|
|
var parts = new List<string>();
|
|
if (!string.IsNullOrWhiteSpace(Identity))
|
|
parts.Add($"# Identity\n{Identity}");
|
|
if (!string.IsNullOrWhiteSpace(Soul))
|
|
parts.Add($"# Soul\n{Soul}");
|
|
if (!string.IsNullOrWhiteSpace(SystemPrompt))
|
|
parts.Add(SystemPrompt);
|
|
return string.Join("\n\n", parts);
|
|
}
|
|
}
|
|
|
|
[JsonPropertyName("tools")]
|
|
public Dictionary<string, Dictionary<string, object?>> Tools { get; set; } = new();
|
|
|
|
[JsonPropertyName("scheduler")]
|
|
public SchedulerConfig? Scheduler { get; set; }
|
|
|
|
[JsonPropertyName("toolJobs")]
|
|
public List<ToolJobConfig> ToolJobs { get; set; } = new();
|
|
|
|
[JsonPropertyName("loopGuard")]
|
|
public LoopGuardConfig LoopGuard { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// Prompt-Caching: "auto" (Default), "on" oder "off".
|
|
///
|
|
/// Bei "auto" wird es für Modelle aktiviert, die cache_control unterstützen.
|
|
/// Der Nutzen ist erheblich, weil jeder Schritt eines Runs den kompletten Prompt
|
|
/// erneut sendet — System-Prompt und Tool-Definitionen also dutzendfach.
|
|
/// </summary>
|
|
[JsonPropertyName("promptCaching")]
|
|
public string PromptCaching { get; set; } = "auto";
|
|
|
|
/// <summary>
|
|
/// Maximale Länge eines einzelnen Tool-Ergebnisses in Zeichen, bevor es gekürzt in
|
|
/// den Kontext wandert. Ohne Grenze kann ein einziger Abruf den gesamten Kontext
|
|
/// sprengen (ein WebFetch mit 512 KB entspricht etwa 130.000 Tokens).
|
|
/// </summary>
|
|
[JsonPropertyName("maxToolResultChars")]
|
|
public int MaxToolResultChars { get; set; } = 16_000;
|
|
|
|
[JsonPropertyName("budget")]
|
|
public AgentBudget Budget { get; set; } = new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tagesgrenzen eines Agenten. 0 bedeutet jeweils: keine Grenze.
|
|
///
|
|
/// Zwei Arten, weil sich Kosten nicht immer beziffern lassen: Liefert der Anbieter für
|
|
/// ein Modell keine Preise, greift die Kostengrenze nicht — die Token-Grenze immer.
|
|
/// </summary>
|
|
public sealed class AgentBudget
|
|
{
|
|
[JsonPropertyName("dailyCostUsd")]
|
|
public decimal DailyCostUsd { get; set; }
|
|
|
|
[JsonPropertyName("dailyTokens")]
|
|
public long DailyTokens { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public bool HasAnyLimit => DailyCostUsd > 0 || DailyTokens > 0;
|
|
}
|
|
|
|
/// <summary>Tagesgrenzen über alle Agenten einer Instanz hinweg.</summary>
|
|
public sealed class InstanceBudget
|
|
{
|
|
[JsonPropertyName("dailyCostUsd")]
|
|
public decimal DailyCostUsd { get; set; }
|
|
|
|
[JsonPropertyName("dailyTokens")]
|
|
public long DailyTokens { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public bool HasAnyLimit => DailyCostUsd > 0 || DailyTokens > 0;
|
|
|
|
public static InstanceBudget Unlimited { get; } = new();
|
|
}
|
|
|
|
public sealed class SchedulerConfig
|
|
{
|
|
[JsonPropertyName("cron")]
|
|
public string Cron { get; set; } = "";
|
|
|
|
[JsonPropertyName("runOnStart")]
|
|
public bool RunOnStart { get; set; }
|
|
|
|
[JsonPropertyName("taskMessage")]
|
|
public string TaskMessage { get; set; } = "Führe deine zugewiesenen Aufgaben aus.";
|
|
}
|
|
|
|
public sealed class LoopGuardConfig
|
|
{
|
|
[JsonPropertyName("maxSteps")]
|
|
public int MaxSteps { get; set; } = 20;
|
|
|
|
/// <summary>
|
|
/// Kostenbudget für einen kompletten Run: Summe der abgerechneten Tokens über
|
|
/// ALLE Schritte hinweg.
|
|
///
|
|
/// Achtung — dieser Wert ist nicht mit der Kontextgröße zu verwechseln: Da jeder
|
|
/// Schritt den vollständigen Kontext erneut sendet, wächst die Summe quadratisch.
|
|
/// Ein Agent mit stabilem 20k-Kontext verbraucht über 10 Schritte bereits ~200k.
|
|
/// Der Default ist deshalb bewusst großzügig; für die Kontextgröße ist
|
|
/// <see cref="MaxContextTokens"/> zuständig.
|
|
/// </summary>
|
|
[JsonPropertyName("maxCumulativeTokens")]
|
|
public int MaxCumulativeTokens { get; set; } = 500_000;
|
|
|
|
/// <summary>
|
|
/// Veraltet: hieß früher "maxTokens" und wurde fälschlich als Kontextgrenze
|
|
/// verstanden, obwohl er kumulativ zählt. Wird nur noch für die Migration alter
|
|
/// Konfigurationen gelesen — siehe <see cref="MaxCumulativeTokens"/>.
|
|
/// </summary>
|
|
[JsonPropertyName("maxTokens")]
|
|
public int? LegacyMaxTokens { get; set; }
|
|
|
|
[JsonPropertyName("timeoutSeconds")]
|
|
public int TimeoutSeconds { get; set; } = 600;
|
|
|
|
[JsonPropertyName("maxContextTokens")]
|
|
public int MaxContextTokens { get; set; } = 100_000;
|
|
|
|
/// <summary>
|
|
/// Obergrenze für die Ausgabe eines einzelnen Schritts (<c>max_tokens</c> im Request).
|
|
/// Deckelt die teuerste Token-Art gegen Ausreißer (B11/T8). 0 = keine Angabe, dann gilt
|
|
/// der Standard des Anbieters.
|
|
/// </summary>
|
|
[JsonPropertyName("maxResponseTokens")]
|
|
public int MaxResponseTokens { get; set; } = 8_192;
|
|
|
|
[JsonPropertyName("compactionThreshold")]
|
|
public double CompactionThreshold { get; set; } = 0.80;
|
|
|
|
/// <summary>
|
|
/// Modell für die Zusammenfassung beim Kompaktieren. Leer = Modell des Agenten.
|
|
///
|
|
/// Zusammenfassen ist eine anspruchslose Aufgabe; sie mit einem teuren Modell zu
|
|
/// erledigen kostet leicht mehr als der halbe Run, weil bis zu 30.000 Zeichen
|
|
/// verarbeitet werden.
|
|
/// </summary>
|
|
[JsonPropertyName("summaryModel")]
|
|
public string SummaryModel { get; set; } = "google/gemini-2.5-flash";
|
|
|
|
[JsonIgnore]
|
|
public TimeSpan Timeout => TimeSpan.FromSeconds(TimeoutSeconds);
|
|
}
|