Python: [BREAKING] added SerializationMixin and applied to contents, agents, chat client… (#1012)

* added SerializationMixin and applied to contents, agents, chat clients, removed AFBaseModel

* fix annotations type

* mypy fixes

* fix tests

* fix serializable subvalues and added large docstring

* updated indents in code block

* fixed exported urls
This commit is contained in:
Eduard van Valkenburg
2025-09-30 21:53:46 +02:00
committed by GitHub
Unverified
parent 3eb26632ce
commit 54ad135914
84 changed files with 2302 additions and 1957 deletions
-3
View File
@@ -1,3 +0,0 @@
# Copyright (c) Microsoft. All rights reserved.
"""Test utilities for sample testing."""
-43
View File
@@ -1,43 +0,0 @@
# Copyright (c) Microsoft. All rights reserved.
import asyncio
import logging
from collections.abc import Awaitable, Callable
from typing import Any
logger = logging.getLogger(__name__)
async def retry(
func: Callable[[], Awaitable[Any]],
retries: int = 3,
reset: Callable[[], None] | None = None,
name: str | None = None,
) -> None:
"""Retry function with reset capability and proper logging.
Args:
func: The function to retry.
retries: Number of retries.
reset: Function to reset the state of any variables used in the function.
name: Optional name for logging purposes.
"""
func_name = name or func.__module__
logger.info(f"Running {retries} retries with func: {func_name}")
for i in range(retries):
logger.info(f" Try {i + 1} for {func_name}")
try:
if reset:
reset()
await func()
return
except Exception as e:
logger.warning(f" On try {i + 1} got this error: {e}")
if i == retries - 1: # Last retry
raise
# Binary exponential backoff like Semantic Kernel
backoff = 2**i
logger.info(f" Sleeping for {backoff} seconds before retrying")
await asyncio.sleep(backoff)
-3
View File
@@ -1,3 +0,0 @@
# Copyright (c) Microsoft. All rights reserved.
"""Sample tests package."""
@@ -1,3 +0,0 @@
# Copyright (c) Microsoft. All rights reserved.
"""Getting started sample tests."""
@@ -146,7 +146,6 @@ from samples.getting_started.agents.openai.openai_responses_client_with_thread i
from samples.getting_started.agents.openai.openai_responses_client_with_web_search import (
main as openai_responses_client_with_web_search,
)
from tests.sample_utils import retry
# Environment variable for controlling sample tests
RUN_SAMPLES_TESTS = "RUN_SAMPLES_TESTS"
@@ -579,6 +578,7 @@ agent_samples = [
]
@pytest.mark.flaky
@mark.parametrize("sample, responses", agent_samples)
async def test_agent_samples(sample: Callable[..., Awaitable[Any]], responses: list[str], monkeypatch: MonkeyPatch):
"""Test agent samples with input mocking and retry logic."""
@@ -592,4 +592,4 @@ async def test_agent_samples(sample: Callable[..., Awaitable[Any]], responses: l
return responses.pop(0) if responses else "exit"
monkeypatch.setattr("builtins.input", mock_input)
await retry(sample, retries=3, reset=reset)
await sample
@@ -32,7 +32,6 @@ from samples.getting_started.chat_client.openai_chat_client import (
from samples.getting_started.chat_client.openai_responses_client import (
main as openai_responses_client,
)
from tests.sample_utils import retry
# Environment variable for controlling sample tests
RUN_SAMPLES_TESTS = "RUN_SAMPLES_TESTS"
@@ -132,4 +131,4 @@ async def test_chat_client_samples(
return responses.pop(0) if responses else "exit"
monkeypatch.setattr("builtins.input", mock_input)
await retry(sample, retries=3, reset=reset)
await sample
@@ -10,7 +10,6 @@ from pytest import MonkeyPatch, mark, param
from samples.getting_started.threads.custom_chat_message_store_thread import main as threads_custom_store
from samples.getting_started.threads.suspend_resume_thread import main as threads_suspend_resume
from tests.sample_utils import retry
# Environment variable for controlling sample tests
RUN_SAMPLES_TESTS = "RUN_SAMPLES_TESTS"
@@ -51,4 +50,4 @@ async def test_thread_samples(sample: Callable[..., Awaitable[Any]], responses:
return responses.pop(0) if responses else "exit"
monkeypatch.setattr("builtins.input", mock_input)
await retry(sample, retries=3, reset=reset)
await sample