Skip to content

Commit 62e02da

Browse files
eavanvalkenburgCopilotCopilot
authored
Python: update FoundryAgent for hosted agent sessions (#5447)
* fixes to FoundryAgent to connect to new hosted agents Co-authored-by: Copilot <[email protected]> * fix mypy Co-authored-by: Copilot <[email protected]> * Python: remove Foundry service session helpers Remove the public hosted-agent service session CRUD helpers from FoundryAgent and drop the related feature-stage inventory entry. Update the hosted-agent sample to create and delete service sessions directly through the preview AIProjectClient APIs, and tighten a few test harnesses surfaced by full workspace validation. Co-authored-by: Copilot <[email protected]> * fix from merge * fix hosted env detection Co-authored-by: Copilot <[email protected]> * reverted sample update * fix tests and code Co-authored-by: Copilot <[email protected]> * remove aenter * skipping some tests Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 63c0a51 commit 62e02da

15 files changed

Lines changed: 602 additions & 181 deletions

File tree

‎python/packages/core/agent_framework/_telemetry.py‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import contextlib
56
import logging
67
import os
78
from typing import Any, Final
@@ -60,13 +61,12 @@ def _detect_hosted_environment() -> None:
6061
global _hosted_env_detected
6162
if _hosted_env_detected:
6263
return
63-
_hosted_env_detected = True
6464

65-
env_value = os.environ.get(_FOUNDRY_HOSTING_ENV_VAR)
66-
if env_value is not None:
65+
if (env_value := os.environ.get(_FOUNDRY_HOSTING_ENV_VAR)) is not None:
6766
# Env var exists — trust its value and skip the fallback.
6867
if env_value:
6968
_add_user_agent_prefix(_HOSTED_USER_AGENT_PREFIX)
69+
_hosted_env_detected = True
7070
return
7171

7272
# Env var not set — fall back to AgentConfig as a second layer of defense.
@@ -78,13 +78,12 @@ def _detect_hosted_environment() -> None:
7878
return
7979
except (ModuleNotFoundError, ValueError):
8080
return
81-
try:
81+
with contextlib.suppress(ImportError, AttributeError):
8282
from azure.ai.agentserver.core import AgentConfig # pyright: ignore[reportMissingImports]
8383

8484
if AgentConfig.from_env().is_hosted:
8585
_add_user_agent_prefix(_HOSTED_USER_AGENT_PREFIX)
86-
except (ImportError, AttributeError):
87-
pass
86+
_hosted_env_detected = True
8887

8988

9089
def get_user_agent() -> str:

‎python/packages/core/agent_framework/foundry/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
_IMPORTS: dict[str, tuple[str, str]] = {
1515
"AnthropicFoundryClient": ("agent_framework_anthropic", "agent-framework-anthropic"),
1616
"FoundryAgent": ("agent_framework_foundry", "agent-framework-foundry"),
17+
"FoundryAgentOptions": ("agent_framework_foundry", "agent-framework-foundry"),
1718
"FoundryChatClient": ("agent_framework_foundry", "agent-framework-foundry"),
1819
"FoundryChatOptions": ("agent_framework_foundry", "agent-framework-foundry"),
1920
"FoundryEmbeddingClient": ("agent_framework_foundry", "agent-framework-foundry"),

‎python/packages/devui/tests/devui/test_ui_memory_regression.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,13 @@ async def test_devui_streaming_renderer_memory_is_bounded(
655655
)
656656

657657
try:
658-
websocket_url = await _get_devtools_websocket_url(debug_port)
658+
try:
659+
websocket_url = await _get_devtools_websocket_url(debug_port)
660+
except RuntimeError as exc:
661+
return_code = browser_process.poll()
662+
if return_code is not None:
663+
pytest.skip(f"Chromium exited before DevTools became available (code {return_code}).")
664+
pytest.skip(str(exc))
659665

660666
async with websocket_connect(websocket_url, max_size=None) as websocket:
661667
client = _CDPClient(websocket)

‎python/packages/foundry/agent_framework_foundry/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import importlib.metadata
44

5-
from ._agent import FoundryAgent, RawFoundryAgent, RawFoundryAgentChatClient
5+
from ._agent import FoundryAgent, FoundryAgentOptions, RawFoundryAgent, RawFoundryAgentChatClient
66
from ._chat_client import FoundryChatClient, FoundryChatOptions, RawFoundryChatClient
77
from ._embedding_client import (
88
FoundryEmbeddingClient,
@@ -25,6 +25,7 @@
2525

2626
__all__ = [
2727
"FoundryAgent",
28+
"FoundryAgentOptions",
2829
"FoundryChatClient",
2930
"FoundryChatOptions",
3031
"FoundryEmbeddingClient",

0 commit comments

Comments
 (0)