Address comments (#2160)

This commit is contained in:
Laveesh Rohra
2025-11-12 17:44:45 -08:00
committed by GitHub
Unverified
parent 3829e1cabc
commit be56177cc7
3 changed files with 28 additions and 30 deletions
@@ -34,6 +34,9 @@ WAIT_FOR_RESPONSE_HEADER: str = "x-ms-wait-for-response"
EntityHandler = Callable[[df.DurableEntityContext], None]
HandlerT = TypeVar("HandlerT", bound=Callable[..., Any])
DEFAULT_MAX_POLL_RETRIES: int = 30
DEFAULT_POLL_INTERVAL_SECONDS: float = 1.0
if TYPE_CHECKING:
class DFAppBase:
@@ -70,17 +73,16 @@ class AgentFunctionApp(DFAppBase):
.. code-block:: python
from agent_framework.azure import AgentFunctionApp
from agent_framework.azure import AzureOpenAIAssistantsClient
from agent_framework.azure import AgentFunctionApp, AzureOpenAIChatClient
# Create agents with unique names
weather_agent = AzureOpenAIAssistantsClient(...).create_agent(
weather_agent = AzureOpenAIChatClient(...).create_agent(
name="WeatherAgent",
instructions="You are a helpful weather agent.",
tools=[get_weather],
)
math_agent = AzureOpenAIAssistantsClient(...).create_agent(
math_agent = AzureOpenAIChatClient(...).create_agent(
name="MathAgent",
instructions="You are a helpful math assistant.",
tools=[calculate],
@@ -128,23 +130,23 @@ class AgentFunctionApp(DFAppBase):
http_auth_level: func.AuthLevel = func.AuthLevel.FUNCTION,
enable_health_check: bool = True,
enable_http_endpoints: bool = True,
max_poll_retries: int = 30,
poll_interval_seconds: float = 1,
max_poll_retries: int = DEFAULT_MAX_POLL_RETRIES,
poll_interval_seconds: float = DEFAULT_POLL_INTERVAL_SECONDS,
default_callback: AgentResponseCallbackProtocol | None = None,
):
"""Initialize the AgentFunctionApp.
Args:
agents: List of agent instances to register
http_auth_level: HTTP authentication level (default: FUNCTION)
enable_health_check: Enable built-in health check endpoint (default: True)
enable_http_endpoints: Enable HTTP endpoints for agents (default: True)
max_poll_retries: Maximum number of polling attempts when waiting for a response
poll_interval_seconds: Delay (in seconds) between polling attempts
default_callback: Optional callback invoked for agents without specific callbacks
:param agents: List of agent instances to register.
:param http_auth_level: HTTP authentication level (default: ``func.AuthLevel.FUNCTION``).
:param enable_health_check: Enable the built-in health check endpoint (default: ``True``).
:param enable_http_endpoints: Enable HTTP endpoints for agents (default: ``True``).
:param max_poll_retries: Maximum polling attempts when waiting for a response.
Defaults to ``DEFAULT_MAX_POLL_RETRIES``.
:param poll_interval_seconds: Delay in seconds between polling attempts.
Defaults to ``DEFAULT_POLL_INTERVAL_SECONDS``.
:param default_callback: Optional callback invoked for agents without specific callbacks.
Note:
If no agents are provided, they can be added later using add_agent().
:note: If no agents are provided, they can be added later using :meth:`add_agent`.
"""
logger.debug("[AgentFunctionApp] Initializing with Durable Entities...")
@@ -161,14 +163,14 @@ class AgentFunctionApp(DFAppBase):
try:
retries = int(max_poll_retries)
except (TypeError, ValueError):
retries = 10
retries = DEFAULT_MAX_POLL_RETRIES
self.max_poll_retries = max(1, retries)
try:
interval = float(poll_interval_seconds)
except (TypeError, ValueError):
interval = 0.5
self.poll_interval_seconds = interval if interval > 0 else 0.5
interval = DEFAULT_POLL_INTERVAL_SECONDS
self.poll_interval_seconds = interval if interval > 0 else DEFAULT_POLL_INTERVAL_SECONDS
if agents:
# Register all provided agents
@@ -710,7 +712,8 @@ class AgentFunctionApp(DFAppBase):
headers: dict[str, str] = {}
raw_headers = req.headers
if isinstance(raw_headers, Mapping):
for key, value in raw_headers.items():
header_mapping: Mapping[str, Any] = cast(Mapping[str, Any], raw_headers)
for key, value in header_mapping.items():
if value is not None:
headers[str(key).lower()] = str(value)
return headers
@@ -771,13 +774,8 @@ class AgentFunctionApp(DFAppBase):
def _should_wait_for_response(self, req: func.HttpRequest, req_body: dict[str, Any]) -> bool:
"""Determine whether the caller requested to wait for the response."""
header_value = None
raw_headers = req.headers
if isinstance(raw_headers, Mapping):
for key, value in raw_headers.items():
if str(key).lower() == WAIT_FOR_RESPONSE_HEADER:
header_value = value
break
headers: dict[str, str] = self._extract_normalized_headers(req)
header_value: str | None = headers.get(WAIT_FOR_RESPONSE_HEADER)
if header_value is not None:
return self._coerce_to_bool(header_value)
@@ -4,7 +4,7 @@ description = "Azure Functions integration for Microsoft Agent Framework."
authors = [{ name = "Microsoft", email = "af-support@microsoft.com"}]
readme = "README.md"
requires-python = ">=3.10"
version = "1.0.0b251028"
version = "1.0.0b251112"
license-files = ["LICENSE"]
urls.homepage = "https://aka.ms/agent-framework"
urls.source = "https://github.com/microsoft/agent-framework/tree/main/python"
+2 -2
View File
@@ -254,7 +254,7 @@ requires-dist = [
[[package]]
name = "agent-framework-azurefunctions"
version = "1.0.0b251028"
version = "1.0.0b251112"
source = { editable = "packages/azurefunctions" }
dependencies = [
{ name = "agent-framework-core", marker = "sys_platform == 'darwin' or sys_platform == 'linux' or sys_platform == 'win32'" },
@@ -1729,7 +1729,7 @@ name = "exceptiongroup"
version = "1.3.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "typing-extensions", marker = "(python_full_version < '3.13' and sys_platform == 'darwin') or (python_full_version < '3.13' and sys_platform == 'linux') or (python_full_version < '3.13' and sys_platform == 'win32')" },
{ name = "typing-extensions", marker = "(python_full_version < '3.11' and sys_platform == 'darwin') or (python_full_version < '3.11' and sys_platform == 'linux') or (python_full_version < '3.11' and sys_platform == 'win32')" },
]
sdist = { url = "https://files.pythonhosted.org/packages/0b/9f/a65090624ecf468cdca03533906e7c69ed7588582240cfe7cc9e770b50eb/exceptiongroup-1.3.0.tar.gz", hash = "sha256:b241f5885f560bc56a59ee63ca4c6a8bfa46ae4ad651af316d4e81817bb9fd88", size = 29749, upload-time = "2025-05-10T17:42:51.123Z" }
wheels = [