-
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
python/packages/bedrock/agent_framework_bedrock/_chat_client.py
Outdated
Show resolved
Hide resolved
576ef6c to
e8ef41a
Compare
359c4ba to
314a320
Compare
|
We're tracking docs updated for this, too, right? |
f0e756c to
d391ecc
Compare
d391ecc to
9a75973
Compare
* WIP typeddict for options * updated all clients and ChatAgents * updated everything * added ADR * fix mypy * proper typevar imports * fixed import * fixed other imports * slight update in the sample * updated from feedback * fixes * fixed missing covariants and test fixes * fixed typing * updated anthropic thinking config * ruff fixes * fixed int tests * fix tests and mypy
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