Skip to content

[azure-ai-projects] Add Agent Insights Samples - #48889

Open
seangayler-msft wants to merge 33 commits into
mainfrom
sean/agent-insights-samples
Open

[azure-ai-projects] Add Agent Insights Samples#48889
seangayler-msft wants to merge 33 commits into
mainfrom
sean/agent-insights-samples

Conversation

@seangayler-msft

@seangayler-msft seangayler-msft commented Sep 3, 2026

Copy link
Copy Markdown
Member

Samples

Adds two self-contained samples under samples/agent_insights/. Each registers a temporary external agent, emits fictional traces, waits for ingestion, and deletes its own monitor and agent in finally.

  • On-demand: analyze the traces, read results, and resolve one insight.
  • Scheduled: enable a six-hour schedule and print its settings without waiting for scheduled analysis. Cleanup disables scheduling and cancels active runs before deletion.

Setup and cleanup are simple functions at the bottom of each sample. The project, connected Application Insights, analysis-model deployment, and permissions must already exist. The samples do not deploy infrastructure or change roles.

Supporting changes

  • Remove the separate recording fixture and optional resource templates. Keep focused Agent Insights tests under tests/agent_insights/.
  • Fix sync/async cancelled-run handling and preserve Foundry-Features on polling requests and the final GET.
  • Refresh both recordings to cover the complete sample lifecycle, including trace export and agent cleanup, with scoped redaction and offline playback.
  • Target package version 2.7.0.

Cancel VS Cancelled Patch Explanation

Cancellation is a core Agent Insights capability. The service returns cancelled, but Azure Core's default polling logic recognizes canceled instead. Without the adapter, polling can continue after a run is cancelled. The patch makes cancellation terminal for the polling engine while keeping the public poller.status() value as cancelled.

@seangayler-msft seangayler-msft self-assigned this Sep 3, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The reviewed changes have no unresolved issues blocking approval.

Pull request overview

Adds a synchronous Agent Insights sample demonstrating a safe monitor lifecycle.

Changes:

  • Demonstrates monitor creation, retrieval, listing, and cleanup.
  • Registers sample testing and LLM validation.
  • Documents the sample in the changelog.
File summaries
File Description
sdk/ai/azure-ai-projects/tests/samples/test_samples.py Registers the sample, pending an HTTP recording.
sdk/ai/azure-ai-projects/tests/samples/llm_instructions.py Adds Agent Insights output validation mapping.
sdk/ai/azure-ai-projects/samples/agent_insights/sample_agent_insights_basic.py Implements the monitor lifecycle sample.
sdk/ai/azure-ai-projects/CHANGELOG.md Announces the new sample.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@seangayler-msft
seangayler-msft marked this pull request as ready for review September 3, 2026 20:44
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@seangayler-msft
seangayler-msft force-pushed the sean/agent-insights-samples branch from 2c62b9c to 36680dd Compare September 4, 2026 17:18
Copilot AI review requested due to automatic review settings September 4, 2026 17:18
@seangayler-msft
seangayler-msft marked this pull request as draft September 4, 2026 17:18
@seangayler-msft seangayler-msft changed the title [azure-ai-projects] Add basic Agent Insights sample [azure-ai-projects] Add reproducible Agent Insights sample Sep 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Live-test authentication and dependency ordering are broken, and fixture code is incompatible with supported Python 3.10.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 15/15 changed files
  • Comments generated: 4
  • Review effort level: Balanced

Comment thread sdk/ai/azure-ai-projects/test-resources-post.ps1 Outdated
Comment thread sdk/ai/azure-ai-projects/test-resources-post.ps1 Outdated
Comment thread sdk/ai/azure-ai-projects/tests/agent_insights/recording_fixture.py Outdated
Comment thread sdk/ai/azure-ai-projects/tests/agent_insights/test_recording_fixture.py Outdated
@seangayler-msft

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@seangayler-msft

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@seangayler-msft
seangayler-msft marked this pull request as ready for review September 4, 2026 18:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The scheduled sample can report a missing next-run timestamp despite its documented and tested contract.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

