Skip to content

Commit ad7e0a1

Browse files
howieleungYoYoJa
andauthored
work iq samples (#47184)
* work iq samples * Add work IQ project connection and user input to service preparer * update tests * push assets.json --------- Co-authored-by: Jessie Li <jessli@microsoft.com>
1 parent 7d8a485 commit ad7e0a1

28 files changed

Lines changed: 326 additions & 43 deletions

sdk/ai/azure-ai-projects/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ Breaking changes in beta classes:
7171
* `sample_models_basic.py` — synchronous end-to-end registration via the `create` helper (uses `azcopy`), followed by `get`, `list_versions`, `list`, `get_credentials`, `update`, and `delete`.
7272
* `sample_models_create_and_poll.py` — alternative synchronous registration that hand-rolls the spec's three-step flow (`pending_upload` → upload via `azure-storage-blob``pending_create_version` + poll), without taking a dependency on `azcopy`.
7373
* `sample_models_basic_async.py` — asynchronous version of the same three-step flow using `azure.ai.projects.aio.AIProjectClient` and `azure.storage.blob.aio.ContainerClient`.
74+
* Added new evaluation sample `sample_model_evaluation_instant_model.py` demonstrating model evaluation with an instant model.
75+
* Added new Agent tool samples `sample_agent_work_iq.py` and `sample_agent_work_iq_async.py` demonstrating use of `WorkIQPreviewTool`.
76+
* Added new Agent tool samples `sample_agent_fabric_iq.py` and `sample_agent_fabric_iq_async.py` demonstrating use of `FabricIQPreviewTool`.
77+
* Refreshed evaluation samples under `samples/evaluations/` and `samples/evaluations/agentic_evaluators/` (including `sample_agent_evaluation`, `sample_agent_response_evaluation`, `sample_eval_catalog_prompt_based_evaluators`, `sample_evaluations_ai_assisted`, `sample_evaluations_builtin_with_csv`, `sample_evaluations_builtin_with_dataset_id`, `sample_evaluations_builtin_with_inline_data`, `sample_evaluations_builtin_with_inline_data_oai`, `sample_scheduled_evaluations`, `sample_coherence`, `sample_fluency`, `sample_intent_resolution`, `sample_relevance`, `sample_response_completeness`, `sample_tool_call_accuracy`, `sample_tool_call_success`, `sample_tool_input_accuracy`, `sample_tool_output_utilization`, `sample_tool_selection`, and `sample_generic_agentic_evaluator`).
7478
* New sample `sample_dataset_generation_job_simpleqna_with_prompt_source.py` showing an end-to-end flow that generates a QnA dataset via `.beta.datasets.create_generation_job` and runs an OpenAI evaluation.
7579

7680
## 2.1.0 (2026-04-20)

sdk/ai/azure-ai-projects/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/ai/azure-ai-projects",
5-
"Tag": "python/ai/azure-ai-projects_7fc443e02a"
5+
"Tag": "python/ai/azure-ai-projects_7c0b4d3cf0"
66
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# pylint: disable=line-too-long,useless-suppression
2+
# ------------------------------------
3+
# Copyright (c) Microsoft Corporation.
4+
# Licensed under the MIT License.
5+
# ------------------------------------
6+
7+
"""
8+
DESCRIPTION:
9+
This sample demonstrates how to run a Prompt Agent that uses the
10+
WorkIQ preview tool with a synchronous client.
11+
12+
USAGE:
13+
python sample_agent_work_iq.py
14+
15+
Before running the sample:
16+
17+
pip install "azure-ai-projects>=2.2.0" python-dotenv
18+
19+
Set these environment variables with your own values:
20+
1) FOUNDRY_PROJECT_ENDPOINT - The Azure AI Project endpoint, as found in the Overview
21+
page of your Microsoft Foundry portal.
22+
2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in
23+
the "Models + endpoints" tab in your Microsoft Foundry project.
24+
3) WORK_IQ_PROJECT_CONNECTION_ID - The fully-qualified resource id of the WorkIQ project connection.
25+
4) WORK_IQ_USER_INPUT - The natural-language question to send to the agent.
26+
"""
27+
28+
import os
29+
from dotenv import load_dotenv
30+
from azure.identity import DefaultAzureCredential
31+
from azure.ai.projects import AIProjectClient
32+
from azure.ai.projects.models import PromptAgentDefinition, WorkIQPreviewTool
33+
34+
load_dotenv()
35+
36+
endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"]
37+
38+
with (
39+
DefaultAzureCredential() as credential,
40+
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
41+
project_client.get_openai_client() as openai_client,
42+
):
43+
tool_payload = WorkIQPreviewTool(
44+
project_connection_id=os.environ["WORK_IQ_PROJECT_CONNECTION_ID"],
45+
)
46+
47+
agent = project_client.agents.create_version(
48+
agent_name="MyAgent",
49+
definition=PromptAgentDefinition(
50+
model=os.environ["FOUNDRY_MODEL_NAME"],
51+
instructions="Use the available WorkIQ tools to answer questions and perform tasks.",
52+
tools=[tool_payload],
53+
),
54+
)
55+
print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})")
56+
57+
user_input = os.environ.get("WORK_IQ_USER_INPUT") or input("Enter your question:\n")
58+
59+
response = openai_client.responses.create(
60+
input=user_input,
61+
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
62+
)
63+
64+
print(f"Agent response: {response.output_text}")
65+
66+
# Clean up the agent version so unused versions don't accumulate in the project.
67+
project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version)
68+
print("Agent deleted")
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# pylint: disable=line-too-long,useless-suppression
2+
# ------------------------------------
3+
# Copyright (c) Microsoft Corporation.
4+
# Licensed under the MIT License.
5+
# ------------------------------------
6+
7+
"""
8+
DESCRIPTION:
9+
This sample demonstrates how to run a Prompt Agent that uses the
10+
WorkIQ preview tool with an asynchronous client.
11+
12+
USAGE:
13+
python sample_agent_work_iq_async.py
14+
15+
Before running the sample:
16+
17+
pip install "azure-ai-projects>=2.2.0" python-dotenv aiohttp
18+
19+
Set these environment variables with your own values:
20+
1) FOUNDRY_PROJECT_ENDPOINT - The Azure AI Project endpoint, as found in the Overview
21+
page of your Microsoft Foundry portal.
22+
2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in
23+
the "Models + endpoints" tab in your Microsoft Foundry project.
24+
3) WORK_IQ_PROJECT_CONNECTION_ID - The fully-qualified resource id of the WorkIQ project connection.
25+
4) WORK_IQ_USER_INPUT - The natural-language question to send to the agent.
26+
"""
27+
28+
import os
29+
import asyncio
30+
from dotenv import load_dotenv
31+
from azure.identity.aio import DefaultAzureCredential
32+
from azure.ai.projects.aio import AIProjectClient
33+
from azure.ai.projects.models import PromptAgentDefinition, WorkIQPreviewTool
34+
35+
load_dotenv()
36+
37+
endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"]
38+
39+
40+
async def main():
41+
async with (
42+
DefaultAzureCredential() as credential,
43+
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
44+
project_client.get_openai_client() as openai_client,
45+
):
46+
tool_payload = WorkIQPreviewTool(
47+
project_connection_id=os.environ["WORK_IQ_PROJECT_CONNECTION_ID"],
48+
)
49+
50+
agent = await project_client.agents.create_version(
51+
agent_name="MyAgent",
52+
definition=PromptAgentDefinition(
53+
model=os.environ["FOUNDRY_MODEL_NAME"],
54+
instructions="Use the available WorkIQ tools to answer questions and perform tasks.",
55+
tools=[tool_payload],
56+
),
57+
)
58+
print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})")
59+
60+
user_input = os.environ.get("WORK_IQ_USER_INPUT") or input("Enter your question:\n")
61+
62+
response = await openai_client.responses.create(
63+
input=user_input,
64+
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
65+
)
66+
67+
print(f"Agent response: {response.output_text}")
68+
69+
# Clean up the agent version so unused versions don't accumulate in the project.
70+
await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version)
71+
print("Agent deleted")
72+
73+
74+
if __name__ == "__main__":
75+
asyncio.run(main())

sdk/ai/azure-ai-projects/samples/evaluations/agentic_evaluators/sample_coherence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def main() -> None:
6868
type="azure_ai_evaluator",
6969
name="coherence",
7070
evaluator_name="builtin.coherence",
71-
initialization_parameters={"deployment_name": f"{model_deployment_name}"},
71+
initialization_parameters={"model": f"{model_deployment_name}"},
7272
data_mapping={"query": "{{item.query}}", "response": "{{item.response}}"},
7373
)
7474
]

sdk/ai/azure-ai-projects/samples/evaluations/agentic_evaluators/sample_fluency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def main() -> None:
6868
type="azure_ai_evaluator",
6969
name="fluency",
7070
evaluator_name="builtin.fluency",
71-
initialization_parameters={"deployment_name": f"{model_deployment_name}"},
71+
initialization_parameters={"model": f"{model_deployment_name}"},
7272
data_mapping={"query": "{{item.query}}", "response": "{{item.response}}"},
7373
)
7474
]

sdk/ai/azure-ai-projects/samples/evaluations/agentic_evaluators/sample_generic_agentic_evaluator/sample_generic_agentic_evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _get_evaluator_initialization_parameters(evaluator_name: str) -> dict[str, s
3737
if evaluator_name == "task_navigation_efficiency":
3838
return {"matching_mode": "exact_match"} # Can be "exact_match", "in_order_match", or "any_order_match"
3939
model_deployment_name = os.environ.get("FOUNDRY_MODEL_NAME", "") # Sample : gpt-4o-mini
40-
return {"deployment_name": model_deployment_name}
40+
return {"model": model_deployment_name}
4141

4242

4343
def _get_evaluation_contents() -> list[SourceFileContentContent]:

sdk/ai/azure-ai-projects/samples/evaluations/agentic_evaluators/sample_intent_resolution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def main() -> None:
7373
type="azure_ai_evaluator",
7474
name="intent_resolution",
7575
evaluator_name="builtin.intent_resolution",
76-
initialization_parameters={"deployment_name": f"{model_deployment_name}"},
76+
initialization_parameters={"model": f"{model_deployment_name}"},
7777
data_mapping={
7878
"query": "{{item.query}}",
7979
"response": "{{item.response}}",

sdk/ai/azure-ai-projects/samples/evaluations/agentic_evaluators/sample_relevance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def main() -> None:
7272
type="azure_ai_evaluator",
7373
name="relevance",
7474
evaluator_name="builtin.relevance",
75-
initialization_parameters={"deployment_name": f"{model_deployment_name}"},
75+
initialization_parameters={"model": f"{model_deployment_name}"},
7676
data_mapping={"query": "{{item.query}}", "response": "{{item.response}}"},
7777
)
7878
]

sdk/ai/azure-ai-projects/samples/evaluations/agentic_evaluators/sample_response_completeness.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def main() -> None:
7070
type="azure_ai_evaluator",
7171
name="response_completeness",
7272
evaluator_name="builtin.response_completeness",
73-
initialization_parameters={"deployment_name": f"{model_deployment_name}"},
73+
initialization_parameters={"model": f"{model_deployment_name}"},
7474
data_mapping={"ground_truth": "{{item.ground_truth}}", "response": "{{item.response}}"},
7575
)
7676
]

0 commit comments

Comments
 (0)