Skip to content

python/autonomous/github-trending: support Foundry endpoints + wire observability flags#322

Open
Yogeshp-MSFT wants to merge 2 commits into
microsoft:mainfrom
Yogeshp-MSFT:python/foundry-and-observability-support
Open

python/autonomous/github-trending: support Foundry endpoints + wire observability flags#322
Yogeshp-MSFT wants to merge 2 commits into
microsoft:mainfrom
Yogeshp-MSFT:python/foundry-and-observability-support

Conversation

@Yogeshp-MSFT

Copy link
Copy Markdown

What was changed

main.py

  • Auto-detect Azure OpenAI vs Foundry endpoints. Parses AZURE_OPENAI_ENDPOINT, strips any path the user pasted from the Foundry portal (e.g. /api/projects/<name>/openai/v1/responses), and selects the right OpenAI client:
    • *.services.ai.azure.com / *.cognitiveservices.azure.comAsyncOpenAI with base_url=<host>/openai/v1 and api-key header (no api-version query, which the /openai/v1 path rejects).
    • *.openai.azure.comAsyncAzureOpenAI with azure_endpoint and api-version (existing behavior).
  • Wire up ENABLE_A365_OBSERVABILITY and ENABLE_A365_OBSERVABILITY_EXPORTER as the README documents. Previously the code silently ignored both flags. ENABLE_A365_OBSERVABILITY=false now skips use_microsoft_opentelemetry() entirely; ENABLE_A365_OBSERVABILITY_EXPORTER=false produces spans on the console but does not upload them.
  • Accept canonical AGENT365OBSERVABILITY__* env-var names (what a365 setup all writes to .env) with fallback to the legacy AGENT365_* aliases.
  • Add AZURE_OPENAI_API_VERSION env var (default 2024-10-21) so users on classic Azure OpenAI can pin to a specific GA/preview version. Foundry endpoints ignore it.

.env.template and README.md

  • Document Foundry endpoint support.
  • List both canonical (AGENT365OBSERVABILITY__*) and legacy (AGENT365_*) env-var names side-by-side.
  • Document AZURE_OPENAI_API_VERSION and the runtime semantics of both observability flags.

Why

  1. Foundry / AI Services endpoints are the recommended path for new Microsoft AI projects, but the upstream sample only worked with classic *.openai.azure.com resources. With a Foundry endpoint, chat.completions.create() failed with 400 BadRequest — api-version query parameter is not allowed when using /v1 path.
  2. The README documented ENABLE_A365_OBSERVABILITY[_EXPORTER] as required, but the code wasn't actually reading them — runtime behavior didn't match the docs.
  3. a365 setup all (CLI v1.1.206+) auto-stamps .env with AGENT365OBSERVABILITY__* keys, but the upstream code only read the legacy AGENT365_* names. Users following the recommended CLI path got "credentials not configured" warnings even with a fully-stamped .env.

Validation

End-to-end runs against a Foundry account with a fresh Agent 365 identity:

Check Result
python main.py startup Observability configured (a365_exporter=true, credentials_present=true)
chat.completions against Foundry endpoint ✅ HTTP 200 OK
Tool-call loop (get_trending_repositories) ✅ GitHub Search returned 10 repos; LLM produced markdown digest
3-hop FMI token chain Observability token registered (initial + 50-min refresh)
A365 span tree invoke_agentChat gpt-4oexecute_tool with matching traceId
A365 backend export ✅ Spans uploaded successfully
ENABLE_A365_OBSERVABILITY_EXPORTER=false toggle ✅ Falls back to console exporter
Legacy AGENT365_* env-var names ✅ Still accepted via fallback
HTTP /api/health and / ✅ 200
Heartbeat (60 s) and SIGINT shutdown ✅ Both working

@Yogeshp-MSFT Yogeshp-MSFT requested a review from a team as a code owner June 17, 2026 07:45
Copilot AI review requested due to automatic review settings June 17, 2026 07:45

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for Azure AI Foundry/OpenAI-compatible endpoints and makes Agent 365 observability configuration more flexible via canonical env vars and feature flags.

Changes:

  • Add Foundry vs classic Azure OpenAI client selection based on endpoint domain, and strip pasted portal paths.
  • Introduce AZURE_OPENAI_API_VERSION config for classic Azure OpenAI while avoiding api-version for Foundry /openai/v1.
  • Add canonical AGENT365OBSERVABILITY__* env var support plus observability/exporter feature flags and improved logging.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
python/autonomous/github-trending/main.py Adds endpoint parsing and client selection (Foundry vs classic) and refactors observability setup with feature flags + canonical env vars.
python/autonomous/github-trending/README.md Documents the new endpoint compatibility, API version behavior, canonical env vars, and observability flags.
python/autonomous/github-trending/.env.template Updates template to include AZURE_OPENAI_API_VERSION, canonical A365 keys, and revised observability flag comments.

Comment thread python/autonomous/github-trending/main.py
Comment thread python/autonomous/github-trending/main.py
Comment thread python/autonomous/github-trending/.env.template Outdated
…bservability flags

* Auto-detect Azure OpenAI vs Foundry endpoints in main.py:
  - services.ai.azure.com / cognitiveservices.azure.com -> AsyncOpenAI
    with base_url=<host>/openai/v1 and api-key header (no api-version)
  - openai.azure.com -> AsyncAzureOpenAI with api_version (existing)
  - Strips paths users may paste from the Foundry portal (e.g.
    /api/projects/<name>/openai/v1/responses) so any shape works.

* Wire ENABLE_A365_OBSERVABILITY and ENABLE_A365_OBSERVABILITY_EXPORTER
  flags as the README documents. Previously the code ignored both,
  so docs and runtime behavior diverged.

* Accept canonical AGENT365OBSERVABILITY__* env-var names (what
  `a365 setup all` writes to .env on CLI v1.1.206+) with fallback
  to legacy AGENT365_* aliases for backward compatibility.

* Add AZURE_OPENAI_API_VERSION env var (default 2024-10-21) so users
  on classic Azure OpenAI can pin a specific version. Foundry ignores
  this value.

* Update README configuration table and Quick-Start to document
  Foundry support, both env-var conventions side-by-side, and
  observability flag semantics.

Validation: end-to-end run against a Foundry account with a fresh
Agent 365 identity. chat.completions returned 200 OK, full A365
span tree (invoke_agent -> Chat -> execute_tool) generated and
exported to the A365 backend; HTTP /api/health and / endpoints,
heartbeat, and graceful shutdown all verified.
@Yogeshp-MSFT Yogeshp-MSFT force-pushed the python/foundry-and-observability-support branch from 700448a to a2684fe Compare June 17, 2026 08:56
Three small fixes from the Copilot AI review on PR microsoft#322:

1. Validate AZURE_OPENAI_ENDPOINT scheme + host
   - urlparse() silently produces empty scheme/netloc on input like
     "your-resource.openai.azure.com" (no https://), which would cascade
     into a malformed resource_endpoint such as "://".
   - Add an explicit check after urlparse() and raise SystemExit with a
     clear example URL so the failure mode is obvious.

2. Stop sending two conflicting auth headers to Foundry endpoints
   - The previous Foundry branch passed api_key=AZURE_OPENAI_API_KEY (which
     the OpenAI SDK turns into Authorization: Bearer ...) AND
     default_headers={"api-key": AZURE_OPENAI_API_KEY}, sending both
     headers on every request.
   - Foundry's /openai/v1 path expects the api-key header, so keep
     default_headers and pass a placeholder string for api_key (the SDK
     requires it to be set; Foundry ignores the placeholder Bearer token).

3. Drop the dead apiVersion=="preview" detection branch
   - The ^preview$ sentinel never matched documented values like
     2024-08-01-preview and was never triggered in practice. Host detection
     alone is sufficient.

4. Align .env.template default with the README
   - README documents ENABLE_A365_OBSERVABILITY_EXPORTER default as false.
   - Template was set to true, which would silently start uploading traces
     when a user copies the template and fills in credentials.
   - Flip template default to false; users explicitly opt in by changing it.

No functional change for users on classic Azure OpenAI endpoints.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants