Skip to content

Commit e8ef41a

Browse files
updated from feedback
1 parent 6d3a205 commit e8ef41a

File tree

16 files changed

+128
-101
lines changed

16 files changed

+128
-101
lines changed

docs/decisions/00XX-python-typeddict-options.md renamed to docs/decisions/0011-python-typeddict-options.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ response = await client.get_response(
108108

109109
**Cons:**
110110
- More complex implementation
111-
- Requires TypeVar with default (Python 3.13+ or typing_extensions)
112111
- Some type: ignore comments needed for TypedDict field overrides
112+
- Minor: Requires TypeVar with default (Python 3.13+ or typing_extensions)
113+
114+
> [NOTE!]
115+
> In .NET this is already achieved through overloads on the `GetResponseAsync` method for each provider-specific options class, e.g., `AnthropicChatOptions`, `OpenAIChatOptions`, etc. So this does not apply to .NET.
113116
114117
### Implementation Details
115118

python/packages/ag-ui/agent_framework_ag_ui/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _unwrap_server_function_call_contents(contents: MutableSequence[Contents | d
8181
"TAGUIChatOptions",
8282
bound=TypedDict, # type: ignore[valid-type]
8383
default="AGUIChatOptions",
84-
contravariant=True,
84+
covariant=True,
8585
)
8686

8787

python/packages/ag-ui/agent_framework_ag_ui/_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class AGUIChatOptions(ChatOptions, total=False):
109109
AGUI_OPTION_TRANSLATIONS: dict[str, str] = {}
110110
"""Maps ChatOptions keys to AG-UI parameter names (protocol uses standard names)."""
111111

112-
TAGUIChatOptions = TypeVar("TAGUIChatOptions", bound=TypedDict, default="AGUIChatOptions", contravariant=True) # type: ignore[valid-type]
112+
TAGUIChatOptions = TypeVar("TAGUIChatOptions", bound=TypedDict, default="AGUIChatOptions", covariant=True) # type: ignore[valid-type]
113113

114114

115115
# endregion

python/packages/ag-ui/agent_framework_ag_ui_examples/agents/document_writer_agent.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
"""Example agent demonstrating predictive state updates with document writing."""
44

5-
from typing import Any
6-
75
from agent_framework import ChatAgent, ChatClientProtocol, ai_function
86
from agent_framework.ag_ui import AgentFrameworkAgent, DocumentWriterConfirmationStrategy
97

@@ -40,7 +38,7 @@ def write_document_local(document: str) -> str:
4038
)
4139

4240

43-
def document_writer_agent(chat_client: ChatClientProtocol[Any]) -> AgentFrameworkAgent:
41+
def document_writer_agent(chat_client: ChatClientProtocol) -> AgentFrameworkAgent:
4442
"""Create a document writer agent with predictive state updates.
4543
4644
Args:

python/packages/anthropic/agent_framework_anthropic/_chat_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ class AnthropicChatOptions(ChatOptions, total=False):
157157

158158
TAnthropicOptions = TypeVar(
159159
"TAnthropicOptions",
160-
bound=TypedDict,
160+
bound=TypedDict, # type: ignore[valid-type]
161161
default="AnthropicChatOptions",
162-
contravariant=True,
163-
) # type: ignore[valid-type]
162+
covariant=True,
163+
)
164164

165165
# Translation between framework options keys and Anthropic Messages API
166166
OPTION_TRANSLATIONS: dict[str, str] = {

python/packages/azure-ai/agent_framework_azure_ai/_chat_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class AzureAIAgentOptions(ChatOptions, total=False):
199199
"TAzureAIAgentOptions",
200200
bound=TypedDict, # type: ignore[valid-type]
201201
default="AzureAIAgentOptions",
202-
contravariant=True,
202+
covariant=True,
203203
)
204204

205205

@@ -262,14 +262,14 @@ def __init__(
262262
263263
# Using environment variables
264264
# Set AZURE_AI_PROJECT_ENDPOINT=https://your-project.cognitiveservices.azure.com
265-
# Set AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4
265+
# Set AZURE_AI_MODEL_DEPLOYMENT_NAME=<model name>
266266
credential = DefaultAzureCredential()
267267
client = AzureAIAgentClient(credential=credential)
268268
269269
# Or passing parameters directly
270270
client = AzureAIAgentClient(
271271
project_endpoint="https://your-project.cognitiveservices.azure.com",
272-
model_deployment_name="gpt-4",
272+
model_deployment_name="<model name>",
273273
credential=credential,
274274
)
275275

python/packages/azure-ai/agent_framework_azure_ai/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"TAzureAIClientOptions",
5555
bound=TypedDict, # type: ignore[valid-type]
5656
default="OpenAIResponsesOptions",
57-
contravariant=True,
57+
covariant=True,
5858
)
5959

6060

python/packages/bedrock/agent_framework_bedrock/_chat_client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class BedrockChatOptions(ChatOptions, total=False):
9696
9797
Keys:
9898
# Inherited from ChatOptions (mapped to Bedrock):
99-
model_id: The Bedrock model identifier (e.g., 'anthropic.claude-3-sonnet-20240229-v1:0'),
99+
model_id: The Bedrock model identifier,
100100
translates to ``modelId`` in Bedrock API.
101101
temperature: Sampling temperature,
102102
translates to ``inferenceConfig.temperature``.
@@ -177,7 +177,7 @@ class BedrockChatOptions(ChatOptions, total=False):
177177
}
178178
"""Maps ChatOptions keys to Bedrock Converse API parameter names."""
179179

180-
TBedrockChatOptions = TypeVar("TBedrockChatOptions", bound=TypedDict, default="BedrockChatOptions", contravariant=True) # type: ignore[valid-type]
180+
TBedrockChatOptions = TypeVar("TBedrockChatOptions", bound=TypedDict, default="BedrockChatOptions", covariant=True) # type: ignore[valid-type]
181181

182182

183183
# endregion
@@ -254,7 +254,7 @@ def __init__(
254254
from agent_framework.bedrock import BedrockChatClient
255255
256256
# Basic usage with default credentials
257-
client = BedrockChatClient(model_id="anthropic.claude-3-sonnet-20240229-v1:0")
257+
client = BedrockChatClient(model_id="<model name>")
258258
259259
# Using custom ChatOptions with type safety:
260260
from typing import TypedDict
@@ -265,9 +265,7 @@ class MyOptions(BedrockChatOptions, total=False):
265265
my_custom_option: str
266266
267267
268-
client: BedrockChatClient[MyOptions] = BedrockChatClient(
269-
model_id="anthropic.claude-3-sonnet-20240229-v1:0"
270-
)
268+
client = BedrockChatClient[MyOptions](model_id="<model name>")
271269
response = await client.get_response("Hello", options={"my_custom_option": "value"})
272270
"""
273271
try:

python/packages/core/agent_framework/_agents.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
logger = get_logger("agent_framework")
5858

5959
TThreadType = TypeVar("TThreadType", bound="AgentThread")
60-
TOptions = TypeVar("TOptions", bound=TypedDict, default="ChatOptions", contravariant=True) # type: ignore[valid-type]
60+
TOptions = TypeVar("TOptions", bound=TypedDict, default="ChatOptions", covariant=True) # type: ignore[valid-type]
6161

6262

6363
def _merge_options(base: dict[str, Any], override: dict[str, Any]) -> dict[str, Any]:
@@ -673,6 +673,7 @@ def __init__(
673673
provider-specific options including temperature, max_tokens, model_id,
674674
tool_choice, and provider-specific options like reasoning_effort.
675675
You can also create your own TypedDict for custom chat clients.
676+
These can be overridden at runtime via the ``options`` parameter of ``run()`` and ``run_stream()``.
676677
tools: The tools to use for the request.
677678
kwargs: Any additional keyword arguments. Will be stored as ``additional_properties``.
678679

python/packages/core/agent_framework/_clients.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
TInput = TypeVar("TInput", contravariant=True)
4040
TEmbedding = TypeVar("TEmbedding")
4141
TBaseChatClient = TypeVar("TBaseChatClient", bound="BaseChatClient")
42-
TOptions = TypeVar("TOptions", bound=TypedDict, default="ChatOptions", contravariant=True) # type: ignore[valid-type]
42+
TOptions = TypeVar("TOptions", bound=TypedDict, default="ChatOptions", covariant=True) # type: ignore[valid-type]
4343

4444
logger = get_logger()
4545

0 commit comments

Comments
 (0)