You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The use of C# list literal syntax in AddDialogs calls (e.g., routingCtx.AddDialogs([value.Data])) requires C# 12/.NET 8. Ensure the project targets compatible language/runtime or replace with new List { value.Data } for broader compatibility.
Multiple calls to Context.AddDialogs use bracket list literals ([message]/[msg]). Verify language version or replace with explicit List initializers to avoid compile issues across projects.
GetDialogs now returns a new list each call. Call sites that loop frequently may allocate unnecessarily; consider exposing read-only view or keeping existing API but documenting copy behavior to avoid performance regressions.
Refactor RoutingService to eliminate the redundant local dialogs list. Instead, use RoutingContext as the single source of truth for dialog history by removing the dialogs parameter from InvokeAgent and InvokeFunction.
publicpartialclassRoutingService{publicasyncTask<bool>InvokeAgent(stringagentId, ...)// No 'dialogs' parameter{vardialogs=Context.GetDialogs();// Fetched from context// ...varmessage= ...;Context.AddDialogs([message]);// Single source of truth is updatedreturntrue;}privateasyncTask<bool>InvokeFunction(RoleDialogModelmessage, ...)// No 'dialogs' parameter{// ...awaitInvokeAgent(curAgentId,options);// ...}}
Suggestion importance[1-10]: 9
__
Why: This is an excellent design suggestion that correctly identifies redundant state management, which can lead to bugs and maintenance issues. Centralizing dialog history in RoutingContext would significantly improve the code's robustness and clarity.
High
Learned best practice
Add null-safe logging guards
Guard potentially null properties in debug logging by using null-conditional operators and safe defaults to prevent NullReferenceExceptions.
Why:
Relevant best practice - Ensure null-safety on optional inputs and object properties when accessing nested properties in logs to avoid NullReferenceExceptions.
Low
General
Simplify and optimize the method
Refactor the AddDialogs method to avoid redundant list allocations when the input dialogs is null by using a direct null check instead of creating intermediate empty lists.
public void AddDialogs(List<RoleDialogModel> dialogs)
{
- var items = new List<RoleDialogeModel>(dialogs ?? []);- _dialogs ??= [];- _dialogs.AddRange(items);+ if (dialogs != null)+ {+ _dialogs ??= [];+ _dialogs.AddRange(dialogs);+ }
}
Apply / Chat
Suggestion importance[1-10]: 3
__
Why: The suggestion correctly identifies a minor inefficiency and proposes a cleaner, slightly more performant implementation, which is a valid but low-impact improvement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement
Description
Add
AddDialogsmethod to routing context interfaceRefactor dialog management for better consistency
Improve logging format in observers
Minor code cleanup and variable renaming
Diagram Walkthrough
File Walkthrough
IRoutingContext.cs
Add AddDialogs method to interfacesrc/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs
AddDialogsmethod to interface for appending dialog listsConversationObserver.cs
Refactor observer with improved loggingsrc/Infrastructure/BotSharp.Core/MessageHub/Observers/ConversationObserver.cs
routeCtxtoroutingCtxAddDialogsmethod callRoutingContext.cs
Implement AddDialogs with defensive copyingsrc/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs
AddDialogsmethod for appending dialog collectionsSetDialogsto create defensive copiesGetDialogsto return defensive copiesRoutingService.InvokeAgent.cs
Use AddDialogs for message handlingsrc/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs
Context.SetDialogscalls withContext.AddDialogsFileInstructService.SelectFile.cs
Rename routing context variablesrc/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.SelectFile.cs
routeContexttoroutingCtxfor consistencyChatHubObserver.cs
Add import and improve loggingsrc/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs
BotSharp.Core.MessageHub.ObserversMySqlService.cs
Reorder using statementssrc/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs
ExcelHandlerSettings.cs
Add documentation commentsrc/Plugins/BotSharp.Plugin.ExcelHandler/Settings/ExcelHandlerSettings.cs