Skip to content

refine instruction log settings #961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; } = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
12 changes: 10 additions & 2 deletions src/Infrastructure/BotSharp.Logger/Hooks/InstructionLogHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ public InstructionLogHook(
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>();
Expand All @@ -49,6 +56,7 @@ public override async Task OnResponseGenerated(InstructResponseModel response)
UserId = user?.Id
}
});
return;

await base.OnResponseGenerated(response);
}
}
5 changes: 4 additions & 1 deletion src/WebStarter/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@
},

"Instruction": {
"EnableLog": true
"Logging": {
"Enabled": true,
"ExcludedAgentIds": []
}
},

"ChatHub": {
Expand Down
Loading