Skip to content

Filter conversation by agent ids #1102

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

iceljc
Copy link
Collaborator

@iceljc iceljc commented Jul 14, 2025

PR Type

Enhancement


Description

  • Add support for filtering conversations by multiple agent IDs

  • Enhance ConversationFilter with AgentIds list property

  • Update repository implementations to handle multi-agent filtering

  • Add convenience method for state inheritance in SideCarOptions


Changes diagram

flowchart LR
  A["ConversationFilter"] --> B["Add AgentIds property"]
  B --> C["FileRepository implementation"]
  B --> D["MongoRepository implementation"]
  C --> E["Contains-based filtering"]
  D --> F["In-based filtering"]
  G["SideCarOptions"] --> H["Add InheritStates method"]
Loading

Changes walkthrough 📝

Relevant files
Enhancement
ConversationFilter.cs
Add multi-agent filtering property                                             

src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationFilter.cs

  • Add AgentIds property as List? to support multiple agent filtering
  • +1/-0     
    SideCarOptions.cs
    Add state inheritance convenience method                                 

    src/Infrastructure/BotSharp.Abstraction/SideCar/Models/SideCarOptions.cs

  • Modernize Empty() method with target-typed new expression
  • Add InheritStates() static method for convenient state inheritance
    configuration
  • +10/-1   
    FileRepository.Conversation.cs
    Implement multi-agent filtering in FileRepository               

    src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs

  • Migrate single AgentId to AgentIds list for backward compatibility
  • Update filtering logic to use Contains() method for multi-agent
    support
  • +8/-2     
    MongoRepository.Conversation.cs
    Implement multi-agent filtering in MongoRepository             

    src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs

  • Migrate single AgentId to AgentIds list for backward compatibility
  • Update MongoDB filtering to use In() operator for multi-agent queries
  • +8/-2     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • 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

    Potential Bug

    The backward compatibility logic for migrating single AgentId to AgentIds list modifies the filter object directly, which could cause unexpected side effects if the same filter is reused elsewhere in the application.

    if (filter?.AgentId != null)
    {
        filter.AgentIds ??= [];
        filter.AgentIds.Add(filter.AgentId);
    }
    Potential Bug

    Same issue as FileRepository - the filter object is being modified in-place during the AgentId to AgentIds migration, which could affect other parts of the code using the same filter instance.

    if (filter?.AgentId != null)
    {
        filter.AgentIds ??= [];
        filter.AgentIds.Add(filter.AgentId);
    }

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Prevent duplicate agent IDs

    The migration logic should check if AgentIds already contains the AgentId to
    avoid duplicates. This prevents the same agent ID from being added multiple
    times if the method is called repeatedly.

    src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs [399-403]

     if (filter?.AgentId != null)
     {
         filter.AgentIds ??= [];
    -    filter.AgentIds.Add(filter.AgentId);
    +    if (!filter.AgentIds.Contains(filter.AgentId))
    +    {
    +        filter.AgentIds.Add(filter.AgentId);
    +    }
     }
    • Apply / Chat
    Suggestion importance[1-10]: 6

    __

    Why: The suggestion correctly points out that if the same filter object is reused across multiple calls, the AgentIds list will grow with duplicates. Adding a Contains check makes the backward-compatibility logic more robust.

    Low
    • More

    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