Skip to content

Fix: Make Flags.from_dict generic to support all subclasses #261

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 1 commit into
base: main
Choose a base branch
from

Conversation

Mirza-Samad-Ahmed-Baig
Copy link

@Mirza-Samad-Ahmed-Baig Mirza-Samad-Ahmed-Baig commented Jul 9, 2025

This PR addresses a bug in the Flags.from_dict class method where it was hardcoded to return an ObsFlags instance, preventing it from correctly instantiating other subclasses like ActionFlags. The method has been updated to be fully generic. It now uses the class it is called on (cls) for instantiation and filters the input dictionary to only include keys that correspond to the class's fields. This ensures that any subclass of Flags can be correctly created from a dictionary, making the implementation more robust and less error-prone.

Description by Korbit AI

What change is being made?

Make the Flags.from_dict method generic to support all subclasses by modifying it to filter dictionary keys based on the subclass's fields and use the class itself instead of a hardcoded subclass for instantiation.

Why are these changes being made?

The existing implementation of Flags.from_dict was not generic, as it specifically returned an ObsFlags instance, limiting support to that subclass only. By making it generic and utilizing subclass fields dynamically, we ensure compatibility with any subclass, improving code reusability and flexibility.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've completed my review and didn't find any issues... but I did find this frog.

           .--._.--.
          ( O     O )
          /   . .   \
         .`._______.'.
        /(           )\
      _/  \  \   /  /  \_
   .~   `  \  \ /  /  '   ~.
  {    -.   \  V  /   .-    }
_ _`.    \  |  |  |  /    .'_ _
>_       _} |  |  | {_       _<
 /. - ~ ,_-'  .^.  `-_, ~ - .\
         '-'|/   \|`-`
Files scanned
File Path Reviewed
src/agentlab/agents/dynamic_prompting.py

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant