Skip to content

chore(python-sdk): literal defaults #49

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

stevenh
Copy link
Contributor

@stevenh stevenh commented Jun 3, 2025

Set the event type and message role using pydantic Field and disable setting in the constructor to help prevent accidental misuse while reducing unnecessary boilerplate code.

Replace Role type alias with an Enum to eliminate repeating string literals and align with EventType.

Use Field(min_length=1) to validate TextMessageContentEvent delta, simplifying the code.

Fixes #41

@stevenh stevenh force-pushed the chore/default-literals branch 2 times, most recently from 117f6ef to 097f6fd Compare June 3, 2025 20:06
@stevenh stevenh marked this pull request as ready for review June 3, 2025 20:08
Set the event type and message role using pydantic Field and disable
setting in the constructor to help prevent accidental misuse while
reducing unnecessary boilerplate code.

Replace Role type alias with an Enum to eliminate repeating string
literals and align with EventType.

Use Field(min_length=1) to validate TextMessageContentEvent delta,
simplifying the code.

Fixes ag-ui-protocol#41
Copy link

@Copilot 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 refactors the SDK to enforce literal defaults for event types and message roles using pydantic Fields with init=False, reducing boilerplate and minimizing misuse. Key changes include:

  • Removing explicit specification of role and type in message/event constructors.
  • Replacing Role type alias with a Role Enum.
  • Adding Field(min_length=1) validation for TextMessageContentEvent delta.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
python-sdk/tests/test_types.py Removed redundant role entries from tests for message serialization
python-sdk/tests/test_events.py Removed explicit type and role fields from event tests
python-sdk/tests/test_encoder.py Removed explicit type field in event creation for encoding tests
python-sdk/ag_ui/core/types.py Updated message role definitions to use the Role Enum and Field with init=False
python-sdk/ag_ui/core/events.py Updated event type definitions to use Field with literal defaults and init=False
Comments suppressed due to low confidence (1)

python-sdk/tests/test_events.py:367

  • With the use of Field(min_length=1) for the 'delta' field, pydantic now raises a ValidationError instead of a ValueError when an empty string is provided. Update the test in test_validation_constraints to expect ValidationError instead of ValueError.
TextMessageContentEvent(

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.

[python] Defined SDK events should hardcode the type
1 participant