Add sample routines for hosted agents with various triggers#48121
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 9 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
Updates hosted-agent routine samples to self-provision temporary agent versions and adds GitHub issue trigger coverage.
Changes:
- Adds a GitHub issue-triggered routine sample.
- Makes existing routine samples create and clean up temporary hosted-agent versions.
- Documents required model and trigger configuration.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
sample_routines_with_timer_trigger.py |
Self-provisions an agent for timer routines. |
sample_routines_with_schedule_trigger.py |
Self-provisions an agent for scheduled routines. |
sample_routines_with_github_issue_trigger.py |
Adds GitHub issue-triggered routine usage. |
sample_routines_with_dispatch.py |
Self-provisions an agent for dispatched routines. |
sample_routines_crud.py |
Self-provisions an agent for CRUD demonstrations. |
Comments suppressed due to low confidence (3)
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_timer_trigger.py:74
- The temporary agent version is cleaned up when this context exits, but the routine is deleted only on the normal path. Any polling/service error or
KeyboardInterruptafter creation leaves an enabled timer routine behind while restoring/deleting the agent version it was intended to invoke. Wrap the routine lifecycle intry/finally, as the schedule-trigger sample does, so the routine is deleted before this context unwinds.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_dispatch.py:79 - The temporary agent version is cleaned up when this context exits, but the routine is deleted only on the normal path. If dispatching or polling raises, the sample leaves a stale routine behind after restoring/deleting its backing agent version. Please protect the routine lifecycle with
try/finally, matching the schedule-trigger sample's cleanup pattern.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_crud.py:72 - The new temporary hosted-agent context always removes/restores its version, but the routine cleanup remains normal-path only. If any CRUD call fails after creation, this leaves a routine referring to an agent whose temporary version has already been removed. Please place routine deletion in a
finallyblock inside this context.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (4)
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_github_issue_trigger.py:77
- This sample is automatically included by
test_hosted_agents_samples, butservicePreparerdoes not defineGITHUB_CONNECTION_NAME,GITHUB_USERNAME, orGITHUB_REPOSITORY. The sample test will therefore raiseKeyErrorwhile importing this module. Exclude this externally triggered sample from the hosted-agent parametrization, or add a dedicated test configuration that supplies all three values.
github_connection_name = os.environ["GITHUB_CONNECTION_NAME"]
poll_interval_seconds = int(os.environ.get("POLL_INTERVAL_SECONDS", "10"))
github_owner = os.environ["GITHUB_USERNAME"]
github_repository = os.environ["GITHUB_REPOSITORY"]
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_dispatch.py:83
- If dispatching or polling raises, this context manager deletes the temporary hosted-agent version while the routine created below is never deleted, leaving a routine bound to a removed/restored agent route. Wrap routine creation and use in
try/finallyand delete the routine in thefinallyblock before this context exits, as the schedule-trigger sample does.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_crud.py:76 - If any CRUD operation raises, this context manager still deletes the temporary hosted-agent version, but the routine created below remains and points at a removed/restored agent route. Put the routine lifecycle in
try/finallyand delete the routine infinallybefore the hosted-agent context exits.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_timer_trigger.py:78 - If routine creation or polling raises, the temporary hosted-agent version is cleaned up by this context manager but the timer routine is left behind, bound to a removed/restored agent route. Protect the routine lifecycle with
try/finallyand delete the routine infinallybefore exiting this context.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (3)
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_github_issue_trigger.py:41
- The sample describes this value as a repository name but tells users to provide a full clone URL, while
owneris supplied separately toGitHubIssueRoutineTrigger. This makes the required filter format ambiguous and can cause the trigger never to match. Please document the exact service-accepted value (repository name/slug versus URL) consistently.
6) GITHUB_REPOSITORY - The GitHub repository name in the format of https://github.com/xxx/xxx.git.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_github_issue_trigger.py:125
- This inline comment is not Black-formatted (two spaces are required before it), and the sentence is ungrammatical. This newly added sample can therefore fail formatting validation.
connection_id=github_connection_name, # currently it accept connection name
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_schedule_trigger.py:77
- Opening the zip stream at module import makes
main()one-shot: the first call closes the stream, so a second call uploads from a closed file, and importing without callingmain()leaks the open handle. Create the stream insidemain(), as the new GitHub-trigger sample does.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_github_issue_trigger.py:41
owneris supplied separately toGitHubIssueRoutineTrigger, sorepositoryshould be only the repository name. Following the documented full-URL format passes that URL unchanged as the repository filter and can prevent the trigger from matching issues.
6) GITHUB_REPOSITORY - The GitHub repository name in the format of https://github.com/xxx/xxx.git.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_github_issue_trigger.py:125
- Correct the grammar in this explanatory comment.
connection_id=github_connection_name, # currently it accept connection name
sdk/ai/azure-ai-projects/tests/samples/test_samples.py:305
- Correct the grammar and GitHub capitalization in this skip reason.
"sample_routines_with_github_issue_trigger.py", # Cannot run without interact on Github
[Pilot] PR Pipeline Failure AnalysisA CI pipeline failed on this pull request. Here is an automated analysis of what went wrong and how to get the build green. What failedA single test — Recommended next steps
Raw pipeline analysis (azsdk ci analyze)
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (7)
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_schedule_trigger.py:77
select_basic_agent_code_zipimmediately opens the generated zip stream, but this happens at module import while onlymain()closes it. Importing the sample without callingmain()leaks the descriptor, and callingmain()twice reuses a closed stream. Create the stream insidemain(), as the new GitHub sample does.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_timer_trigger.py:74- Once this context is added, an exception or Ctrl+C after the routine is created exits the helper and deletes the temporary agent version, but the routine deletion at the bottom is skipped. That leaves a timer routine referring to a restored/deleted agent setup. Wrap the routine lifecycle in
try/finallyand delete the routine in thefinally, as the schedule sample does.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_dispatch.py:79 - An exception or Ctrl+C after routine creation skips the bottom-of-file delete. The newly added helper context still restores the endpoint and deletes the temporary agent version, leaving the dispatch routine orphaned. Put routine cleanup in a
finallyblock, matching the schedule and GitHub samples.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_timer_trigger.py:53 - This newly added hosted-agent setup calls the stable
project_client.agents.create_version_from_codeAPI through the helper, but that API moved from.beta.agentsonly in 2.3.0 (CHANGELOG.md:9). The sample still tells users to installazure-ai-projects>=2.2.0, so that documented environment cannot run the sample; raise the prerequisite to 2.3.0.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_schedule_trigger.py:57 - This newly added hosted-agent setup uses the stable
.agents.create_version_from_codepath through the helper, which became available in 2.3.0 (CHANGELOG.md:9). The sample's prerequisite remainsazure-ai-projects>=2.2.0, so update it to 2.3.0.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_dispatch.py:57 - The added hosted-agent setup invokes stable
.agents.create_version_from_codevia the helper, but that API moved from.beta.agentsin 2.3.0 (CHANGELOG.md:9). Keeping the documentedazure-ai-projects>=2.2.0minimum makes the sample fail for users on that version; raise it to 2.3.0.
sdk/ai/azure-ai-projects/tests/samples/test_samples.py:305 - Use the product name's canonical capitalization and make the skip reason grammatical.
"sample_routines_with_github_issue_trigger.py", # Cannot run without interact on Github
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (4)
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_dispatch.py:79
- If any operation after routine creation raises (including
dispatch,list_runs, or Ctrl+C), this context manager deletes the temporary hosted-agent version while the routine deletion at the end is skipped. That leaves a live routine targeting a deleted version. Put the routine lifecycle in atry/finallyand tolerateResourceNotFoundErrorduring cleanup, as the schedule-trigger sample does.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_timer_trigger.py:74 - If routine creation succeeds and polling later raises or is interrupted, this context manager removes the temporary hosted-agent version but the routine deletion at the end is never reached. The remaining timer routine then targets a deleted version. Wrap the routine lifecycle in a
try/finallyand tolerateResourceNotFoundErrorduring cleanup, matching the schedule-trigger sample.
sdk/ai/azure-ai-projects/samples/routines/sample_routines_crud.py:1 - Deleting this sample leaves the current unreleased CHANGELOG entry (
CHANGELOG.md:47) claiming thatsample_routines_crud.pyis being added. Please either retain/move the sample or update the release notes so they do not point users to a nonexistent file.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_github_issue_trigger.py:10 - The unreleased CHANGELOG has a dedicated “Sample updates” list (
CHANGELOG.md:41-52) but does not mention this newly added GitHub issue-trigger sample. Add an entry so the new user-facing sample is included in the package release notes.
This sample demonstrates how to create a Routine that fires when a GitHub
issue is opened in a GitHub repository.
Co-authored-by: howieleung <177042912+howieleung@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (7)
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_timer_trigger.py:34
- This sample now calls
create_version_from_code, whose helper uses the stableproject_client.agents.create_version_from_codeAPI. The package changelog documents that API as moving from.beta.agentsto.agentsin 2.3.0, but this sample still tells users that 2.2.0 is sufficient. Following the documented install command can therefore fail; raise the minimum version to 2.3.0.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_schedule_trigger.py:36 - This sample now calls
create_version_from_code, whose helper uses the stableproject_client.agents.create_version_from_codeAPI. The package changelog documents that API as moving from.beta.agentsto.agentsin 2.3.0, but this sample still tells users that 2.2.0 is sufficient. Following the documented install command can therefore fail; raise the minimum version to 2.3.0.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_dispatch.py:38 - This sample now calls
create_version_from_code, whose helper uses the stableproject_client.agents.create_version_from_codeAPI. The package changelog documents that API as moving from.beta.agentsto.agentsin 2.3.0, but this sample still tells users that 2.2.0 is sufficient. Following the documented install command can therefore fail; raise the minimum version to 2.3.0.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_dispatch.py:83 - The routine is deleted only on the success path, while this new context manager always restores/deletes the temporary hosted-agent version during unwinding. Any dispatch, polling, or interruption error leaves an enabled routine behind after its intended agent version is removed (or after routing is restored to a pre-existing version). Wrap the routine lifecycle in
try/finally, as the schedule and GitHub samples do, so the routine is always deleted before this context exits.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_timer_trigger.py:78 - The routine is deleted only on the success path, while this new context manager always restores/deletes the temporary hosted-agent version during unwinding. Any polling or interruption error leaves an enabled timer routine behind after its intended agent version is removed (or after routing is restored to a pre-existing version). Wrap the routine lifecycle in
try/finally, as the schedule and GitHub samples do, so the routine is always deleted before this context exits.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_github_issue_trigger.py:10 - This adds a new user-facing GitHub-trigger sample and the PR also removes the CRUD sample, but
CHANGELOG.mdhas no entry for either change. Add an unreleased sample-updates entry so the package history reflects the added and removed samples, as required for significant SDK changes.
"""
DESCRIPTION:
This sample demonstrates how to create a Routine that fires when a GitHub
issue is opened in a GitHub repository.
sdk/ai/azure-ai-projects/tests/samples/test_samples.py:305
- Use “Cannot run without interaction on GitHub” for correct grammar and product capitalization.
"sample_routines_with_github_issue_trigger.py", # Cannot run without interact on Github
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (3)
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_timer_trigger.py:74
- This newly added setup calls
create_version_from_code, whose helper uses the stableproject_client.agents.create_version_from_codeAPI. That API moved to.agentsin 2.3.0 (CHANGELOG.md:9), but this sample still instructs users to installazure-ai-projects>=2.2.0; a 2.2.x environment will fail before the routine runs. Please raise the sample's documented minimum to 2.3.0.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_schedule_trigger.py:85 - This newly added setup calls
create_version_from_code, whose helper uses the stableproject_client.agents.create_version_from_codeAPI. That API moved to.agentsin 2.3.0 (CHANGELOG.md:9), but this sample still instructs users to installazure-ai-projects>=2.2.0; a 2.2.x environment will fail before the routine runs. Please raise the sample's documented minimum to 2.3.0.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_dispatch.py:79 - This newly added setup calls
create_version_from_code, whose helper uses the stableproject_client.agents.create_version_from_codeAPI. That API moved to.agentsin 2.3.0 (CHANGELOG.md:9), but this sample still instructs users to installazure-ai-projects>=2.2.0; a 2.2.x environment will fail before the routine runs. Please raise the sample's documented minimum to 2.3.0.
…k-for-python into howie/samples-230
Co-authored-by: howieleung <177042912+howieleung@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (5)
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_dispatch.py:40
- The new hosted-agent setup uses the stable
project_client.agents.create_version_from_codeAPI throughcreate_version_from_code, but this sample still tells users to install 2.2.0. In 2.2.0 that operation was under.beta.agentsand had the older signature (seeCHANGELOG.md:7-9,28), so following these prerequisites causes the sample to fail. Requireazure-ai-projects>=2.3.0.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_timer_trigger.py:36 - The new hosted-agent setup uses the stable
project_client.agents.create_version_from_codeAPI throughcreate_version_from_code, but this sample still tells users to install 2.2.0. In 2.2.0 that operation was under.beta.agentsand had the older signature (seeCHANGELOG.md:7-9,28), so following these prerequisites causes the sample to fail. Requireazure-ai-projects>=2.3.0.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_schedule_trigger.py:39 - The new hosted-agent setup uses the stable
project_client.agents.create_version_from_codeAPI throughcreate_version_from_code, but this sample still tells users to install 2.2.0. In 2.2.0 that operation was under.beta.agentsand had the older signature (seeCHANGELOG.md:7-9,28), so following these prerequisites causes the sample to fail. Requireazure-ai-projects>=2.3.0.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_github_issue_trigger.py:41 GitHubIssueRoutineTriggertakesownerandrepositoryseparately, sorepositorymust be the repository name (for example,azure-sdk-for-python), not a full clone URL. Following the documented URL format sends the wrong repository filter and the issue event will not match.
6) GITHUB_REPOSITORY - The GitHub repository name in the format of https://github.com/xxx/xxx.git.
sdk/ai/azure-ai-projects/tests/samples/test_samples.py:305
- Use the correct GitHub capitalization and replace the ungrammatical skip reason.
"sample_routines_with_github_issue_trigger.py", # Cannot run without interact on Github
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (7)
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_timer_trigger.py:74
- This context manager always deletes the temporary hosted-agent version on exit, but the routine is deleted only on the happy path at line 144. If dispatch polling raises or the user interrupts after
create_or_update, the sample leaves a timer routine referencing a deleted agent version. Put the routine lifecycle in atry/finally, as the schedule and GitHub-trigger samples do.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_dispatch.py:79 - This context manager always deletes the temporary hosted-agent version on exit, but the routine is deleted only on the happy path at line 162. If dispatch or polling raises, the sample leaves a routine referencing a deleted agent version. Put the routine lifecycle in a
try/finally, as the schedule and GitHub-trigger samples do.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_github_issue_trigger.py:41 - The trigger already receives the owner separately, and
repositoryexpects a repository filter/name rather than a full GitHub URL. A user following this URL example will pass the wrong value toGitHubIssueRoutineTrigger, so document a repository-name example instead.
6) GITHUB_REPOSITORY - The GitHub repository name in the format of https://github.com/xxx/xxx.git.
sdk/ai/azure-ai-projects/tests/samples/test_samples.py:305
- Correct the grammar and GitHub capitalization in this skip reason.
"sample_routines_with_github_issue_trigger.py", # Cannot run without interact on Github
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_timer_trigger.py:34
- Because this newly required model setting is used by the temporary hosted agent created through stable
project_client.agents.create_version_from_code, the installation instruction above must require 2.3.0, where that method moved from.beta.agents. An existing 2.2.0 installation currently satisfies the documented command but cannot run this updated sample.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_schedule_trigger.py:36 - Because this newly required model setting is used by the temporary hosted agent created through stable
project_client.agents.create_version_from_code, the installation instruction above must require 2.3.0, where that method moved from.beta.agents. An existing 2.2.0 installation currently satisfies the documented command but cannot run this updated sample.
sdk/ai/azure-ai-projects/samples/hosted_agents/sample_routines_with_dispatch.py:38 - Because this newly required model setting is used by the temporary hosted agent created through stable
project_client.agents.create_version_from_code, the installation instruction above must require 2.3.0, where that method moved from.beta.agents. An existing 2.2.0 installation currently satisfies the documented command but cannot run this updated sample.
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