Skip to content

Robust AgentsModel instantiations and added Activity unit tests#108

Merged
axelsrz merged 12 commits intomainfrom
users/robrandao/activity-unit-tests
Sep 4, 2025
Merged

Robust AgentsModel instantiations and added Activity unit tests#108
axelsrz merged 12 commits intomainfrom
users/robrandao/activity-unit-tests

Conversation

@rodrigobr-msft
Copy link
Contributor

This pull request introduces several improvements to the construction and handling of activity models in the Microsoft Agents Activity library. The most significant changes include the addition of utility functions for robust model field selection, refactoring of entity imports for better modularity, and enhanced handling of optional fields to avoid setting values to None unnecessarily. There are also updates to card models and entity definitions to standardize field types.

Model Construction and Field Selection Improvements

  • Introduced pick_model_dict, pick_model, and helper classes like SkipNone in _model_utils.py to allow for dynamic and conditional inclusion of fields in model initialization internally, improving code readability and reducing errors from unset or None values.
  • Updated Activity methods (create_reply, create_trace, create_trace_activity, get_conversation_reference) to use the new helpers for safer field assignment, ensuring unset values are properly handled and reducing None assignments. [1] [2] [3] [4]

Entity and Import Refactoring

  • Refactored entity imports by moving them into a dedicated entity subpackage and updating all relevant import statements for improved modularity and maintainability. [1] [2] [3] [4] [5]
  • Removed the add_ai_to_activity function from ai_entity.py and reimplemented it in activity.py to better encapsulate its usage with activities. [1] [2]

Model and Entity Field Type Updates

  • Changed the text field type from NonEmptyString to str in AnimationCard, AudioCard, and BasicCard models for consistency and flexibility. [1] [2] [3]
  • Updated the type field in the Entity model from NonEmptyString to str for broader compatibility.

Utility and Helper Method Enhancements

  • Added a pick_properties class method to AgentsModel to allow selective copying of fields from one model instance to another, preserving unset values and supporting partial updates.

Bug Fixes and Minor Improvements

  • Improved the get_mentions method in Activity to handle cases where entities is None, preventing potential errors.
  • Fixed the logic in __is_activity to use a more precise string comparison for activity types.

These changes collectively improve the robustness, maintainability, and clarity of the activity model construction and entity handling in the codebase.

@rodrigobr-msft rodrigobr-msft changed the title Users/robrandao/activity unit tests Robust AgentsModel instantiations and added Activity unit tests Sep 2, 2025
axelsrz
axelsrz previously approved these changes Sep 4, 2025
@axelsrz axelsrz merged commit d4157fa into main Sep 4, 2025
5 checks passed
@rodrigobr-msft rodrigobr-msft linked an issue Sep 8, 2025 that may be closed by this pull request
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.

create_reply leads to validation errors

2 participants

Comments