refine instruction log settings

This commit is contained in:
Jicheng Lu 2025-03-21 15:00:53 -05:00
parent b2e6db6999
commit 52e6c6a4b0
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": {