feat(utils): add configurable ID factory via set_id_factory()#1839
Open
lajxw wants to merge 6 commits into
Open
feat(utils): add configurable ID factory via set_id_factory()#1839lajxw wants to merge 6 commits into
lajxw wants to merge 6 commits into
Conversation
DavdGao
requested changes
Jun 12, 2026
DavdGao
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR. Two suggestions on the test file:
- Make the tests async to match our template. Please follow
tests/test_template.py, which usesIsolatedAsyncioTestCasewithasyncSetUp / asyncTearDowninstead of the syncunittest.TestCase. - Trim the test cases. A few of the current tests add little value (e.g. asserting the public export is the internal function, the non-callable TypeError check). Please keep just the two that capture the intent:
- the default id_factory still returns uuid.uuid4().hex
- after from agentscope import set_id_factory, a custom factory actually takes effect on entities
Member
|
@lajxw Plz format the code by running |
Author
|
I have made the requested changes; please review again. |
DavdGao
reviewed
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentScope Version
2.0.1
Description
Background: AgentScope hardcodes uuid.uuid4().hex for all entity IDs. This prevents alignment with production databases that use other ID strategies such as UUIDv7 (time-ordered), causing block_id mismatch between streaming events and persisted records.
Changes:
- Added _id_factory global and set_id_factory() in src/agentscope/_utils/_common.py, allowing users to override the default ID generation strategy at startup.
- Exported set_id_factory from src/agentscope/init.py as public API.
- Replaced 34 occurrences of uuid.uuid4().hex with _generate_id / _generate_id() across 18 entity files.
- Security-sensitive tokens (gateway tokens, Redis lock tokens) intentionally remain as uuid.uuid4().hex.
Close #1782
Checklist
Please check the following items before code is ready to be reviewed.