agent-framework-foundry 1.12.0__tar.gz → 1.13.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/PKG-INFO +39 -5
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/README.md +35 -1
- agent_framework_foundry-1.13.1/agent_framework_foundry/__init__.py +90 -0
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/agent_framework_foundry/_agent.py +9 -3
- agent_framework_foundry-1.13.1/agent_framework_foundry/_constants.py +10 -0
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/agent_framework_foundry/_embedding_client.py +6 -5
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/agent_framework_foundry/_feature_usage.py +7 -3
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/agent_framework_foundry/_foundry_evals.py +79 -8
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/agent_framework_foundry/_memory_provider.py +4 -2
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/agent_framework_foundry/_to_prompt_agent.py +4 -2
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/pyproject.toml +5 -5
- agent_framework_foundry-1.12.0/agent_framework_foundry/__init__.py +0 -53
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/LICENSE +0 -0
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/agent_framework_foundry/_chat_client.py +0 -0
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/agent_framework_foundry/_oauth_helpers.py +0 -0
- {agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/agent_framework_foundry/_tools.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: agent-framework-foundry
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.13.1
|
|
4
4
|
Summary: Microsoft Foundry integrations for Microsoft Agent Framework.
|
|
5
5
|
Author-email: Microsoft <af-support@microsoft.com>
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -16,11 +16,11 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.14
|
|
17
17
|
Classifier: Typing :: Typed
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: agent-framework-core>=1.
|
|
20
|
-
Requires-Dist: agent-framework-openai>=1.
|
|
19
|
+
Requires-Dist: agent-framework-core>=1.19.0,<2
|
|
20
|
+
Requires-Dist: agent-framework-openai>=1.14.2,<2
|
|
21
21
|
Requires-Dist: aiohttp>=3.9,<4
|
|
22
22
|
Requires-Dist: azure-ai-inference>=1.0.0b9,<1.0.0b10
|
|
23
|
-
Requires-Dist: azure-ai-projects>=2.2.0,<2.
|
|
23
|
+
Requires-Dist: azure-ai-projects>=2.2.0,<2.7.0
|
|
24
24
|
Requires-Dist: httpx>=0.28,<1
|
|
25
25
|
Project-URL: homepage, https://aka.ms/agent-framework
|
|
26
26
|
Project-URL: issues, https://github.com/microsoft/agent-framework/issues
|
|
@@ -31,6 +31,38 @@ Project-URL: source, https://github.com/microsoft/agent-framework/tree/main/pyth
|
|
|
31
31
|
|
|
32
32
|
This package contains the Microsoft Foundry integrations for Microsoft Agent Framework, including Foundry chat clients, preconfigured Foundry agents, Foundry embedding clients, and Foundry memory providers.
|
|
33
33
|
|
|
34
|
+
## SDK compatibility
|
|
35
|
+
|
|
36
|
+
This package supports `azure-ai-projects>=2.2.0,<2.7.0`. Projects 2.5 and later require
|
|
37
|
+
`openai>=3.0.0`, so `agent-framework-foundry` requires `agent-framework-openai>=1.14.2`,
|
|
38
|
+
which supports both OpenAI 2.x and 3.x.
|
|
39
|
+
|
|
40
|
+
## Evaluations
|
|
41
|
+
|
|
42
|
+
`FoundryEvals` implements the provider-neutral `Evaluator` protocol with
|
|
43
|
+
Microsoft Foundry's built-in and generated evaluators. Core owns `EvalItem`,
|
|
44
|
+
local evaluation, and the `evaluate_agent()` / `evaluate_workflow()`
|
|
45
|
+
orchestration functions; this package owns the Foundry Evals data mappings,
|
|
46
|
+
wire serialization, submission, polling, and result parsing.
|
|
47
|
+
|
|
48
|
+
Use `evaluate_agent()` for the common run-and-evaluate path:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from agent_framework import evaluate_agent
|
|
52
|
+
from agent_framework.foundry import FoundryEvals
|
|
53
|
+
|
|
54
|
+
results = await evaluate_agent(
|
|
55
|
+
agent=agent,
|
|
56
|
+
queries=["What's the weather in Seattle?"],
|
|
57
|
+
evaluators=FoundryEvals(),
|
|
58
|
+
)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
For manual control, construct public `EvalItem` instances and pass them to
|
|
62
|
+
`FoundryEvals.evaluate()`. The Foundry wire format is private to this package.
|
|
63
|
+
`evaluate_traces()` and `evaluate_foundry_target()` provide Foundry-specific
|
|
64
|
+
entry points for existing traces, response IDs, and registered targets.
|
|
65
|
+
|
|
34
66
|
## Concurrent reuse
|
|
35
67
|
|
|
36
68
|
A `FoundryChatClient` instance can be shared by concurrent asynchronous calls on the same event loop. Streaming,
|
|
@@ -52,7 +84,9 @@ Toolboxes can be authored two ways:
|
|
|
52
84
|
- **Foundry portal** — create and version toolboxes through the UI without touching code.
|
|
53
85
|
- **Programmatically** — use the [`azure-ai-projects`](https://pypi.org/project/azure-ai-projects/) SDK to create, update, and version toolboxes from Python.
|
|
54
86
|
|
|
55
|
-
>
|
|
87
|
+
> In `azure-ai-projects` 2.2, toolbox authoring is available through
|
|
88
|
+
> `project_client.beta.toolboxes`. Projects 2.3 and later expose stable
|
|
89
|
+
> `project_client.toolboxes` operations.
|
|
56
90
|
|
|
57
91
|
### Using toolboxes with `FoundryAgent`
|
|
58
92
|
|
|
@@ -2,6 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
This package contains the Microsoft Foundry integrations for Microsoft Agent Framework, including Foundry chat clients, preconfigured Foundry agents, Foundry embedding clients, and Foundry memory providers.
|
|
4
4
|
|
|
5
|
+
## SDK compatibility
|
|
6
|
+
|
|
7
|
+
This package supports `azure-ai-projects>=2.2.0,<2.7.0`. Projects 2.5 and later require
|
|
8
|
+
`openai>=3.0.0`, so `agent-framework-foundry` requires `agent-framework-openai>=1.14.2`,
|
|
9
|
+
which supports both OpenAI 2.x and 3.x.
|
|
10
|
+
|
|
11
|
+
## Evaluations
|
|
12
|
+
|
|
13
|
+
`FoundryEvals` implements the provider-neutral `Evaluator` protocol with
|
|
14
|
+
Microsoft Foundry's built-in and generated evaluators. Core owns `EvalItem`,
|
|
15
|
+
local evaluation, and the `evaluate_agent()` / `evaluate_workflow()`
|
|
16
|
+
orchestration functions; this package owns the Foundry Evals data mappings,
|
|
17
|
+
wire serialization, submission, polling, and result parsing.
|
|
18
|
+
|
|
19
|
+
Use `evaluate_agent()` for the common run-and-evaluate path:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from agent_framework import evaluate_agent
|
|
23
|
+
from agent_framework.foundry import FoundryEvals
|
|
24
|
+
|
|
25
|
+
results = await evaluate_agent(
|
|
26
|
+
agent=agent,
|
|
27
|
+
queries=["What's the weather in Seattle?"],
|
|
28
|
+
evaluators=FoundryEvals(),
|
|
29
|
+
)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
For manual control, construct public `EvalItem` instances and pass them to
|
|
33
|
+
`FoundryEvals.evaluate()`. The Foundry wire format is private to this package.
|
|
34
|
+
`evaluate_traces()` and `evaluate_foundry_target()` provide Foundry-specific
|
|
35
|
+
entry points for existing traces, response IDs, and registered targets.
|
|
36
|
+
|
|
5
37
|
## Concurrent reuse
|
|
6
38
|
|
|
7
39
|
A `FoundryChatClient` instance can be shared by concurrent asynchronous calls on the same event loop. Streaming,
|
|
@@ -23,7 +55,9 @@ Toolboxes can be authored two ways:
|
|
|
23
55
|
- **Foundry portal** — create and version toolboxes through the UI without touching code.
|
|
24
56
|
- **Programmatically** — use the [`azure-ai-projects`](https://pypi.org/project/azure-ai-projects/) SDK to create, update, and version toolboxes from Python.
|
|
25
57
|
|
|
26
|
-
>
|
|
58
|
+
> In `azure-ai-projects` 2.2, toolbox authoring is available through
|
|
59
|
+
> `project_client.beta.toolboxes`. Projects 2.3 and later expose stable
|
|
60
|
+
> `project_client.toolboxes` operations.
|
|
27
61
|
|
|
28
62
|
### Using toolboxes with `FoundryAgent`
|
|
29
63
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
import importlib.metadata
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Final
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from ._agent import (
|
|
8
|
+
FoundryAgent,
|
|
9
|
+
FoundryAgentOptions,
|
|
10
|
+
RawFoundryAgent,
|
|
11
|
+
RawFoundryAgentChatClient,
|
|
12
|
+
)
|
|
13
|
+
from ._chat_client import FoundryChatClient, FoundryChatOptions, RawFoundryChatClient
|
|
14
|
+
from ._constants import FOUNDRY_HOSTED_AGENT_SESSION_ID_KEY
|
|
15
|
+
from ._embedding_client import (
|
|
16
|
+
FoundryEmbeddingClient,
|
|
17
|
+
FoundryEmbeddingOptions,
|
|
18
|
+
FoundryEmbeddingSettings,
|
|
19
|
+
RawFoundryEmbeddingClient,
|
|
20
|
+
)
|
|
21
|
+
from ._foundry_evals import (
|
|
22
|
+
FoundryEvals,
|
|
23
|
+
GeneratedEvaluatorRef,
|
|
24
|
+
evaluate_foundry_target,
|
|
25
|
+
evaluate_traces,
|
|
26
|
+
)
|
|
27
|
+
from ._memory_provider import FoundryMemoryProvider
|
|
28
|
+
from ._to_prompt_agent import to_prompt_agent
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
__version__ = importlib.metadata.version(__name__)
|
|
32
|
+
except importlib.metadata.PackageNotFoundError:
|
|
33
|
+
__version__ = "0.0.0"
|
|
34
|
+
|
|
35
|
+
_LAZY_EXPORTS: Final[dict[str, str]] = {
|
|
36
|
+
"FOUNDRY_HOSTED_AGENT_SESSION_ID_KEY": "._constants",
|
|
37
|
+
"FoundryAgent": "._agent",
|
|
38
|
+
"FoundryAgentOptions": "._agent",
|
|
39
|
+
"FoundryChatClient": "._chat_client",
|
|
40
|
+
"FoundryChatOptions": "._chat_client",
|
|
41
|
+
"FoundryEmbeddingClient": "._embedding_client",
|
|
42
|
+
"FoundryEmbeddingOptions": "._embedding_client",
|
|
43
|
+
"FoundryEmbeddingSettings": "._embedding_client",
|
|
44
|
+
"FoundryEvals": "._foundry_evals",
|
|
45
|
+
"FoundryMemoryProvider": "._memory_provider",
|
|
46
|
+
"GeneratedEvaluatorRef": "._foundry_evals",
|
|
47
|
+
"RawFoundryAgent": "._agent",
|
|
48
|
+
"RawFoundryAgentChatClient": "._agent",
|
|
49
|
+
"RawFoundryChatClient": "._chat_client",
|
|
50
|
+
"RawFoundryEmbeddingClient": "._embedding_client",
|
|
51
|
+
"evaluate_foundry_target": "._foundry_evals",
|
|
52
|
+
"evaluate_traces": "._foundry_evals",
|
|
53
|
+
"to_prompt_agent": "._to_prompt_agent",
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
__all__ = [
|
|
57
|
+
"FOUNDRY_HOSTED_AGENT_SESSION_ID_KEY",
|
|
58
|
+
"FoundryAgent",
|
|
59
|
+
"FoundryAgentOptions",
|
|
60
|
+
"FoundryChatClient",
|
|
61
|
+
"FoundryChatOptions",
|
|
62
|
+
"FoundryEmbeddingClient",
|
|
63
|
+
"FoundryEmbeddingOptions",
|
|
64
|
+
"FoundryEmbeddingSettings",
|
|
65
|
+
"FoundryEvals",
|
|
66
|
+
"FoundryMemoryProvider",
|
|
67
|
+
"GeneratedEvaluatorRef",
|
|
68
|
+
"RawFoundryAgent",
|
|
69
|
+
"RawFoundryAgentChatClient",
|
|
70
|
+
"RawFoundryChatClient",
|
|
71
|
+
"RawFoundryEmbeddingClient",
|
|
72
|
+
"__version__",
|
|
73
|
+
"evaluate_foundry_target",
|
|
74
|
+
"evaluate_traces",
|
|
75
|
+
"to_prompt_agent",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def __getattr__(name: str) -> Any:
|
|
80
|
+
"""Lazily resolve public Foundry exports."""
|
|
81
|
+
if module_name := _LAZY_EXPORTS.get(name):
|
|
82
|
+
value = getattr(importlib.import_module(module_name, __name__), name)
|
|
83
|
+
globals()[name] = value
|
|
84
|
+
return value
|
|
85
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def __dir__() -> list[str]:
|
|
89
|
+
"""Return public names for interactive discovery."""
|
|
90
|
+
return sorted(set(globals()) | set(__all__))
|
{agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/agent_framework_foundry/_agent.py
RENAMED
|
@@ -41,6 +41,7 @@ from azure.core.credentials_async import AsyncTokenCredential
|
|
|
41
41
|
|
|
42
42
|
from agent_framework_foundry._oauth_helpers import try_parse_oauth_consent_event
|
|
43
43
|
|
|
44
|
+
from ._constants import FOUNDRY_HOSTED_AGENT_SESSION_ID_KEY
|
|
44
45
|
from ._feature_usage import (
|
|
45
46
|
FeatureIndex,
|
|
46
47
|
create_feature_usage_policy,
|
|
@@ -94,9 +95,6 @@ class FoundryAgentSettings(TypedDict, total=False):
|
|
|
94
95
|
agent_version: str | None
|
|
95
96
|
|
|
96
97
|
|
|
97
|
-
FOUNDRY_HOSTED_AGENT_SESSION_ID_KEY = "foundry_hosted_agent_session_id"
|
|
98
|
-
|
|
99
|
-
|
|
100
98
|
class FoundryAgentOptions(OpenAIChatOptions, total=False):
|
|
101
99
|
"""Microsoft Foundry agent-specific chat options.
|
|
102
100
|
|
|
@@ -660,6 +658,14 @@ class RawFoundryAgent(
|
|
|
660
658
|
"""
|
|
661
659
|
|
|
662
660
|
service_session_state_keys: ClassVar[frozenset[str]] = frozenset({FOUNDRY_HOSTED_AGENT_SESSION_ID_KEY})
|
|
661
|
+
"""Session-state keys this agent owns, which untrusted input must never supply.
|
|
662
|
+
|
|
663
|
+
Holds the Foundry hosted-agent session ID. Despite the attribute name, that value is not a conversation or
|
|
664
|
+
an ``AgentSession.service_session_id``: it identifies the hosted agent's *runtime session*, a VM-isolated
|
|
665
|
+
sandbox with a persistent filesystem. Hosts such as AG-UI read this to reject client-supplied values, since
|
|
666
|
+
honouring one would run the server's own credentialed call inside another session's sandbox. Hosts are
|
|
667
|
+
expected to reserve this key independently as well, because a wrapper agent may not forward this attribute.
|
|
668
|
+
"""
|
|
663
669
|
|
|
664
670
|
def __init__(
|
|
665
671
|
self,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
FOUNDRY_HOSTED_AGENT_SESSION_ID_KEY = "foundry_hosted_agent_session_id"
|
|
4
|
+
"""``AgentSession.state`` key holding the Foundry hosted-agent session ID.
|
|
5
|
+
|
|
6
|
+
This is the hosted agent's runtime session, a VM-isolated sandbox with a persistent filesystem, sent as
|
|
7
|
+
``extra_body["agent_session_id"]``. It is distinct from ``AgentSession.service_session_id``, which continues the
|
|
8
|
+
model-side response or conversation chain. The value is server-owned; see
|
|
9
|
+
``RawFoundryAgent.service_session_state_keys``.
|
|
10
|
+
"""
|
|
@@ -14,6 +14,7 @@ from agent_framework import (
|
|
|
14
14
|
Embedding,
|
|
15
15
|
EmbeddingGenerationOptions,
|
|
16
16
|
GeneratedEmbeddings,
|
|
17
|
+
SecretString,
|
|
17
18
|
UsageDetails,
|
|
18
19
|
load_settings,
|
|
19
20
|
)
|
|
@@ -83,7 +84,7 @@ class FoundryEmbeddingSettings(TypedDict, total=False):
|
|
|
83
84
|
"""Foundry inference embedding settings."""
|
|
84
85
|
|
|
85
86
|
models_endpoint: str | None
|
|
86
|
-
models_api_key:
|
|
87
|
+
models_api_key: SecretString | None
|
|
87
88
|
embedding_model: str | None
|
|
88
89
|
image_embedding_model: str | None
|
|
89
90
|
|
|
@@ -123,7 +124,7 @@ class RawFoundryEmbeddingClient(
|
|
|
123
124
|
model: str | None = None,
|
|
124
125
|
image_model: str | None = None,
|
|
125
126
|
endpoint: str | None = None,
|
|
126
|
-
api_key: str | None = None,
|
|
127
|
+
api_key: str | SecretString | None = None,
|
|
127
128
|
text_client: EmbeddingsClient | None = None,
|
|
128
129
|
image_client: ImageEmbeddingsClient | None = None,
|
|
129
130
|
credential: AzureKeyCredential | None = None,
|
|
@@ -148,8 +149,8 @@ class RawFoundryEmbeddingClient(
|
|
|
148
149
|
self.image_model: str = settings.get("image_embedding_model") or self.model # type: ignore[assignment]
|
|
149
150
|
resolved_endpoint = settings["models_endpoint"] # type: ignore[reportTypedDictNotRequiredAccess]
|
|
150
151
|
|
|
151
|
-
if credential is None and settings.get("models_api_key"):
|
|
152
|
-
credential = AzureKeyCredential(
|
|
152
|
+
if credential is None and (models_api_key := settings.get("models_api_key")):
|
|
153
|
+
credential = AzureKeyCredential(models_api_key.get_secret_value())
|
|
153
154
|
|
|
154
155
|
if credential is None and text_client is None and image_client is None:
|
|
155
156
|
raise ValueError("Either 'api_key', 'credential', or pre-configured client(s) must be provided.")
|
|
@@ -381,7 +382,7 @@ class FoundryEmbeddingClient(
|
|
|
381
382
|
model: str | None = None,
|
|
382
383
|
image_model: str | None = None,
|
|
383
384
|
endpoint: str | None = None,
|
|
384
|
-
api_key: str | None = None,
|
|
385
|
+
api_key: str | SecretString | None = None,
|
|
385
386
|
text_client: EmbeddingsClient | None = None,
|
|
386
387
|
image_client: ImageEmbeddingsClient | None = None,
|
|
387
388
|
credential: AzureKeyCredential | None = None,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# Copyright (c) Microsoft. All rights reserved.
|
|
2
2
|
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
3
5
|
from enum import IntEnum
|
|
4
|
-
from typing import Any
|
|
6
|
+
from typing import TYPE_CHECKING, Any
|
|
5
7
|
|
|
6
8
|
from agent_framework._telemetry import (
|
|
7
9
|
USER_AGENT_KEY,
|
|
@@ -13,7 +15,9 @@ from agent_framework_openai._feature_usage import (
|
|
|
13
15
|
create_feature_usage_http_client,
|
|
14
16
|
)
|
|
15
17
|
from azure.core.pipeline.policies import SansIOHTTPPolicy
|
|
16
|
-
|
|
18
|
+
|
|
19
|
+
if TYPE_CHECKING:
|
|
20
|
+
from openai import DefaultAsyncHttpxClient
|
|
17
21
|
|
|
18
22
|
|
|
19
23
|
class FeatureIndex(IntEnum):
|
|
@@ -37,7 +41,7 @@ def create_foundry_feature_usage_http_client() -> DefaultAsyncHttpxClient:
|
|
|
37
41
|
return create_feature_usage_http_client(approved_origin_suffixes=_FOUNDRY_ORIGIN_SUFFIXES)
|
|
38
42
|
|
|
39
43
|
|
|
40
|
-
def create_feature_usage_policy() ->
|
|
44
|
+
def create_feature_usage_policy() -> FeatureUsagePolicy:
|
|
41
45
|
"""Create the destination-aware policy that stamps each actual request hop."""
|
|
42
46
|
return FeatureUsagePolicy()
|
|
43
47
|
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
"""Microsoft Foundry Evals integration for Microsoft Agent Framework.
|
|
4
4
|
|
|
5
5
|
Provides ``FoundryEvals``, an ``Evaluator`` implementation backed by Azure AI
|
|
6
|
-
Foundry's built-in evaluators.
|
|
7
|
-
for the design rationale.
|
|
6
|
+
Foundry's built-in evaluators.
|
|
8
7
|
|
|
9
8
|
Example:
|
|
10
9
|
|
|
@@ -27,13 +26,14 @@ Example:
|
|
|
27
26
|
from __future__ import annotations
|
|
28
27
|
|
|
29
28
|
import asyncio
|
|
29
|
+
import contextlib
|
|
30
|
+
import json
|
|
30
31
|
import logging
|
|
31
32
|
from collections.abc import Iterable, Sequence
|
|
32
33
|
from dataclasses import dataclass
|
|
33
34
|
from typing import TYPE_CHECKING, Any, cast
|
|
34
35
|
|
|
35
36
|
from agent_framework._evaluation import (
|
|
36
|
-
AgentEvalConverter,
|
|
37
37
|
ConversationSplit,
|
|
38
38
|
ConversationSplitter,
|
|
39
39
|
EvalItem,
|
|
@@ -44,15 +44,17 @@ from agent_framework._evaluation import (
|
|
|
44
44
|
)
|
|
45
45
|
from agent_framework._feature_stage import ExperimentalFeature, experimental
|
|
46
46
|
from agent_framework._telemetry import mark_feature_used
|
|
47
|
-
from
|
|
47
|
+
from agent_framework._types import Message
|
|
48
48
|
|
|
49
|
-
from ._chat_client import FoundryChatClient
|
|
50
49
|
from ._feature_usage import FeatureIndex
|
|
51
50
|
|
|
52
51
|
if TYPE_CHECKING:
|
|
53
52
|
from azure.ai.projects.aio import AIProjectClient
|
|
53
|
+
from openai import AsyncOpenAI
|
|
54
54
|
from openai.types.evals import RunRetrieveResponse
|
|
55
55
|
|
|
56
|
+
from ._chat_client import FoundryChatClient
|
|
57
|
+
|
|
56
58
|
logger = logging.getLogger(__name__)
|
|
57
59
|
|
|
58
60
|
|
|
@@ -217,6 +219,69 @@ def _resolve_evaluator(name: str) -> str:
|
|
|
217
219
|
# ---------------------------------------------------------------------------
|
|
218
220
|
|
|
219
221
|
|
|
222
|
+
def _convert_message(message: Message) -> list[dict[str, Any]]:
|
|
223
|
+
"""Convert one Agent Framework message to the Foundry Evals wire format."""
|
|
224
|
+
content_items: list[dict[str, Any]] = []
|
|
225
|
+
tool_results: list[dict[str, Any]] = []
|
|
226
|
+
|
|
227
|
+
for content in message.contents or []:
|
|
228
|
+
if content.type == "text" and content.text:
|
|
229
|
+
content_items.append({"type": "text", "text": content.text})
|
|
230
|
+
elif content.type in ("data", "uri") and content.uri:
|
|
231
|
+
image: dict[str, Any] = {
|
|
232
|
+
"type": "input_image",
|
|
233
|
+
"image_url": content.uri,
|
|
234
|
+
}
|
|
235
|
+
if content.media_type:
|
|
236
|
+
image["detail"] = "auto"
|
|
237
|
+
content_items.append(image)
|
|
238
|
+
elif content.type == "function_call":
|
|
239
|
+
arguments = content.arguments
|
|
240
|
+
if isinstance(arguments, str):
|
|
241
|
+
try:
|
|
242
|
+
arguments = json.loads(arguments)
|
|
243
|
+
except (json.JSONDecodeError, TypeError):
|
|
244
|
+
arguments = {"_raw_arguments": "[unparseable]"}
|
|
245
|
+
content_items.append({
|
|
246
|
+
"type": "tool_call",
|
|
247
|
+
"tool_call_id": content.call_id or "",
|
|
248
|
+
"name": content.name or "",
|
|
249
|
+
"arguments": arguments if arguments is not None else {},
|
|
250
|
+
})
|
|
251
|
+
elif content.type == "function_result":
|
|
252
|
+
result = content.result
|
|
253
|
+
if isinstance(result, str):
|
|
254
|
+
with contextlib.suppress(json.JSONDecodeError, TypeError):
|
|
255
|
+
result = json.loads(result)
|
|
256
|
+
tool_results.append({
|
|
257
|
+
"call_id": content.call_id or "",
|
|
258
|
+
"result": result,
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
if tool_results:
|
|
262
|
+
return [
|
|
263
|
+
{
|
|
264
|
+
"role": "tool",
|
|
265
|
+
"tool_call_id": tool_result["call_id"],
|
|
266
|
+
"content": [{"type": "tool_result", "tool_result": tool_result["result"]}],
|
|
267
|
+
}
|
|
268
|
+
for tool_result in tool_results
|
|
269
|
+
]
|
|
270
|
+
if content_items:
|
|
271
|
+
return [{"role": message.role, "content": content_items}]
|
|
272
|
+
return [
|
|
273
|
+
{
|
|
274
|
+
"role": message.role,
|
|
275
|
+
"content": [{"type": "text", "text": ""}],
|
|
276
|
+
}
|
|
277
|
+
]
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _convert_messages(messages: Sequence[Message]) -> list[dict[str, Any]]:
|
|
281
|
+
"""Convert Agent Framework messages to the Foundry Evals wire format."""
|
|
282
|
+
return [converted for message in messages for converted in _convert_message(message)]
|
|
283
|
+
|
|
284
|
+
|
|
220
285
|
def _build_testing_criteria(
|
|
221
286
|
evaluators: Sequence[str | GeneratedEvaluatorRef],
|
|
222
287
|
model: str,
|
|
@@ -662,6 +727,10 @@ def _resolve_openai_client(
|
|
|
662
727
|
project_client: AIProjectClient | None = None,
|
|
663
728
|
) -> AsyncOpenAI:
|
|
664
729
|
"""Resolve an AsyncOpenAI client from a FoundryChatClient, raw client, or project_client."""
|
|
730
|
+
from openai import AsyncOpenAI
|
|
731
|
+
|
|
732
|
+
from ._chat_client import FoundryChatClient
|
|
733
|
+
|
|
665
734
|
if client is not None:
|
|
666
735
|
if isinstance(client, FoundryChatClient):
|
|
667
736
|
return client.client
|
|
@@ -853,6 +922,8 @@ class FoundryEvals:
|
|
|
853
922
|
|
|
854
923
|
# Auto-create a FoundryChatClient from env vars when no client is provided
|
|
855
924
|
if client is None and project_client is None:
|
|
925
|
+
from ._chat_client import FoundryChatClient
|
|
926
|
+
|
|
856
927
|
client = FoundryChatClient(model=model or "gpt-4o")
|
|
857
928
|
|
|
858
929
|
self._client = _resolve_openai_client(client, project_client)
|
|
@@ -882,7 +953,7 @@ class FoundryEvals:
|
|
|
882
953
|
evaluators and filters tool evaluators for items without tool definitions.
|
|
883
954
|
|
|
884
955
|
Args:
|
|
885
|
-
items:
|
|
956
|
+
items: Provider-neutral evaluation data items.
|
|
886
957
|
eval_name: Display name for the evaluation run.
|
|
887
958
|
|
|
888
959
|
Returns:
|
|
@@ -919,8 +990,8 @@ class FoundryEvals:
|
|
|
919
990
|
d: dict[str, Any] = {
|
|
920
991
|
"query": query_text,
|
|
921
992
|
"response": response_text,
|
|
922
|
-
"query_messages":
|
|
923
|
-
"response_messages":
|
|
993
|
+
"query_messages": _convert_messages(query_msgs),
|
|
994
|
+
"response_messages": _convert_messages(response_msgs),
|
|
924
995
|
}
|
|
925
996
|
if item.tools:
|
|
926
997
|
d["tool_definitions"] = [
|
|
@@ -21,10 +21,8 @@ from agent_framework import (
|
|
|
21
21
|
load_settings,
|
|
22
22
|
)
|
|
23
23
|
from agent_framework._telemetry import IS_TELEMETRY_ENABLED, get_user_agent, mark_feature_used
|
|
24
|
-
from azure.ai.projects.aio import AIProjectClient
|
|
25
24
|
from azure.core.credentials import TokenCredential
|
|
26
25
|
from azure.core.credentials_async import AsyncTokenCredential
|
|
27
|
-
from openai.types.responses import ResponseInputItemParam
|
|
28
26
|
|
|
29
27
|
from ._feature_usage import FeatureIndex, create_feature_usage_policy
|
|
30
28
|
|
|
@@ -35,6 +33,8 @@ else:
|
|
|
35
33
|
|
|
36
34
|
if TYPE_CHECKING:
|
|
37
35
|
from agent_framework import SupportsAgentRun
|
|
36
|
+
from azure.ai.projects.aio import AIProjectClient
|
|
37
|
+
from openai.types.responses import ResponseInputItemParam
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
logger = logging.getLogger(__name__)
|
|
@@ -110,6 +110,8 @@ class FoundryMemoryProvider(ContextProvider):
|
|
|
110
110
|
)
|
|
111
111
|
|
|
112
112
|
if project_client is None:
|
|
113
|
+
from azure.ai.projects.aio import AIProjectClient
|
|
114
|
+
|
|
113
115
|
resolved_endpoint = foundry_settings.get("project_endpoint")
|
|
114
116
|
if not resolved_endpoint:
|
|
115
117
|
raise ValueError(
|
|
@@ -34,8 +34,6 @@ from agent_framework import FunctionTool
|
|
|
34
34
|
from agent_framework._feature_stage import ExperimentalFeature, experimental
|
|
35
35
|
from agent_framework._mcp import MCPTool
|
|
36
36
|
|
|
37
|
-
from ._chat_client import RawFoundryChatClient
|
|
38
|
-
|
|
39
37
|
if TYPE_CHECKING:
|
|
40
38
|
from agent_framework import Agent
|
|
41
39
|
from azure.ai.projects.models import (
|
|
@@ -45,6 +43,8 @@ if TYPE_CHECKING:
|
|
|
45
43
|
Tool,
|
|
46
44
|
)
|
|
47
45
|
|
|
46
|
+
from ._chat_client import RawFoundryChatClient
|
|
47
|
+
|
|
48
48
|
|
|
49
49
|
@experimental(feature_id=ExperimentalFeature.TO_PROMPT_AGENT)
|
|
50
50
|
def to_prompt_agent(
|
|
@@ -81,6 +81,8 @@ def to_prompt_agent(
|
|
|
81
81
|
tools, and generation parameters. Pass it to
|
|
82
82
|
``AIProjectClient.agents.create_version(...)`` to publish.
|
|
83
83
|
"""
|
|
84
|
+
from ._chat_client import RawFoundryChatClient
|
|
85
|
+
|
|
84
86
|
if not isinstance(agent.client, RawFoundryChatClient):
|
|
85
87
|
raise TypeError(
|
|
86
88
|
"Creating a Foundry Prompt Agent requires an Agent whose client is a FoundryChatClient; "
|
|
@@ -4,7 +4,7 @@ description = "Microsoft Foundry integrations for Microsoft Agent Framework."
|
|
|
4
4
|
authors = [{ name = "Microsoft", email = "af-support@microsoft.com"}]
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.13.1"
|
|
8
8
|
license-files = ["LICENSE"]
|
|
9
9
|
urls.homepage = "https://aka.ms/agent-framework"
|
|
10
10
|
urls.source = "https://github.com/microsoft/agent-framework/tree/main/python"
|
|
@@ -23,16 +23,16 @@ classifiers = [
|
|
|
23
23
|
"Typing :: Typed",
|
|
24
24
|
]
|
|
25
25
|
dependencies = [
|
|
26
|
-
"agent-framework-core>=1.
|
|
27
|
-
"agent-framework-openai>=1.
|
|
26
|
+
"agent-framework-core>=1.19.0,<2",
|
|
27
|
+
"agent-framework-openai>=1.14.2,<2",
|
|
28
28
|
"aiohttp>=3.9,<4",
|
|
29
29
|
"azure-ai-inference>=1.0.0b9,<1.0.0b10",
|
|
30
|
-
"azure-ai-projects>=2.2.0,<2.
|
|
30
|
+
"azure-ai-projects>=2.2.0,<2.7.0",
|
|
31
31
|
"httpx>=0.28,<1",
|
|
32
32
|
]
|
|
33
33
|
|
|
34
34
|
[tool.uv]
|
|
35
|
-
prerelease = "if-necessary
|
|
35
|
+
prerelease = "if-necessary"
|
|
36
36
|
environments = [
|
|
37
37
|
"sys_platform == 'darwin'",
|
|
38
38
|
"sys_platform == 'linux'",
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
-
|
|
3
|
-
import importlib.metadata
|
|
4
|
-
|
|
5
|
-
from ._agent import (
|
|
6
|
-
FOUNDRY_HOSTED_AGENT_SESSION_ID_KEY,
|
|
7
|
-
FoundryAgent,
|
|
8
|
-
FoundryAgentOptions,
|
|
9
|
-
RawFoundryAgent,
|
|
10
|
-
RawFoundryAgentChatClient,
|
|
11
|
-
)
|
|
12
|
-
from ._chat_client import FoundryChatClient, FoundryChatOptions, RawFoundryChatClient
|
|
13
|
-
from ._embedding_client import (
|
|
14
|
-
FoundryEmbeddingClient,
|
|
15
|
-
FoundryEmbeddingOptions,
|
|
16
|
-
FoundryEmbeddingSettings,
|
|
17
|
-
RawFoundryEmbeddingClient,
|
|
18
|
-
)
|
|
19
|
-
from ._foundry_evals import (
|
|
20
|
-
FoundryEvals,
|
|
21
|
-
GeneratedEvaluatorRef,
|
|
22
|
-
evaluate_foundry_target,
|
|
23
|
-
evaluate_traces,
|
|
24
|
-
)
|
|
25
|
-
from ._memory_provider import FoundryMemoryProvider
|
|
26
|
-
from ._to_prompt_agent import to_prompt_agent
|
|
27
|
-
|
|
28
|
-
try:
|
|
29
|
-
__version__ = importlib.metadata.version(__name__)
|
|
30
|
-
except importlib.metadata.PackageNotFoundError:
|
|
31
|
-
__version__ = "0.0.0"
|
|
32
|
-
|
|
33
|
-
__all__ = [
|
|
34
|
-
"FOUNDRY_HOSTED_AGENT_SESSION_ID_KEY",
|
|
35
|
-
"FoundryAgent",
|
|
36
|
-
"FoundryAgentOptions",
|
|
37
|
-
"FoundryChatClient",
|
|
38
|
-
"FoundryChatOptions",
|
|
39
|
-
"FoundryEmbeddingClient",
|
|
40
|
-
"FoundryEmbeddingOptions",
|
|
41
|
-
"FoundryEmbeddingSettings",
|
|
42
|
-
"FoundryEvals",
|
|
43
|
-
"FoundryMemoryProvider",
|
|
44
|
-
"GeneratedEvaluatorRef",
|
|
45
|
-
"RawFoundryAgent",
|
|
46
|
-
"RawFoundryAgentChatClient",
|
|
47
|
-
"RawFoundryChatClient",
|
|
48
|
-
"RawFoundryEmbeddingClient",
|
|
49
|
-
"__version__",
|
|
50
|
-
"evaluate_foundry_target",
|
|
51
|
-
"evaluate_traces",
|
|
52
|
-
"to_prompt_agent",
|
|
53
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{agent_framework_foundry-1.12.0 → agent_framework_foundry-1.13.1}/agent_framework_foundry/_tools.py
RENAMED
|
File without changes
|