Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions python/packages/ag-ui/agent_framework_ag_ui/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,21 @@
from ._message_adapters import agent_framework_messages_to_agui
from ._utils import convert_tools_to_agui_format

if TYPE_CHECKING:
from ._types import AGUIChatOptions

from typing import TypedDict

if sys.version_info >= (3, 13):
from typing import TypeVar
from typing import TypeVar # type: ignore # pragma: no cover
else:
from typing_extensions import TypeVar

from typing_extensions import TypeVar # type: ignore # pragma: no cover
if sys.version_info >= (3, 12):
from typing import override # type: ignore # pragma: no cover
else:
from typing_extensions import override # type: ignore[import] # pragma: no cover

if sys.version_info >= (3, 11):
from typing import Self # pragma: no cover
from typing import Self, TypedDict # pragma: no cover
else:
from typing_extensions import Self # pragma: no cover
from typing_extensions import Self, TypedDict # pragma: no cover

if TYPE_CHECKING:
from ._types import AGUIChatOptions

logger: logging.Logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -85,7 +81,7 @@ async def streaming_wrapper(self: Any, *args: Any, **kwargs: Any) -> AsyncIterab

@wraps(original_get_response)
async def response_wrapper(self: Any, *args: Any, **kwargs: Any) -> ChatResponse:
response = await original_get_response(self, *args, **kwargs)
response: ChatResponse[Any] = await original_get_response(self, *args, **kwargs) # type: ignore[var-annotated]
if response.messages:
for message in response.messages:
_unwrap_server_function_call_contents(cast(MutableSequence[Content | dict[str, Any]], message.contents))
Expand Down
18 changes: 12 additions & 6 deletions python/packages/ag-ui/agent_framework_ag_ui/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@
"""Type definitions for AG-UI integration."""

import sys
from typing import Any, TypedDict
from typing import Any, Generic

from agent_framework import ChatOptions
from pydantic import BaseModel, Field

if sys.version_info >= (3, 13):
from typing import TypeVar
from typing import TypeVar # type: ignore # pragma: no cover
else:
from typing_extensions import TypeVar
from typing_extensions import TypeVar # type: ignore # pragma: no cover
if sys.version_info >= (3, 11):
from typing import TypedDict # type: ignore # pragma: no cover
else:
from typing_extensions import TypedDict # type: ignore # pragma: no cover


TAGUIChatOptions = TypeVar("TAGUIChatOptions", bound=TypedDict, default="AGUIChatOptions", covariant=True) # type: ignore[valid-type]
TResponseModel = TypeVar("TResponseModel", bound=BaseModel | None, default=None)


class PredictStateConfig(TypedDict):
Expand Down Expand Up @@ -76,7 +84,7 @@ class AGUIRequest(BaseModel):
# region AG-UI Chat Options TypedDict


