Updates to support release of version 2.2.0 of azure-ai-projects package#46894
Open
dargilco wants to merge 11 commits into
Open
Updates to support release of version 2.2.0 of azure-ai-projects package#46894dargilco wants to merge 11 commits into
dargilco wants to merge 11 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Fixed telemetry instrumentor to correctly call is_recording() as a method * adding tests * updating changelog
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates azure-ai-projects for the upcoming 2.2.0 release, including new preview tools, API surface renames, and telemetry fixes.
Changes:
- Fix span recording guards in telemetry instrumentors by correctly calling
is_recording()and add tests for non-recording spans. - Apply breaking API updates/renames across models/operations (e.g.,
AgentEndpointConfig,PendingUploadResult,SkillDetails,taxonomyarg rename, remove sessionisolation_key). - Update and add samples demonstrating new features (toolbox tool-search) and update hosted agents/evaluations samples to match renamed APIs.
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/ai/azure-ai-projects/tests/samples/llm_instructions.py | Formatting-only change to instruction strings (parenthesized multi-line literals). |
| sdk/ai/azure-ai-projects/tests/agents/telemetry/test_non_recording_span.py | Adds regression tests ensuring instrumentors skip non-recording spans. |
| sdk/ai/azure-ai-projects/samples/hosted_agents/sample_sessions_crud_async.py | Updates session CRUD sample for removal of isolation_key. |
| sdk/ai/azure-ai-projects/samples/hosted_agents/sample_sessions_crud.py | Updates session CRUD sample for removal of isolation_key. |
| sdk/ai/azure-ai-projects/samples/hosted_agents/sample_session_log_stream_async.py | Updates endpoint config type rename (AgentEndpointConfig). |
| sdk/ai/azure-ai-projects/samples/hosted_agents/sample_session_log_stream.py | Updates endpoint config type rename (AgentEndpointConfig). |
| sdk/ai/azure-ai-projects/samples/hosted_agents/sample_agent_endpoint_async.py | Updates endpoint config type rename (AgentEndpointConfig). |
| sdk/ai/azure-ai-projects/samples/hosted_agents/sample_agent_endpoint.py | Updates endpoint config type rename (AgentEndpointConfig). |
| sdk/ai/azure-ai-projects/samples/hosted_agents/hosted_agents_util.py | Updates helper to remove isolation_key usage when creating/deleting sessions. |
| sdk/ai/azure-ai-projects/samples/evaluations/sample_scheduled_evaluations.py | Updates evaluation taxonomy create call to use taxonomy= parameter. |
| sdk/ai/azure-ai-projects/samples/evaluations/sample_redteam_evaluations.py | Updates evaluation taxonomy create call to use taxonomy= parameter. |
| sdk/ai/azure-ai-projects/samples/agents/sample_toolboxes_with_search_preview_async.py | Adds async sample for Toolbox tool-search preview via MCP. |
| sdk/ai/azure-ai-projects/samples/agents/sample_toolboxes_with_search_preview.py | Adds sync sample for Toolbox tool-search preview via MCP. |
| sdk/ai/azure-ai-projects/cspell.json | Adds spelling exceptions and normalizes ordering. |
| sdk/ai/azure-ai-projects/azure/ai/projects/telemetry/_utils.py | Fixes is_recording guard to call is_recording() correctly. |
| sdk/ai/azure-ai-projects/azure/ai/projects/telemetry/_responses_instrumentor.py | Fixes multiple is_recording guards to call is_recording(). |
| sdk/ai/azure-ai-projects/azure/ai/projects/telemetry/_ai_project_instrumentor.py | Fixes is_recording guards to call is_recording(). |
| sdk/ai/azure-ai-projects/azure/ai/projects/operations/_patch_sessions.py | Updates session file upload return type rename to SessionFileWriteResult. |
| sdk/ai/azure-ai-projects/azure/ai/projects/operations/_patch_datasets.py | Updates pending upload type rename to PendingUploadResult. |
| sdk/ai/azure-ai-projects/azure/ai/projects/operations/_operations.py | Applies API surface renames/removals (sessions isolation key removal, taxonomy arg rename, skill result renames, etc.). |
| sdk/ai/azure-ai-projects/azure/ai/projects/models/_models.py | Introduces/renames models and tools (e.g., FabricIQPreviewTool, ToolboxSearchPreviewTool, AgentEndpointConfig, target config renames). |
| sdk/ai/azure-ai-projects/azure/ai/projects/models/_enums.py | Updates enums (adds MCP protocol/tool types, removes isolation key source enum). |
| sdk/ai/azure-ai-projects/azure/ai/projects/models/init.py | Re-exports updated/renamed models and enums. |
| sdk/ai/azure-ai-projects/azure/ai/projects/aio/operations/_patch_sessions_async.py | Async session file upload return type rename to SessionFileWriteResult. |
| sdk/ai/azure-ai-projects/azure/ai/projects/aio/operations/_patch_datasets_async.py | Async pending upload type rename to PendingUploadResult. |
| sdk/ai/azure-ai-projects/azure/ai/projects/aio/operations/_operations.py | Async operations updated for the same API renames/removals as sync operations. |
| sdk/ai/azure-ai-projects/assets.json | Bumps assets tag reference. |
| sdk/ai/azure-ai-projects/apiview-properties.json | Updates APIView type map for renamed/new models. |
| sdk/ai/azure-ai-projects/CHANGELOG.md | Adds 2.2.0 entry describing new features, breaking changes, and telemetry fix. |
| sdk/ai/azure-ai-projects/.github/skills/azure-ai-projects-emit-from-typespec/SKILL.md | Adds internal skill documentation for emitting SDK from TypeSpec. |
| sdk/ai/azure-ai-projects/.github/skills/README.md | Adds README for using the local Copilot skills workflow. |
Comment on lines
881
to
+897
| @@ -898,10 +894,7 @@ def build_beta_agents_delete_session_request( | |||
| # Construct parameters | |||
| _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") | |||
|
|
|||
| # Construct headers | |||
| _headers["x-session-isolation-key"] = _SERIALIZER.header("isolation_key", isolation_key, "str") | |||
|
|
|||
| return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) | |||
| return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) | |||
Comment on lines
+5365
to
5368
| self, agent_name: str, body: JSON, *, content_type: str = "application/json", **kwargs: Any | ||
| ) -> _models.AgentSessionResource: | ||
| """Creates a new session for an agent endpoint. The endpoint resolves the backing agent version | ||
| from ``version_indicator`` and enforces session ownership using the provided isolation key for |
Comment on lines
+24
to
+33
| def _make_non_recording_span(): | ||
| """Return a mock AbstractSpan wrapping a non-recording OTel span. | ||
|
|
||
| * ``span_instance.is_recording()`` returns ``False`` | ||
| * ``span_instance.is_recording`` (the property/method) also returns ``False`` | ||
| so the guard correctly skips writes. | ||
| * Any call to ``add_event``, ``set_status``, ``record_exception`` or | ||
| ``set_attribute`` raises ``AssertionError``, catching any code path | ||
| that fails to check ``is_recording()`` properly. | ||
| """ |
|
|
||
| class ToolboxSearchPreviewTool(Tool, discriminator="toolbox_search_preview"): | ||
| """A tool for searching over the agent's toolbox. When present, deferred tools are hidden from | ||
| ``tools/list`` and only discoverable via ``search_tools`` queries at runtime. |
|
|
||
| from dotenv import load_dotenv | ||
|
|
||
| from azure.core.exceptions import ResourceNotFoundError |
Comment on lines
+75
to
+125
| toolbox_version = project_client.beta.toolboxes.create_version( | ||
| name=TOOLBOX_NAME, | ||
| description=f"Toolbox with `{INNER_MCP_LABEL}` MCP server and tool search enabled.", | ||
| tools=[inner_mcp_tool, ToolboxSearchPreviewTool()], | ||
| ) | ||
| print(f"Created toolbox `{TOOLBOX_NAME}` (version {toolbox_version.version}).") | ||
|
|
||
| toolbox_mcp_url = f"{endpoint}/toolboxes/{TOOLBOX_NAME}/versions/{toolbox_version.version}/mcp?api-version=v1" | ||
| token = credential.get_token("https://ai.azure.com/.default").token | ||
|
|
||
| toolbox_mcp_tool = MCPTool( | ||
| server_label=TOOLBOX_MCP_LABEL, | ||
| server_url=toolbox_mcp_url, | ||
| authorization=token, | ||
| headers={"Foundry-Features": "Toolboxes=V1Preview"}, | ||
| require_approval="never", | ||
| ) | ||
|
|
||
| agent = project_client.agents.create_version( | ||
| agent_name="MyAgent", | ||
| definition=PromptAgentDefinition( | ||
| model=os.environ["FOUNDRY_MODEL_NAME"], | ||
| instructions=( | ||
| "Always use the toolbox search tool to answer questions and perform tasks. " | ||
| "Use `tool_search` to discover a relevant tool, then `call_tool` " | ||
| "with the tool name returned by the search." | ||
| ), | ||
| tools=[toolbox_mcp_tool], | ||
| ), | ||
| ) | ||
| print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version}).") | ||
|
|
||
| response = openai_client.responses.create( | ||
| input="What is my username in Github profile?", | ||
| extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, | ||
| ) | ||
|
|
||
| for item in response.output: | ||
| if item.type == "mcp_approval_request": | ||
| print(f"server_label={item.server_label}, name={item.name}") | ||
| elif item.type == "mcp_list_tools": | ||
| print(f"server_label={item.server_label}, tools={[t.name for t in (item.tools or [])]}") | ||
| elif item.type == "mcp_call": | ||
| print(f"server_label={item.server_label}, name={item.name}, error={item.error}") | ||
| else: | ||
| print() | ||
|
|
||
| print(f"Response: {response.output_text}") | ||
|
|
||
| project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) | ||
| print(f"Agent version {agent.version} deleted.") |
Comment on lines
+68
to
+126
|
|
||
| inner_mcp_tool = MCPTool( | ||
| server_label=INNER_MCP_LABEL, | ||
| server_url=INNER_MCP_URL, | ||
| require_approval="never", | ||
| project_connection_id=os.environ["MCP_PROJECT_CONNECTION_ID"], | ||
| ) | ||
|
|
||
| toolbox_version = await project_client.beta.toolboxes.create_version( | ||
| name=TOOLBOX_NAME, | ||
| description=f"Toolbox with `{INNER_MCP_LABEL}` MCP server and tool search enabled.", | ||
| tools=[inner_mcp_tool, ToolboxSearchPreviewTool()], | ||
| ) | ||
| print(f"Created toolbox `{TOOLBOX_NAME}` (version {toolbox_version.version}).") | ||
|
|
||
| toolbox_mcp_url = f"{endpoint}/toolboxes/{TOOLBOX_NAME}/versions/{toolbox_version.version}/mcp?api-version=v1" | ||
| token = (await credential.get_token("https://ai.azure.com/.default")).token | ||
|
|
||
| toolbox_mcp_tool = MCPTool( | ||
| server_label=TOOLBOX_MCP_LABEL, | ||
| server_url=toolbox_mcp_url, | ||
| authorization=token, | ||
| headers={"Foundry-Features": "Toolboxes=V1Preview"}, | ||
| require_approval="never", | ||
| ) | ||
|
|
||
| agent = await project_client.agents.create_version( | ||
| agent_name="MyAgent", | ||
| definition=PromptAgentDefinition( | ||
| model=os.environ["FOUNDRY_MODEL_NAME"], | ||
| instructions=( | ||
| "Always use the toolbox search tool to answer questions and perform tasks. " | ||
| "Use `tool_search` to discover a relevant tool, then `call_tool` " | ||
| "with the tool name returned by the search." | ||
| ), | ||
| tools=[toolbox_mcp_tool], | ||
| ), | ||
| ) | ||
| print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version}).") | ||
|
|
||
| response = await openai_client.responses.create( | ||
| input="What is my username in Github profile?", | ||
| extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, | ||
| ) | ||
|
|
||
| for item in response.output: | ||
| if item.type == "mcp_approval_request": | ||
| print(f"server_label={item.server_label}, name={item.name}") | ||
| elif item.type == "mcp_list_tools": | ||
| print(f"server_label={item.server_label}, tools={[t.name for t in (item.tools or [])]}") | ||
| elif item.type == "mcp_call": | ||
| print(f"server_label={item.server_label}, name={item.name}, error={item.error}") | ||
| else: | ||
| print() | ||
|
|
||
| print(f"Response: {response.output_text}") | ||
|
|
||
| await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) | ||
| print(f"Agent version {agent.version} deleted.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See CHANGELOG.md