-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Python: [BREAKING] Types API Review improvements #3647
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
Merged
eavanvalkenburg
merged 16 commits into
microsoft:main
from
eavanvalkenburg:types-api-review-3575
Feb 4, 2026
Merged
Python: [BREAKING] Types API Review improvements #3647
eavanvalkenburg
merged 16 commits into
microsoft:main
from
eavanvalkenburg:types-api-review-3575
Feb 4, 2026
+3,767
−3,229
Conversation
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
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Member
dmytrostruk
approved these changes
Feb 4, 2026
4 tasks
- Remove EnumLike metaclass from _types.py
- Replace Role class with NewType('Role', str) + RoleLiteral
- Replace FinishReason class with NewType('FinishReason', str) + FinishReasonLiteral
- Update all usages across codebase to use string literals
- Remove .value access patterns (direct string comparison now works)
- Add backward compatibility for legacy dict serialization format
- Update tests to reflect new string-based types
Addresses microsoft#3591, microsoft#3615
- Remove overloads from ChatResponse.__init__ - Remove text parameter from ChatResponse.__init__ - Remove | dict[str, Any] from finish_reason and usage_details params - Remove **kwargs from AgentResponse.__init__ - Both now accept ChatMessage | Sequence[ChatMessage] | None for messages - Update docstrings and examples to reflect changes - Fix tests that were using removed kwargs - Fix Role type hint usage in ag-ui utils
…microsoft#3597) - Remove text parameter from ChatResponseUpdate.__init__ - Remove text parameter from AgentResponseUpdate.__init__ - Remove **kwargs from both update classes - Simplify contents parameter type to Sequence[Content] | None - Update all usages to use contents=[Content.from_text(...)] pattern - Fix imports in test files - Update docstrings and examples
- ChatResponse.from_chat_response_updates → ChatResponse.from_updates - ChatResponse.from_chat_response_generator → ChatResponse.from_update_generator - AgentResponse.from_agent_run_response_updates → AgentResponse.from_updates
…crosoft#3595) - Remove try_parse_value method from ChatResponse - Remove try_parse_value method from AgentResponse - Remove try_parse_value calls from from_updates and from_update_generator methods - Update samples to use try/except with response.value instead - Update tests to use response.value pattern - Users should now use response.value with try/except for safe parsing
…icrosoft#3596) - Add agent_id parameter to AgentResponse class - Document that author_name is on ChatMessage objects, not responses - Update ChatResponse docstring with author_name note - Update AgentResponse docstring with author_name note
- Make contents a positional argument accepting Sequence[Content | str]
- Auto-convert strings in contents to TextContent
- Remove overloads, keep text kwarg for backward compatibility with serialization
- Update _parse_content_list to handle string items
- Update all usages across codebase to use new format: ChatMessage("role", ["text"])
- Update prepare_messages and normalize_messages to accept Content - Update type signatures in _agents.py and _clients.py - Add tests for Content input handling
Update all remaining ChatMessage(role=..., text=...) to use new
ChatMessage('role', ['text']) signature.
- Fix redis provider: remove .value access on string literals - Fix durabletask ensure_response_format: set _response_format before accessing .value
- Fix ollama _chat_client: remove .value on string literals - Fix ollama _chat_client: rename ai_model_id to model_id - Fix _parse_content_list: skip None values gracefully
93d7f47 to
4397131
Compare
moonbox3
approved these changes
Feb 4, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
Summary
This PR addresses all type-related sub-issues from the Python Single Agent API Review (#3575).
Changes
Replace Role and FinishReason with NewType + Literal
EnumLikemetaclassRoleandFinishReasonclasses withNewType+LiteralRoleLiteral | strfor IDE autocomplete while accepting custom valuesSimplify ChatResponse/AgentResponse type hints
messagesparameter to acceptChatMessage | Sequence[ChatMessage] | Nonetextparameter and**kwargsfrom__init__Remove text parameter from ChatResponseUpdate/AgentResponseUpdate
textparameter (usecontents=[Content.from_text(...)]instead)**kwargsfrom both classesRename from_chat_response_updates
from_chat_response_updates→from_updatesonChatResponsefrom_chat_response_generator→from_update_generatoronChatResponsefrom_agent_run_response_updates→from_updatesonAgentResponseRemove try_parse_value method
ChatResponseandAgentResponsetry/exceptwith.valueproperty insteadDocumentation clarification
agent_idparameter toAgentResponseandAgentResponseUpdateauthor_nameis onChatMessageobjects, not responsesSimplify ChatMessage.init signature
contentsa positional argument:ChatMessage("role", ["text"])TextContenttextkwarg for backward compatibility with serializationAllow Content as input on run/get_response
prepare_messagesandnormalize_messagesto acceptContentBreaking Changes
RoleandFinishReasonare nowNewTypeinstead of classes (no.valueaccess)ChatMessagesignature changed: useChatMessage("role", ["text"])instead ofChatMessage(role="role", text="text")try_parse_valueremoved - usetry/exceptwith.valuepropertytextparameter removed fromChatResponseUpdateandAgentResponseUpdatefrom_chat_response_updates→from_updates, etc.Closes
Closes #3591
Closes #3592
Closes #3593
Closes #3595
Closes #3596
Closes #3597
Closes #3615
Closes #3618
Testing