class AGUIChatOptions(ChatOptions, total=False):
class AGUIChatOptions(ChatOptions[TResponseModel], Generic[TResponseModel], total=False):
"""AG-UI protocol-specific chat options dict.

Extends base ChatOptions for the AG-UI (Agent-UI) protocol.
Expand Down Expand Up @@ -140,7 +148,5 @@ class AGUIChatOptions(ChatOptions, total=False):
AGUI_OPTION_TRANSLATIONS: dict[str, str] = {}
"""Maps ChatOptions keys to AG-UI parameter names (protocol uses standard names)."""

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


# endregion
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from typing import TypeVar # type: ignore # pragma: no cover
else:
from typing_extensions import TypeVar # type: ignore # pragma: no cover
if sys.version_info >= (3, 11):
from typing import TypedDict # type: ignore # pragma: no cover
else:
from typing_extensions import TypedDict # type: ignore # pragma: no cover

if TYPE_CHECKING:
from agent_framework import ChatOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
from collections.abc import AsyncIterable, MutableMapping, MutableSequence, Sequence
from typing import Any, ClassVar, Final, Generic, Literal, TypedDict
from typing import Any, ClassVar, Final, Generic, Literal

from agent_framework import (
AGENT_FRAMEWORK_USER_AGENT,
Expand Down Expand Up @@ -47,15 +47,18 @@
)
from pydantic import BaseModel, SecretStr, ValidationError

if sys.version_info >= (3, 11):
from typing import TypedDict # type: ignore # pragma: no cover
else:
from typing_extensions import TypedDict # type: ignore # pragma: no cover
if sys.version_info >= (3, 13):
from typing import TypeVar
from typing import TypeVar # type: ignore # pragma: no cover
else:
from typing_extensions import TypeVar

from typing_extensions import TypeVar # type: ignore # pragma: no cover
if sys.version_info >= (3, 12):
from typing import override # type: ignore # pragma: no cover
else:
from typing_extensions import override # type: ignore[import] # pragma: no cover
from typing_extensions import override # type: ignore # pragma: no cover

__all__ = [
"AnthropicChatOptions",
Expand All @@ -69,6 +72,8 @@
BETA_FLAGS: Final[list[str]] = ["mcp-client-2025-04-04", "code-execution-2025-08-25"]
STRUCTURED_OUTPUTS_BETA_FLAG: Final[str] = "structured-outputs-2025-11-13"

TResponseModel = TypeVar("TResponseModel", bound=BaseModel | None, default=None)


# region Anthropic Chat Options TypedDict

Expand All @@ -91,7 +96,7 @@ class ThinkingConfig(TypedDict, total=False):
budget_tokens: int


class AnthropicChatOptions(ChatOptions, total=False):
class AnthropicChatOptions(ChatOptions[TResponseModel], Generic[TResponseModel], total=False):
"""Anthropic-specific chat options.

Extends ChatOptions with options specific to Anthropic's Messages API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
from collections.abc import Callable, MutableMapping, Sequence
from typing import TYPE_CHECKING, Any, Generic, TypedDict, cast
from typing import TYPE_CHECKING, Any, Generic, cast

from agent_framework import (
AGENT_FRAMEWORK_USER_AGENT,
Expand All @@ -27,9 +27,13 @@
from ._chat_client import AzureAIAgentOptions

if sys.version_info >= (3, 13):
from typing import Self, TypeVar # pragma: no cover
from typing import Self, TypeVar # type: ignore # pragma: no cover
else:
from typing_extensions import Self, TypeVar # pragma: no cover
from typing_extensions import Self, TypeVar # type: ignore # pragma: no cover
if sys.version_info >= (3, 11):
from typing import TypedDict # type: ignore # pragma: no cover
else:
from typing_extensions import TypedDict # type: ignore # pragma: no cover


# Type variable for options - allows typed ChatAgent[TOptions] returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import sys
from collections.abc import AsyncIterable, Callable, Mapping, MutableMapping, MutableSequence, Sequence
from typing import Any, ClassVar, Generic, TypedDict
from typing import Any, ClassVar, Generic

from agent_framework import (
AGENT_FRAMEWORK_USER_AGENT,
Expand Down Expand Up @@ -96,9 +96,9 @@
else:
from typing_extensions import override # type: ignore[import] # pragma: no cover
if sys.version_info >= (3, 11):
from typing import Self # pragma: no cover
from typing import Self, TypedDict # type: ignore # pragma: no cover
else:
from typing_extensions import Self # pragma: no cover
from typing_extensions import Self, TypedDict # type: ignore # pragma: no cover


logger = get_logger("agent_framework.azure")
Expand Down Expand Up @@ -1265,7 +1265,7 @@ def as_agent(
| MutableMapping[str, Any]
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]]
| None = None,
default_options: TAzureAIAgentOptions | None = None,
default_options: TAzureAIAgentOptions | Mapping[str, Any] | None = None,
chat_message_store_factory: Callable[[], ChatMessageStoreProtocol] | None = None,
context_provider: ContextProvider | None = None,
middleware: Sequence[Middleware] | None = None,
Expand Down
8 changes: 4 additions & 4 deletions python/packages/azure-ai/agent_framework_azure_ai/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
from collections.abc import Callable, Mapping, MutableMapping, MutableSequence, Sequence
from typing import Any, ClassVar, Generic, TypedDict, TypeVar, cast
from typing import Any, ClassVar, Generic, TypeVar, cast

from agent_framework import (
AGENT_FRAMEWORK_USER_AGENT,
Expand Down Expand Up @@ -38,9 +38,9 @@
else:
from typing_extensions import override # type: ignore[import] # pragma: no cover
if sys.version_info >= (3, 11):
from typing import Self # pragma: no cover
from typing import Self, TypedDict # type: ignore # pragma: no cover
else:
from typing_extensions import Self # pragma: no cover
from typing_extensions import Self, TypedDict # type: ignore # pragma: no cover


logger = get_logger("agent_framework.azure")
Expand Down Expand Up @@ -551,7 +551,7 @@ def as_agent(
| MutableMapping[str, Any]
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]]
| None = None,
default_options: TAzureAIClientOptions | None = None,
default_options: TAzureAIClientOptions | Mapping[str, Any] | None = None,
chat_message_store_factory: Callable[[], ChatMessageStoreProtocol] | None = None,
context_provider: ContextProvider | None = None,
middleware: Sequence[Middleware] | None = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
from collections.abc import Callable, MutableMapping, Sequence
from typing import Any, Generic, TypedDict
from typing import Any, Generic

from agent_framework import (
AGENT_FRAMEWORK_USER_AGENT,
Expand Down Expand Up @@ -33,9 +33,13 @@
from ._shared import AzureAISettings, create_text_format_config, from_azure_ai_tools, to_azure_ai_tools

if sys.version_info >= (3, 13):
from typing import Self, TypeVar # pragma: no cover
from typing import TypeVar # type: ignore # pragma: no cover
else:
from typing_extensions import Self, TypeVar # pragma: no cover
from typing_extensions import TypeVar # type: ignore # pragma: no cover
if sys.version_info >= (3, 11):
from typing import Self, TypedDict # type: ignore # pragma: no cover
else:
from typing_extensions import Self, TypedDict # type: ignore # pragma: no cover


logger = get_logger("agent_framework.azure")
Expand Down
19 changes: 12 additions & 7 deletions python/packages/bedrock/agent_framework_bedrock/_chat_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
from collections import deque
from collections.abc import AsyncIterable, MutableMapping, MutableSequence, Sequence
from typing import Any, ClassVar, Generic, Literal, TypedDict
from typing import Any, ClassVar, Generic, Literal
from uuid import uuid4

from agent_framework import (
Expand Down Expand Up @@ -33,17 +33,20 @@
from boto3.session import Session as Boto3Session
from botocore.client import BaseClient
from botocore.config import Config as BotoConfig
from pydantic import SecretStr, ValidationError
from pydantic import BaseModel, SecretStr, ValidationError

if sys.version_info >= (3, 13):
from typing import TypeVar
from typing import TypeVar # type: ignore # pragma: no cover
else:
from typing_extensions import TypeVar

from typing_extensions import TypeVar # type: ignore # pragma: no cover
if sys.version_info >= (3, 12):
from typing import override # type: ignore # pragma: no cover
else:
from typing_extensions import override # type: ignore[import] # pragma: no cover
from typing_extensions import override # type: ignore # pragma: no cover
if sys.version_info >= (3, 11):
from typing import TypedDict # type: ignore # pragma: no cover
else:
from typing_extensions import TypedDict # type: ignore # pragma: no cover

logger = get_logger("agent_framework.bedrock")

Expand All @@ -55,6 +58,8 @@
"BedrockSettings",
]

TResponseModel = TypeVar("TResponseModel", bound=BaseModel | None, default=None)


# region Bedrock Chat Options TypedDict

Expand Down Expand Up @@ -82,7 +87,7 @@ class BedrockGuardrailConfig(TypedDict, total=False):
"""How to process guardrails during streaming (sync blocks, async does not)."""


class BedrockChatOptions(ChatOptions, total=False):
class BedrockChatOptions(ChatOptions[TResponseModel], Generic[TResponseModel], total=False):
"""Amazon Bedrock Converse API-specific chat options dict.

Extends base ChatOptions with Bedrock-specific parameters.
Expand Down
4 changes: 2 additions & 2 deletions python/packages/chatkit/agent_framework_chatkit/_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
)

if sys.version_info >= (3, 11):
from typing import assert_never
from typing import assert_never # type:ignore # pragma: no cover
else:
from typing_extensions import assert_never
from typing_extensions import assert_never # type:ignore # pragma: no cover

logger = logging.getLogger(__name__)

Expand Down
Loading
Loading