-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Mark agentserver experimental APIs #48401
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
Merged
Shiva S (Shivakishore14)
merged 11 commits into
main
from
sshiva/agentserver-experimental-apis
Aug 4, 2026
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a8b70f8
Mark agentserver experimental APIs
Shivakishore14 2d0d658
Move experimental markers to definitions
Shivakishore14 4e73533
Address experimental API review comments
Shivakishore14 49eb179
Fix experimental class API stub generation
Shivakishore14 1b37929
Update agentserver experimental API stubs
Shivakishore14 925e9f2
Fix core API consistency metadata
Shivakishore14 8629a06
Fix responses docs experimental import
Shivakishore14 99422f5
Fix responses experimental fallback tests
Shivakishore14 6ab995b
Fix agentserver core pylint issues
Shivakishore14 0ff7e6e
Merge branch 'main' into sshiva/agentserver-experimental-apis
Shivakishore14 55511c4
Merge branch 'main' into sshiva/agentserver-experimental-apis
Shivakishore14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
sdk/agentserver/azure-ai-agentserver-core/azure/ai/agentserver/core/_experimental.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
| """Experimental API marker for Agent Server public preview features.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import functools | ||
| import inspect | ||
| import logging | ||
| import os | ||
| import sys | ||
| from collections.abc import Callable | ||
| from contextvars import ContextVar | ||
| from typing import TypeVar, overload | ||
|
|
||
| from typing_extensions import ParamSpec, TypeGuard | ||
|
|
||
| DOCSTRING_TEMPLATE = ".. note:: {0} {1}\n\n" | ||
| DOCSTRING_DEFAULT_INDENTATION = 8 | ||
| EXPERIMENTAL_CLASS_MESSAGE = "This is an experimental class," | ||
| EXPERIMENTAL_METHOD_MESSAGE = "This is an experimental method," | ||
| EXPERIMENTAL_LINK_MESSAGE = ( | ||
| "and may change at any time. Please see https://aka.ms/azure-ai-agentserver-experimental " | ||
| "for more information." | ||
| ) | ||
| DISABLE_EXPERIMENTAL_WARNING_ENV_VAR = "AZURE_AI_AGENTSERVER_DISABLE_EXPERIMENTAL_WARNING" | ||
|
|
||
| _warning_cache: set[str] = set() | ||
| _experimental_init_active: ContextVar[bool] = ContextVar("experimental_init_active", default=False) | ||
| module_logger = logging.getLogger(__name__) | ||
|
|
||
| P = ParamSpec("P") | ||
| T = TypeVar("T") | ||
|
|
||
|
|
||
| @overload | ||
| def experimental(wrapped: type[T]) -> type[T]: ... | ||
|
|
||
|
|
||
| @overload | ||
| def experimental(wrapped: Callable[P, T]) -> Callable[P, T]: ... | ||
|
|
||
|
|
||
| def experimental(wrapped: type[T] | Callable[P, T]) -> type[T] | Callable[P, T]: | ||
| """Add an experimental note and runtime warning to a class or function. | ||
|
|
||
| :param wrapped: Class or callable to mark as experimental. | ||
| :type wrapped: type[T] | Callable[P, T] | ||
| :return: The wrapped class or callable. | ||
| :rtype: type[T] | Callable[P, T] | ||
| """ | ||
|
|
||
| def is_class(value: type[T] | Callable[P, T]) -> TypeGuard[type[T]]: | ||
| return inspect.isclass(value) | ||
|
|
||
| if is_class(wrapped): | ||
| return _add_class_docstring(wrapped) | ||
| if inspect.isfunction(wrapped): | ||
| return _add_function_docstring(wrapped) | ||
| return wrapped | ||
|
|
||
|
|
||
| def _add_class_docstring(cls: type[T]) -> type[T]: | ||
| doc_string = DOCSTRING_TEMPLATE.format(EXPERIMENTAL_CLASS_MESSAGE, EXPERIMENTAL_LINK_MESSAGE) | ||
| if cls.__doc__: | ||
| cls.__doc__ = _add_note_to_docstring(cls.__doc__, doc_string) | ||
| else: | ||
| cls.__doc__ = doc_string + ">" | ||
|
|
||
| original_init = cls.__init__ | ||
|
|
||
| @functools.wraps(original_init) | ||
| def wrapped_init(self, *args, **kwargs): # type: ignore[no-untyped-def] | ||
| cache_key = f"class:{cls.__module__}.{cls.__qualname__}" | ||
| message = f"Class {cls.__module__}.{cls.__qualname__}: {EXPERIMENTAL_CLASS_MESSAGE} {EXPERIMENTAL_LINK_MESSAGE}" | ||
| active = _experimental_init_active.get() | ||
| if not active and not _should_skip_warning() and not _is_warning_cached(cache_key): | ||
| module_logger.warning(message) | ||
| if active: | ||
| return original_init(self, *args, **kwargs) | ||
| token = _experimental_init_active.set(True) | ||
| try: | ||
| return original_init(self, *args, **kwargs) | ||
| finally: | ||
| _experimental_init_active.reset(token) | ||
|
|
||
| cls.__init__ = wrapped_init # type: ignore[method-assign] | ||
| return cls | ||
|
|
||
|
|
||
| def _add_function_docstring(func: Callable[P, T]) -> Callable[P, T]: | ||
| doc_string = DOCSTRING_TEMPLATE.format(EXPERIMENTAL_METHOD_MESSAGE, EXPERIMENTAL_LINK_MESSAGE) | ||
| if func.__doc__: | ||
| func.__doc__ = _add_note_to_docstring(func.__doc__, doc_string) | ||
| else: | ||
| func.__doc__ = doc_string + ">" | ||
|
|
||
| @functools.wraps(func) | ||
| def wrapped(*args: P.args, **kwargs: P.kwargs) -> T: | ||
| cache_key = f"function:{func.__module__}.{func.__qualname__}" | ||
| message = f"Method {func.__module__}.{func.__qualname__}: {EXPERIMENTAL_METHOD_MESSAGE} {EXPERIMENTAL_LINK_MESSAGE}" | ||
| if not _should_skip_warning() and not _is_warning_cached(cache_key): | ||
| module_logger.warning(message) | ||
| return func(*args, **kwargs) | ||
|
|
||
| return wrapped | ||
|
|
||
|
|
||
| def _add_note_to_docstring(doc_string: str, note: str) -> str: | ||
| indent = _get_indentation_size(doc_string) | ||
| doc_string = doc_string.rjust(len(doc_string) + indent) | ||
| return note + doc_string | ||
|
|
||
|
|
||
| def _get_indentation_size(doc_string: str) -> int: | ||
| lines = doc_string.expandtabs().splitlines() | ||
| indent = sys.maxsize | ||
| for line in lines[1:]: | ||
| stripped = line.lstrip() | ||
| if stripped: | ||
| indent = min(indent, len(line) - len(stripped)) | ||
| return indent if indent < sys.maxsize else DOCSTRING_DEFAULT_INDENTATION | ||
|
|
||
|
|
||
| def _should_skip_warning() -> bool: | ||
| return os.getenv(DISABLE_EXPERIMENTAL_WARNING_ENV_VAR, "false").lower() == "true" | ||
|
|
||
|
|
||
| def _is_warning_cached(cache_key: str) -> bool: | ||
| if cache_key in _warning_cache: | ||
| return True | ||
| _warning_cache.add(cache_key) | ||
| return False | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.