Merge pull request #961 from iceljc/master

refine instruction log settings
This commit is contained in:
iceljc 2025-03-21 15:14:46 -05:00 committed by GitHub
commit 8710e4c96c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 25 additions and 7 deletions

View file

@ -8,16 +8,16 @@ public class InstructHookBase : IInstructHook
public virtual async Task BeforeCompletion(Agent agent, RoleDialogModel message)
{
return;
await Task.CompletedTask;
}
public virtual async Task AfterCompletion(Agent agent, InstructResult result)
{
return;
await Task.CompletedTask;
}
public virtual async Task OnResponseGenerated(InstructResponseModel response)
{
return;
await Task.CompletedTask;
}
}

View file

@ -2,5 +2,11 @@ namespace BotSharp.Abstraction.Instructs.Settings;
public class InstructionSettings
{
public bool EnableLog { get; set; }
public InstructionLogSetting Logging { get; set; } = new();
}
public class InstructionLogSetting
{
public bool Enabled { get; set; } = true;
public List<string> ExcludedAgentIds { get; set; } = [];
}

View file

@ -5,6 +5,7 @@ namespace BotSharp.Abstraction.Loggers.Models;
public class InstructionLogModel
{
[JsonPropertyName("id")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string Id { get; set; } = default!;
[JsonPropertyName("agent_id")]

View file

@ -26,7 +26,14 @@ public class InstructionLogHook : InstructHookBase
public override async Task OnResponseGenerated(InstructResponseModel response)
{
var settings = _services.GetRequiredService<InstructionSettings>();
if (!settings.EnableLog || response == null) return;
if (response == null
|| string.IsNullOrWhiteSpace(response.AgentId)
|| settings == null
|| !settings.Logging.Enabled
|| settings.Logging.ExcludedAgentIds.Contains(response.AgentId))
{
return;
}
var db = _services.GetRequiredService<IBotSharpRepository>();
var state = _services.GetRequiredService<IConversationStateService>();
@ -49,6 +56,7 @@ public class InstructionLogHook : InstructHookBase
UserId = user?.Id
}
});
return;
await base.OnResponseGenerated(response);
}
}

View file

@ -223,7 +223,10 @@
},
"Instruction": {
"EnableLog": true
"Logging": {
"Enabled": true,
"ExcludedAgentIds": []
}
},
"ChatHub": {