Skip to content

Add created_at to BaseChatMessage and BaseAgentEvent#6557

Merged
ekzhu merged 6 commits intomicrosoft:mainfrom
withsmilo:add-created-at-to-message-definition
May 23, 2025
Merged

Add created_at to BaseChatMessage and BaseAgentEvent#6557
ekzhu merged 6 commits intomicrosoft:mainfrom
withsmilo:add-created-at-to-message-definition

Conversation

@withsmilo
Copy link
Copy Markdown
Contributor

Why are these changes needed?

I added created_at to both BaseChatMessage and BaseAgentEvent classes that store the time these Pydantic model instances are generated. And then users will be able to use created_at to build up a customized external persisting state management layer for their case.

Related issue number

#6169 (reply in thread)

Checks

@jackgerrits
Copy link
Copy Markdown
Contributor

I think if you need functionality like this then metadata should be used in custom agents. @ekzhu thoughts?

@ekzhu
Copy link
Copy Markdown
Contributor

ekzhu commented May 20, 2025

I think this is fine. metadata can only be populated by custom agents, but timestamp is general enough to be considered a common attribute with wide range of use cases.

@withsmilo
Copy link
Copy Markdown
Contributor Author

Thanks for feedbacks, @ekzhu and @jackgerrits . Could you please review this PR when you have time?

@ekzhu ekzhu requested a review from Copilot May 21, 2025 16:17
@ekzhu ekzhu self-assigned this May 21, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR instruments messages and events with a creation timestamp, adjusts tests to ignore that dynamic field, and tidies imports in the user guide.

  • Adds a created_at field (UTC timezone) to both BaseChatMessage and BaseAgentEvent
  • Introduces helper functions (compare_messages, compare_message_lists, compare_task_results) to compare models without the dynamic timestamp
  • Updates tests to use those comparators instead of direct equality, and reorders imports in the tutorial notebook

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

File Description
python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/models.ipynb Reordered imports for Path and Image
python/packages/autogen-agentchat/src/autogen_agentchat/messages.py Added created_at: datetime to core message/event models
python/packages/autogen-agentchat/tests/utils.py Created comparison helpers and switched the log handler to use model_dump_json
python/packages/autogen-agentchat/tests/ (test_group_chat*.py, test_assistant_agent.py, etc.) Replaced direct == assertions with compare_messages/compare_task_results
Comments suppressed due to low confidence (2)

python/packages/autogen-agentchat/src/autogen_agentchat/messages.py:89

  • There are no tests verifying the new created_at field. Consider adding tests to assert that instances of BaseChatMessage and BaseAgentEvent include a timezone-aware created_at attribute.
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/models.ipynb:454

  • The tutorial notebook hasn’t been updated to illustrate the new created_at field. Consider adding an example that shows how to read or persist created_at from BaseChatMessage and BaseAgentEvent.
"source": [

Comment thread python/packages/autogen-agentchat/tests/utils.py
Comment thread python/packages/autogen-agentchat/tests/utils.py
@withsmilo
Copy link
Copy Markdown
Contributor Author

withsmilo commented May 22, 2025

@ekzhu
I found there was a bug from https://github.com/microsoft/autogen/actions/runs/15168637196/job/42652881189?pr=6557, and pushed a patch commit (b765422) to this PR.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.54%. Comparing base (726e0be) to head (def21aa).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6557   +/-   ##
=======================================
  Coverage   79.53%   79.54%           
=======================================
  Files         225      225           
  Lines       16642    16647    +5     
=======================================
+ Hits        13237    13242    +5     
  Misses       3405     3405           
Flag Coverage Δ
unittests 79.54% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ekzhu ekzhu merged commit db125fb into microsoft:main May 23, 2025
64 checks passed
@withsmilo withsmilo deleted the add-created-at-to-message-definition branch May 23, 2025 07:15
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.

4 participants