For hosted agent, remove rbac assignment, make all of them always cre…#47887
For hosted agent, remove rbac assignment, make all of them always cre…#47887howieleung wants to merge 3 commits into
Conversation
…ate version or create from code, call update details and use agent endpoint. and tear down by restore back the agent detail and delete hosted agent. Removed echo agent and use basic agent instead
There was a problem hiding this comment.
Pull request overview
This PR reworks the azure-ai-projects hosted-agent samples so they no longer depend on RBAC role assignment. RBAC support (rbac_util.py, ensure_agent_identity_rbac[_async]) is removed, and the image/code/session samples now consistently create a version, route the agent endpoint to it via update_details, exercise it, and then tear down (restore the original endpoint and delete the version). The old echo-agent asset is replaced with basic-agent, the zip helper is renamed to zip_directory, and shared create_version_from_code[_async] context managers centralize the create/wait/route/teardown lifecycle. Sample renames (sample_create_hosted_agent[_async].py → ..._from_image[_async].py) and the removal of sample_agent_endpoint[_async].py are reflected in the sample-test parametrization.
Changes:
- Remove RBAC assignment path and the
echo-agentcontainer asset; standardize samples oncreate_version_from_code[_async]+update_details+ endpoint restore + version delete. - Rename
zip→zip_directoryand theselect_echo_agent_code_ziphelper →select_basic_agent_code_zip; add shared lifecycle context managers. - Update sample-test discovery/parametrization (new session/log-stream entries, renamed image samples) and add a
_resolve_sample_path_from_filenamefallback insample_executor.py.
Reviewed changes
Copilot reviewed 27 out of 34 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| samples/hosted_agents/hosted_agents_util.py | Adds create_version_from_code[_async] context managers; renames helper to select_basic_agent_code_zip; drops get_latest_active_agent_version[_async]. |
| samples/hosted_agents/sample_create_hosted_agent_from_image.py | Renamed from sample_create_hosted_agent.py; RBAC replaced with endpoint routing (stale RBAC/echo-agent docstrings remain; no teardown). |
| samples/hosted_agents/sample_create_hosted_agent_from_image_async.py | New async image sample with endpoint routing + teardown (stale echo-agent ref and unneeded mgmt deps in docstring). |
| samples/hosted_agents/sample_create_hosted_agent_from_code[_async].py | Switch to basic-agent, hardcode agent name, add endpoint routing + teardown. |
| samples/hosted_agents/sample_sessions_crud[_async].py, sample_sessions_files_upload_download[_async].py, sample_session_log_stream[_async].py | Create a temporary version via the new context manager instead of resolving an existing active version. |
| samples/hosted_agents/sample_toolbox_with_skill.py, sample_agent_user_identity_isolation.py | Use create_version_from_code; remove RBAC and inline lifecycle handling. |
| samples/hosted_agents/rbac_util.py, sample_agent_endpoint[_async].py, sample_create_hosted_agent_async.py, assets/echo-agent/* | Deleted. |
| samples/hosted_agents/assets/Dockerfile | New Dockerfile for building an agent image. |
| samples/util.py, samples/skills/sample_skills_upload_and_download[_async].py | zip → zip_directory rename and callers updated. |
| tests/samples/test_samples.py, test_samples_async.py, sample_executor.py, test_util.py | Update sample-test parametrization/skip lists and add synthetic-path fallback logic. |
Comments suppressed due to low confidence (3)
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_create_hosted_agent_from_image.py:15
- This docstring still claims the sample sets up agent identity RBAC via
ensure_agent_identity_rbac, but RBAC was removed from this sample in this PR (therbac_utilimport and theensure_agent_identity_rbaccall are gone, andrbac_util.pyis deleted). The statement is now inaccurate and should be updated to reflect that the sample routes the agent endpoint viaupdate_details.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_create_hosted_agent_from_image.py:30 - This references the
assets/echo-agentfolder, which is deleted in this PR (itsmain.py,README.md, andrequirements.txtare removed). The replacement asset isassets/basic-agent(a newassets/Dockerfileis also added). Please update the reference so users aren't pointed at a nonexistent folder.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_create_hosted_agent_from_image.py:93 - Unlike its async counterpart
sample_create_hosted_agent_from_image_async.py(which capturesoriginal_agent_endpoint, restores it, and deletes the created version in afinallyblock), this sync sample configures the endpoint viaupdate_detailsbut never restores the original endpoint or deletes the created version. This diverges from the PR's stated goal of "tear down by restore back the agent detail and delete hosted agent" and, on repeated runs, leaves the agent endpoint pointed at a version and accumulates undeleted versions. Consider wrapping the body in try/finally with endpoint restore and version cleanup to match the async variant.
…ate version or create from code, call update details and use agent endpoint. and tear down by restore back the agent detail and delete hosted agent. Removed echo agent and use basic agent instead
Description
Please add an informative description that covers that changes made by the pull request and link all relevant issues.
If an SDK is being regenerated based on a new API spec, a link to the pull request containing these API spec changes should be included above.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines