diff --git a/Endpoints/AgentEndpoint.cs b/Endpoints/AgentEndpoint.cs index 683ff1e..5ce40de 100644 --- a/Endpoints/AgentEndpoint.cs +++ b/Endpoints/AgentEndpoint.cs @@ -54,7 +54,11 @@ public static class AgentEndpoint Model = body.TryGetProperty("model", out var m) ? m.GetString() ?? "sonnet" : "sonnet", ToolChoice = body.TryGetProperty("toolChoice", out var tc) ? tc.GetString() ?? "any" : "any", CustomCommands = customCommands, - AutoCommit = body.TryGetProperty("autoCommit", out var ac) && ac.GetBoolean() + AutoCommit = body.TryGetProperty("autoCommit", out var ac) && ac.GetBoolean(), + UseSoul = !body.TryGetProperty("useSoul", out var us) || us.GetBoolean(), + UseIdentity = !body.TryGetProperty("useIdentity", out var ui) || ui.GetBoolean(), + UseUserInfo = !body.TryGetProperty("useUserInfo", out var uu) || uu.GetBoolean(), + UseMemory = !body.TryGetProperty("useMemory", out var um) || um.GetBoolean() }; agent = await db.CreateAgent(agent); @@ -80,6 +84,10 @@ public static class AgentEndpoint if (body.TryGetProperty("customCommands", out var cc)) agent.CustomCommands = cc.ValueKind == JsonValueKind.Null ? null : cc.GetRawText(); if (body.TryGetProperty("autoCommit", out var ac)) agent.AutoCommit = ac.GetBoolean(); + if (body.TryGetProperty("useSoul", out var us)) agent.UseSoul = us.GetBoolean(); + if (body.TryGetProperty("useIdentity", out var ui)) agent.UseIdentity = ui.GetBoolean(); + if (body.TryGetProperty("useUserInfo", out var uu)) agent.UseUserInfo = uu.GetBoolean(); + if (body.TryGetProperty("useMemory", out var um)) agent.UseMemory = um.GetBoolean(); await db.UpdateAgent(agent); memoryService.InitializeAgentFiles(agentId, agent.Name); diff --git a/Endpoints/ChatEndpoint.cs b/Endpoints/ChatEndpoint.cs index f0213df..8d99aaf 100644 --- a/Endpoints/ChatEndpoint.cs +++ b/Endpoints/ChatEndpoint.cs @@ -161,7 +161,7 @@ public static class ChatEndpoint streamingTracker.Start(sessionId, chainId); try { - await anthropic.StreamChat(res, modelId, systemPrompt, messages, chainId, workspace, sessionId, agentId: agent.AgentId, maxIterations: maxIterations, toolChoice: toolChoice, cancellationToken: cancellationToken); + await anthropic.StreamChat(res, modelId, systemPrompt, messages, chainId, workspace, sessionId, agentId: agent.AgentId, useMemory: agent.UseMemory, maxIterations: maxIterations, toolChoice: toolChoice, cancellationToken: cancellationToken); } finally { diff --git a/Models/AgentRecord.cs b/Models/AgentRecord.cs index 1db0406..e292877 100644 --- a/Models/AgentRecord.cs +++ b/Models/AgentRecord.cs @@ -11,6 +11,10 @@ public class AgentRecord public string ToolChoice { get; set; } // "any" oder "auto" public string CustomCommands { get; set; } public bool AutoCommit { get; set; } + public bool UseSoul { get; set; } = true; + public bool UseIdentity { get; set; } = true; + public bool UseUserInfo { get; set; } = true; + public bool UseMemory { get; set; } = true; public bool IsDeleted { get; set; } public string CreatedAt { get; set; } public string UpdatedAt { get; set; } diff --git a/Services/AnthropicService.cs b/Services/AnthropicService.cs index 3438e3b..d9f0af0 100644 --- a/Services/AnthropicService.cs +++ b/Services/AnthropicService.cs @@ -38,6 +38,7 @@ public class AnthropicService string workspace, string sessionId = null, string agentId = null, + bool useMemory = true, int maxIterations = 100, string toolChoice = "any", CancellationToken cancellationToken = default) @@ -72,7 +73,7 @@ public class AnthropicService if (!string.IsNullOrEmpty(workspace)) { - var includeMemory = _memoryService != null && !string.IsNullOrEmpty(agentId); + var includeMemory = useMemory && _memoryService != null && !string.IsNullOrEmpty(agentId); payload["tools"] = _toolService.GetToolDefinitions(includeMemory); // "any" erzwingt Tool-Nutzung, aber nur in der ersten Iteration, // damit Claude nicht endlos Tools aufruft wenn die Aufgabe erledigt ist. diff --git a/Services/DatabaseService.cs b/Services/DatabaseService.cs index a2d90cb..0b96b85 100644 --- a/Services/DatabaseService.cs +++ b/Services/DatabaseService.cs @@ -130,6 +130,10 @@ public class DatabaseService TryAddColumn(conn, "agents", "custom_commands", "TEXT"); TryAddColumn(conn, "messages", "is_marked", "INTEGER NOT NULL DEFAULT 0"); TryAddColumn(conn, "agents", "auto_commit", "INTEGER NOT NULL DEFAULT 0"); + TryAddColumn(conn, "agents", "use_soul", "INTEGER NOT NULL DEFAULT 1"); + TryAddColumn(conn, "agents", "use_identity", "INTEGER NOT NULL DEFAULT 1"); + TryAddColumn(conn, "agents", "use_user_info", "INTEGER NOT NULL DEFAULT 1"); + TryAddColumn(conn, "agents", "use_memory", "INTEGER NOT NULL DEFAULT 1"); } private void TryAddColumn(SqliteConnection conn, string table, string column, string type) @@ -148,8 +152,8 @@ public class DatabaseService agent.CreatedAt = now; agent.UpdatedAt = now; await conn.ExecuteAsync(@" - INSERT INTO agents (agent_id, name, avatar, description, model, tool_choice, custom_commands, auto_commit, is_deleted, created_at, updated_at) - VALUES (@AgentId, @Name, @Avatar, @Description, @Model, @ToolChoice, @CustomCommands, @AutoCommit, 0, @CreatedAt, @UpdatedAt) + INSERT INTO agents (agent_id, name, avatar, description, model, tool_choice, custom_commands, auto_commit, use_soul, use_identity, use_user_info, use_memory, is_deleted, created_at, updated_at) + VALUES (@AgentId, @Name, @Avatar, @Description, @Model, @ToolChoice, @CustomCommands, @AutoCommit, @UseSoul, @UseIdentity, @UseUserInfo, @UseMemory, 0, @CreatedAt, @UpdatedAt) ", agent); return agent; } @@ -175,7 +179,9 @@ public class DatabaseService await conn.ExecuteAsync(@" UPDATE agents SET name = @Name, avatar = @Avatar, description = @Description, model = @Model, tool_choice = @ToolChoice, - custom_commands = @CustomCommands, auto_commit = @AutoCommit, updated_at = @UpdatedAt + custom_commands = @CustomCommands, auto_commit = @AutoCommit, + use_soul = @UseSoul, use_identity = @UseIdentity, use_user_info = @UseUserInfo, use_memory = @UseMemory, + updated_at = @UpdatedAt WHERE agent_id = @AgentId ", agent); } diff --git a/Services/SystemPromptBuilder.cs b/Services/SystemPromptBuilder.cs index cb2debd..b784932 100644 --- a/Services/SystemPromptBuilder.cs +++ b/Services/SystemPromptBuilder.cs @@ -12,7 +12,7 @@ public static class SystemPromptBuilder // IDENTITY.md - Wer bin ich (ersetzt "Du bist {Name}.") var hasIdentity = false; - if (memoryService != null && !string.IsNullOrWhiteSpace(agent.AgentId)) + if (agent.UseIdentity && memoryService != null && !string.IsNullOrWhiteSpace(agent.AgentId)) { var identity = memoryService.ReadMemoryFile(agent.AgentId, "IDENTITY.md"); if (!string.IsNullOrEmpty(identity)) @@ -25,7 +25,7 @@ public static class SystemPromptBuilder parts.Add($"Du bist {agent.Name}."); // SOUL.md - Persönlichkeit + Regeln - if (memoryService != null && !string.IsNullOrWhiteSpace(agent.AgentId)) + if (agent.UseSoul && memoryService != null && !string.IsNullOrWhiteSpace(agent.AgentId)) { var soul = memoryService.ReadMemoryFile(agent.AgentId, "SOUL.md"); if (!string.IsNullOrEmpty(soul)) @@ -33,7 +33,7 @@ public static class SystemPromptBuilder } // USER.md - Global (aus data-Ordner) - if (!string.IsNullOrWhiteSpace(dataDir)) + if (agent.UseUserInfo && !string.IsNullOrWhiteSpace(dataDir)) { var userFile = System.IO.Path.Combine(dataDir, "USER.md"); if (System.IO.File.Exists(userFile)) @@ -67,7 +67,7 @@ Wenn der User auf eine bestimmte Zeile in einer Datei verweist (z.B. `[Datei: fo parts.Add($"## Kontext\n{session.Context}"); // Memory-System - if (memoryService != null && !string.IsNullOrWhiteSpace(agent.AgentId)) + if (agent.UseMemory && memoryService != null && !string.IsNullOrWhiteSpace(agent.AgentId)) { var memoryLines = new List { diff --git a/wwwroot/index.html b/wwwroot/index.html index e2569dc..0fa7ef4 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -125,6 +125,22 @@ Auto-Commit erlauben (Agent darf eigenständig committen) + + + +
diff --git a/wwwroot/js/pages/agent-page.js b/wwwroot/js/pages/agent-page.js index 8212b3a..0867532 100644 --- a/wwwroot/js/pages/agent-page.js +++ b/wwwroot/js/pages/agent-page.js @@ -20,6 +20,10 @@ registerPage('agent', { const modelEl = document.getElementById('agentModel'); const toolChoiceEl = document.getElementById('agentToolChoice'); const autoCommitEl = document.getElementById('agentAutoCommit'); + const useSoulEl = document.getElementById('agentUseSoul'); + const useIdentityEl = document.getElementById('agentUseIdentity'); + const useUserInfoEl = document.getElementById('agentUseUserInfo'); + const useMemoryEl = document.getElementById('agentUseMemory'); const avatarPreview = document.getElementById('avatarPreview'); const avatarInput = document.getElementById('avatarInput'); const avatarBtn = document.getElementById('avatarBtn'); @@ -39,6 +43,10 @@ registerPage('agent', { modelEl.value = agent.model || 'sonnet'; toolChoiceEl.checked = (agent.toolChoice || 'any') === 'any'; autoCommitEl.checked = !!agent.autoCommit; + useSoulEl.checked = agent.useSoul !== false; + useIdentityEl.checked = agent.useIdentity !== false; + useUserInfoEl.checked = agent.useUserInfo !== false; + useMemoryEl.checked = agent.useMemory !== false; _agentAvatarData = agent.avatar || null; deleteBtn.hidden = false; @@ -100,6 +108,10 @@ registerPage('agent', { model: modelEl.value, toolChoice: toolChoiceEl.checked ? 'any' : 'auto', autoCommit: autoCommitEl.checked, + useSoul: useSoulEl.checked, + useIdentity: useIdentityEl.checked, + useUserInfo: useUserInfoEl.checked, + useMemory: useMemoryEl.checked, avatar: _agentAvatarData, customCommands: getCommandsFromUI(commandsList) };