sdk/ai/azure-ai-projects/samples/agent_insights/sample_agent_insights_scheduled.py:89

  • This can print Next scheduled run: None, so the sample does not actually read the next run time it promises to demonstrate. The new unit test explicitly accepts next_run=None (test_agent_insights_samples.py:466-490), while the recorded-sample validator rejects that same output (sample_test_helpers.py:44-50). Treat a missing timestamp as an error or poll/get the enabled monitor until a timestamp is available, and update the unit test to require that behavior.
  • Files reviewed: 23/23 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Require agents without existing monitors. Delete on-demand monitors only after success; retain bounded scheduled teardown with ten-second polling. Update cleanup tests and maintainer guidance.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 965d2b3b-7439-4050-b224-cd487bcbb2bc
Copilot AI review requested due to automatic review settings September 10, 2026 17:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The polling and Azure resource changes depend on live service behavior that cannot be fully validated from the available recordings.

Review details
  • Files reviewed: 23/23 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 965d2b3b-7439-4050-b224-cd487bcbb2bc
Copilot AI review requested due to automatic review settings September 10, 2026 17:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It combines public polling behavior changes with live Azure resource provisioning and recorded integration workflows, warranting final human validation.

Review details
  • Files reviewed: 24/24 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Use default final-response handling, preserve feature headers throughout polling, and record the simplified sample workflows.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 965d2b3b-7439-4050-b224-cd487bcbb2bc
Copilot AI review requested due to automatic review settings September 10, 2026 18:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Public LRO behavior, external Azure resources, and live recording artifacts warrant final human validation.

Review details
  • Files reviewed: 24/24 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 965d2b3b-7439-4050-b224-cd487bcbb2bc
Copilot AI review requested due to automatic review settings September 10, 2026 19:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Production polling behavior, recordings, and Azure resource provisioning warrant final human validation.

Review details
  • Files reviewed: 23/23 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Remove duplicate error matrices and redundant mocked coverage while retaining polling headers, cancellation, cleanup races, future severity, and recording safeguards. Reuse the existing playback sleep fixture.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 965d2b3b-7439-4050-b224-cd487bcbb2bc
Copilot AI review requested due to automatic review settings September 10, 2026 20:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The live Azure resource fixture and service-dependent recording workflow require final human validation.

Review details
  • Files reviewed: 23/23 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Register temporary external agents, seed fictional telemetry, and clean up owned resources in each sample. Remove the separate provisioning fixture and keep focused lifecycle coverage. Recording refresh remains deferred.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 965d2b3b-7439-4050-b224-cd487bcbb2bc
Copilot AI review requested due to automatic review settings September 10, 2026 23:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The referenced recordings do not cover the new lifecycle, and recording sanitization would prevent deterministic playback.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 19/19 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment thread sdk/ai/azure-ai-projects/tests/agent_insights/sanitizers.py
# Sanitize checkpoint IDs in URLs and response bodies
add_general_regex_sanitizer(regex=r"ftchkpt-[a-f0-9]+", value="sanitized-checkpoint-id")

add_agent_insights_sanitizers()
Comment thread sdk/ai/azure-ai-projects/assets.json Outdated
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/ai/azure-ai-projects",
"Tag": "python/ai/azure-ai-projects_81db4bd08f"
"Tag": "python/ai/azure-ai-projects_ca13a42c98"
Record the complete temporary-agent sample lifecycle, scope telemetry redactions, and preserve trace relationships during playback. Align the package, changelog, sample requirements, and generated API metadata with version 2.7.0.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 965d2b3b-7439-4050-b224-cd487bcbb2bc
Copilot AI review requested due to automatic review settings September 11, 2026 00:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The service-backed recordings and resource-creation cleanup paths warrant final human validation.

Review details
  • Files reviewed: 18/18 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants