-
Notifications
You must be signed in to change notification settings - Fork 1k
Python: [BREAKING]: Introducing Options as TypedDict and Generic #3140
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
base: main
Are you sure you want to change the base?
Python: [BREAKING]: Introducing Options as TypedDict and Generic #3140
Conversation
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.
Pull request overview
This pull request introduces a major breaking change that refactors the chat options system from a class-based ChatOptions to a TypedDict-based approach with generic type support. The changes enable:
- Type-safe, IDE-autocomplete-friendly options using TypedDict
- Generic support allowing custom provider-specific options without code changes
- Runtime extensibility for new provider parameters
- Consistent parameter passing via
optionsdict instead of mixed kwargs and ChatOptions objects
Key Changes:
- Converted
ChatOptionsfrom a Pydantic-like class to a TypedDict - Changed
chat_optionsparameter tooptions(dict) throughout the codebase - Introduced provider-specific TypedDict options (OpenAIChatOptions, OllamaChatOptions, etc.)
- Added Generic[TOptions] to all chat clients and agents
- Updated all samples, tests, and middleware to use the new dict-based approach
Reviewed changes
Copilot reviewed 100 out of 101 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| python/packages/core/agent_framework/_types.py | Core ChatOptions refactored from class to TypedDict with utility functions |
| python/packages/core/agent_framework/_clients.py | BaseChatClient made generic over TOptions |
| python/packages/core/agent_framework/_agents.py | ChatAgent updated to use dict-based options |
| python/packages/core/agent_framework/openai/*.py | OpenAI clients updated with OpenAIChatOptions, OpenAIResponsesOptions |
| python/packages/core/agent_framework/azure/*.py | Azure clients updated with provider-specific options |
| python/packages/ollama/agent_framework_ollama/*.py | Ollama client updated with OllamaChatOptions |
| python/packages/foundry_local/*.py | Foundry Local client updated with options support |
| python/packages/core/agent_framework/_middleware.py | Middleware updated to work with dict-based options |
| python/packages/core/agent_framework/observability.py | Observability updated for dict-based options |
| python/samples/**/*.py | All samples updated to use new options parameter |
| python/packages//tests/**/.py | All tests updated to use dict-based options |
python/packages/bedrock/agent_framework_bedrock/_chat_client.py
Outdated
Show resolved
Hide resolved
python/packages/core/agent_framework/openai/_responses_client.py
Outdated
Show resolved
Hide resolved
python/packages/ag-ui/agent_framework_ag_ui_examples/agents/ui_generator_agent.py
Show resolved
Hide resolved
2a87cc3 to
b105b73
Compare
7b8ee4c to
c982599
Compare
python/packages/ag-ui/agent_framework_ag_ui_examples/agents/document_writer_agent.py
Outdated
Show resolved
Hide resolved
| # Options not supported in Bedrock Converse API: | ||
| seed: Not supported. | ||
| frequency_penalty: Not supported. | ||
| presence_penalty: Not supported. | ||
| allow_multiple_tool_calls: Not supported (models handle parallel calls automatically). | ||
| response_format: Not directly supported (use model-specific prompting). | ||
| user: Not supported. | ||
| store: Not supported. | ||
| logit_bias: Not supported. | ||
| metadata: Not supported (use additional_properties for additionalModelRequestFields). |
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.
Most of these parameters are excluded in Anthropic, Azure AI V1, Bedrock and Ollama, so I would probably remove them from base ChatOptions and specify them only in chat client implementations that support it (which is OpenAI and Azure AI V2 only, unless I'm missing something?)
In this case, we don't need to override them with None in most of these providers and users won't have to do it when implementing their own ChatOptions.
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.
I've kept the same list of MEAI's ChatOptions that we also already had in the "old" ChatOptions. I will checkin with some folks to see what their thinking is around evolving that.
python/packages/bedrock/agent_framework_bedrock/_chat_client.py
Outdated
Show resolved
Hide resolved
576ef6c to
e8ef41a
Compare
Motivation and Context
This PR makes a major overhaul of the way you can supply options to your chat clients, it leverages a TypedDict called ChatOptions for all the common options and derived classes from there for each provider. It leverages Generics to allow a developer to create specific Options and still get type-checking and IDE autocomplete for those.
For instance, when you want to use reasoning models with the OpenAI Chat Completion API, you could do this:
This makes it very easy to leverage the latest and greatest options from different providers without needing code changes in our codebase on day 1 to support.
The rest of the setup is described in the included ADR.
Addresses item 10 from: #2902
Addresses item a part of item 5 from: #3096
Description
Contribution Checklist