mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] Standardize TypeVar naming convention (TName → NameT) (#3770)
* standardized typevar to use suffix T * addressed copilot comments
This commit is contained in:
@@ -59,17 +59,17 @@ def _unwrap_server_function_call_contents(contents: MutableSequence[Content | di
|
||||
contents[idx] = content.function_call # type: ignore[assignment, union-attr]
|
||||
|
||||
|
||||
TBaseChatClient = TypeVar("TBaseChatClient", bound=type[BaseChatClient[Any]])
|
||||
BaseChatClientT = TypeVar("BaseChatClientT", bound=type[BaseChatClient[Any]])
|
||||
|
||||
TAGUIChatOptions = TypeVar(
|
||||
"TAGUIChatOptions",
|
||||
AGUIChatOptionsT = TypeVar(
|
||||
"AGUIChatOptionsT",
|
||||
bound=TypedDict, # type: ignore[valid-type]
|
||||
default="AGUIChatOptions",
|
||||
covariant=True,
|
||||
)
|
||||
|
||||
|
||||
def _apply_server_function_call_unwrap(chat_client: TBaseChatClient) -> TBaseChatClient:
|
||||
def _apply_server_function_call_unwrap(chat_client: BaseChatClientT) -> BaseChatClientT:
|
||||
"""Class decorator that unwraps server-side function calls after tool handling."""
|
||||
|
||||
original_get_response = chat_client.get_response
|
||||
@@ -111,11 +111,11 @@ def _apply_server_function_call_unwrap(chat_client: TBaseChatClient) -> TBaseCha
|
||||
|
||||
@_apply_server_function_call_unwrap
|
||||
class AGUIChatClient(
|
||||
ChatMiddlewareLayer[TAGUIChatOptions],
|
||||
FunctionInvocationLayer[TAGUIChatOptions],
|
||||
ChatTelemetryLayer[TAGUIChatOptions],
|
||||
BaseChatClient[TAGUIChatOptions],
|
||||
Generic[TAGUIChatOptions],
|
||||
ChatMiddlewareLayer[AGUIChatOptionsT],
|
||||
FunctionInvocationLayer[AGUIChatOptionsT],
|
||||
ChatTelemetryLayer[AGUIChatOptionsT],
|
||||
BaseChatClient[AGUIChatOptionsT],
|
||||
Generic[AGUIChatOptionsT],
|
||||
):
|
||||
"""Chat client for communicating with AG-UI compliant servers.
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ 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)
|
||||
AGUIChatOptionsT = TypeVar("AGUIChatOptionsT", bound=TypedDict, default="AGUIChatOptions", covariant=True) # type: ignore[valid-type]
|
||||
ResponseModelT = TypeVar("ResponseModelT", bound=BaseModel | None, default=None)
|
||||
|
||||
|
||||
class PredictStateConfig(TypedDict):
|
||||
@@ -84,7 +84,7 @@ class AGUIRequest(BaseModel):
|
||||
# region AG-UI Chat Options TypedDict
|
||||
|
||||
|
||||
class AGUIChatOptions(ChatOptions[TResponseModel], Generic[TResponseModel], total=False):
|
||||
class AGUIChatOptions(ChatOptions[ResponseModelT], Generic[ResponseModelT], total=False):
|
||||
"""AG-UI protocol-specific chat options dict.
|
||||
|
||||
Extends base ChatOptions for the AG-UI (Agent-UI) protocol.
|
||||
|
||||
@@ -165,10 +165,10 @@ _UI_GENERATOR_INSTRUCTIONS = """You MUST use the provided tools to generate cont
|
||||
For other requests, use the appropriate tool (create_chart, display_timeline, show_comparison_table).
|
||||
"""
|
||||
|
||||
TOptions = TypeVar("TOptions", bound=TypedDict, default="ChatOptions") # type: ignore[valid-type]
|
||||
OptionsT = TypeVar("OptionsT", bound=TypedDict, default="ChatOptions") # type: ignore[valid-type]
|
||||
|
||||
|
||||
def ui_generator_agent(chat_client: ChatClientProtocol[TOptions]) -> AgentFrameworkAgent:
|
||||
def ui_generator_agent(chat_client: ChatClientProtocol[OptionsT]) -> AgentFrameworkAgent:
|
||||
"""Create a UI generator agent with custom React component rendering.
|
||||
|
||||
Args:
|
||||
|
||||
@@ -21,7 +21,7 @@ from agent_framework import (
|
||||
Content,
|
||||
SupportsAgentRun,
|
||||
)
|
||||
from agent_framework._clients import TOptions_co
|
||||
from agent_framework._clients import OptionsCoT
|
||||
from agent_framework._middleware import ChatMiddlewareLayer
|
||||
from agent_framework._tools import FunctionInvocationLayer
|
||||
from agent_framework._types import ResponseStream
|
||||
@@ -37,11 +37,11 @@ ResponseFn = Callable[..., Awaitable[ChatResponse]]
|
||||
|
||||
|
||||
class StreamingChatClientStub(
|
||||
ChatMiddlewareLayer[TOptions_co],
|
||||
FunctionInvocationLayer[TOptions_co],
|
||||
ChatTelemetryLayer[TOptions_co],
|
||||
BaseChatClient[TOptions_co],
|
||||
Generic[TOptions_co],
|
||||
ChatMiddlewareLayer[OptionsCoT],
|
||||
FunctionInvocationLayer[OptionsCoT],
|
||||
ChatTelemetryLayer[OptionsCoT],
|
||||
BaseChatClient[OptionsCoT],
|
||||
Generic[OptionsCoT],
|
||||
):
|
||||
"""Typed streaming stub that satisfies ChatClientProtocol."""
|
||||
|
||||
@@ -68,7 +68,7 @@ class StreamingChatClientStub(
|
||||
messages: str | ChatMessage | Sequence[str | ChatMessage],
|
||||
*,
|
||||
stream: Literal[False] = ...,
|
||||
options: TOptions_co | ChatOptions[None] | None = ...,
|
||||
options: OptionsCoT | ChatOptions[None] | None = ...,
|
||||
**kwargs: Any,
|
||||
) -> Awaitable[ChatResponse[Any]]: ...
|
||||
|
||||
@@ -78,7 +78,7 @@ class StreamingChatClientStub(
|
||||
messages: str | ChatMessage | Sequence[str | ChatMessage],
|
||||
*,
|
||||
stream: Literal[True],
|
||||
options: TOptions_co | ChatOptions[Any] | None = ...,
|
||||
options: OptionsCoT | ChatOptions[Any] | None = ...,
|
||||
**kwargs: Any,
|
||||
) -> ResponseStream[ChatResponseUpdate, ChatResponse[Any]]: ...
|
||||
|
||||
@@ -87,7 +87,7 @@ class StreamingChatClientStub(
|
||||
messages: str | ChatMessage | Sequence[str | ChatMessage],
|
||||
*,
|
||||
stream: bool = False,
|
||||
options: TOptions_co | ChatOptions[Any] | None = None,
|
||||
options: OptionsCoT | ChatOptions[Any] | None = None,
|
||||
**kwargs: Any,
|
||||
) -> Awaitable[ChatResponse[Any]] | ResponseStream[ChatResponseUpdate, ChatResponse[Any]]:
|
||||
self.last_thread = kwargs.get("thread")
|
||||
|
||||
Reference in New Issue
Block a user