Skip to content

Conversation

@iceljc
Copy link
Collaborator

@iceljc iceljc commented Jul 29, 2025

PR Type

Enhancement


Description

  • Add optional agent filtering to RefreshAgents method

  • Create new AgentMigrationModel for API request handling

  • Update controller to accept agent IDs parameter

  • Improve error message clarity for migration results


Diagram Walkthrough

flowchart LR
  A["AgentController"] -- "POST /refresh-agents" --> B["AgentMigrationModel"]
  B -- "agentIds filter" --> C["AgentService.RefreshAgents"]
  C -- "filtered directories" --> D["Agent Migration Process"]
Loading

File Walkthrough

Relevant files
Enhancement
IAgentService.cs
Update interface with optional agent filtering                     

src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs

  • Add optional agentIds parameter to RefreshAgents method signature
+1/-1     
AgentService.RefreshAgents.cs
Implement selective agent refresh with filtering                 

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs

  • Add optional agentIds parameter to method implementation
  • Filter directories based on provided agent IDs
  • Update error message from "refreshed" to "migrated"
+9/-3     
AgentController.cs
Update controller to accept migration request model           

src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs

  • Change method parameter from empty to AgentMigrationModel
  • Pass agent IDs from request body to service
+2/-2     
AgentMigrationModel.cs
Add new request model for agent migration                               

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentMigrationModel.cs

  • Create new model class for agent migration requests
  • Add AgentIds property with JSON serialization attributes
+10/-0   

@qodo-merge-pro
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Logic Issue

The directory filtering logic uses Contains to match agent IDs with directory names, which could lead to false positives if one agent ID is a substring of another. The comparison should be exact matches only.

    dirs = dirs.Where(x => agentIds.Contains(x.Split(Path.DirectorySeparatorChar).Last())).ToArray();
}
Inconsistent Message

The success message says "Agents are migrated" but the failure message says "No agent gets migrated", creating inconsistency in terminology between migration and refresh operations.

    refreshResult = "No agent gets migrated!";
}

@qodo-merge-pro
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Add case-insensitive agent filtering

The filtering should use case-insensitive comparison to handle potential casing
differences in agent IDs. This prevents issues where agent directories might
have different casing than the provided filter IDs.

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs [32-35]

 if (!agentIds.IsNullOrEmpty())
 {
-    dirs = dirs.Where(x => agentIds.Contains(x.Split(Path.DirectorySeparatorChar).Last())).ToArray();
+    dirs = dirs.Where(x => agentIds.Contains(Path.GetFileName(x), StringComparer.OrdinalIgnoreCase)).ToArray();
 }
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly points out that agent ID comparison should be case-insensitive to prevent bugs, especially since directory names can be case-insensitive on some file systems like Windows.

Medium
Fix cross-platform path handling

The current filtering logic may fail on different operating systems due to path
separator differences. Use Path.GetFileName() instead of manually splitting by
Path.DirectorySeparatorChar for better cross-platform compatibility.

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs [31-35]

 var dirs = Directory.GetDirectories(agentDir);
 if (!agentIds.IsNullOrEmpty())
 {
-    dirs = dirs.Where(x => agentIds.Contains(x.Split(Path.DirectorySeparatorChar).Last())).ToArray();
+    dirs = dirs.Where(x => agentIds.Contains(Path.GetFileName(x))).ToArray();
 }
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that using Path.GetFileName() is more robust and idiomatic for cross-platform path manipulation than splitting the string by Path.DirectorySeparatorChar.

Medium
  • More

@iceljc iceljc merged commit d1a3ded into SciSharp:master Jul 29, 2025
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant