diff --git a/IMPLEMENTATION_NOTES.md b/IMPLEMENTATION_NOTES.md index 89dffba..0ea7690 100644 --- a/IMPLEMENTATION_NOTES.md +++ b/IMPLEMENTATION_NOTES.md @@ -87,7 +87,7 @@ AI Gateway also injects: - `X-MCP-Readonly: true` - `X-MCP-Tools: list_pull_requests,list_issues,actions_list` -- `failureMode: failClosed` +- `mode: failClosed` Tool Search is not enabled. The agent has only three known tools and calls all three in one parallel tool round, so discovery would add latency without @@ -277,7 +277,7 @@ Foundry User role assignment on the model account. The public Azure role-definition ID used by the template is `53ca6127-db72-4b80-b1b0-d745d6d5456d`. -The AI Gateway module uses the live `2025-09-01-preview` contracts: +The AI Gateway module uses the `2026-11-01` ARM contracts: - `Microsoft.ApiManagement/aigateways` with SKU `Premium` - `Microsoft.ApiManagement/aigateways/workspaces` @@ -311,7 +311,7 @@ connection. When `useManagedIdentityForFoundryConnections: false` is explicitly opted into, the connection falls back to `CustomKeys` using `runtimeApiKey.listSecrets().?primaryKey ?? runtimeApiKey.listSecrets().?key` at -`2025-09-01-preview` (the live ARM `listSecrets` response returns `primaryKey` +`2026-11-01` (the live ARM `listSecrets` response returns `primaryKey` and `secondaryKey`). The value crosses the module boundary only through an `@secure()` parameter (`securestring` in ARM), never an output. Do not log resolved deployment parameters or run the hooks with shell tracing/debug @@ -351,13 +351,12 @@ the `azd` postprovision hook. The generated managed resource group has a deny assignment that blocks creating this nested role assignment through ARM/Bicep. The hook then configures `Microsoft.ApiManagement/aigateways/{gatewayName}/workspaces/default/telemetryExporters/applicationInsights` -as `kind: OpenTelemetry`, with the Application Insights resource ID, OTLP signal -endpoints, and `openTelemetry.credentials.managedIdentity` audience -`https://monitor.azure.com`. Metrics -and logs are sufficient for portal dashboard eligibility; the preview service -may omit a supplied `tracesEndpoint` from exporter GET responses. +as `telemetryExporterType: OpenTelemetry`, with OTLP signal endpoint objects +(`{ url: ... }`) and `authentication.managedIdentity` audience +`https://monitor.azure.com`. Metrics and logs are sufficient for portal +dashboard eligibility. -Exporter `kind` is immutable. When replacing an existing legacy +Exporter `telemetryExporterType` is immutable. When replacing an existing legacy `applicationInsights` exporter, the hook deletes it before creating the native OpenTelemetry exporter. Do not restore an inline Bicep exporter: its endpoints and DCR-scoped authorization are only available after Application Insights has @@ -365,15 +364,13 @@ provisioned its managed resources. The Foundry model provider uses: -- `kind: Foundry` -- The model account endpoint returned by Azure -- Foundry account and deployment resource IDs -- `authentication.kind: ManagedIdentity` -- Token resource `https://cognitiveservices.azure.com/` +- `modelProviderType: Foundry` +- `foundry.endpoint.url` set to the model account endpoint returned by Azure +- Foundry account resource IDs in `foundry.resourceIds` +- `authentication.managedIdentity` with token resource `https://cognitiveservices.azure.com/` Each model registration includes: -- `apiFormat: OpenAIChatCompletions` - `/openai/v1/chat/completions` - `/openai/v1/responses` - The live `displayName` wire property @@ -381,15 +378,12 @@ Each model registration includes: segment of the deployment resource ID Each catalog model has a per-minute `tokenLimit` policy keyed by `identity`, -scaled to 1,000 times its Foundry deployment capacity, a `costLimit` budget of -`$10.00` per month keyed by caller `identity` (`id: monthly-caller-budget`), -and a `contentSafety` policy with `Medium` thresholds for Hate, Self-Harm, -Sexual, and Violence. With the default deployment capacities, `gpt-latest` and -`gpt-6-sol` allow 20,000 tokens per minute per caller identity, while -`gpt-mini-latest` allows 200,000. The GitHub MCP ToolServer also has a -`contentSafety` policy with `Medium` thresholds for Hate, Self-Harm, Sexual, -and Violence; the -postprovision credential PUT preserves that policy. The alias `gpt-latest` +scaled to 1,000 times its Foundry deployment capacity, and a `costLimit` budget +of `$10.00` per month keyed by caller `identity` (`id: monthly-caller-budget`). +With the default deployment capacities, `gpt-latest` and `gpt-6-sol` allow +20,000 tokens per minute per caller identity, while `gpt-mini-latest` allows +200,000. Gateway `contentSafety` policy wiring is temporarily disabled pending +`2026-11-01` Content Safety API alignment. The alias `gpt-latest` routes through a three-tier failover chain: `gpt-6.1-sol` at priority 0, `gpt-6-sol` at priority 1, and `gpt-5.4-mini` at priority 2. Each backend explicitly sets a weight of 100; aliases can instead place multiple diff --git a/README.md b/README.md index aace668..aafef3e 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ The default is `microsoft/agent-framework`. The included scheduled routine keeps **Start with [`repo_digest_agent.py`](repo_digest_agent.py).** It connects the Agent Framework agent directly to the AI Gateway model route and uses Foundry Toolbox for the AI Gateway GitHub MCP route. [`github_mcp_middleware.py`](github_mcp_middleware.py) keeps GitHub results bounded, and [`main.py`](main.py) hosts the agent in Foundry. -- **Hub (`infra/ai-gateway/`)**: Standalone AI Gateway (`Microsoft.ApiManagement/aigateways`) that enforces `tokenLimit` on each model at 20,000 tokens/minute per caller identity for `gpt-latest` and `gpt-6-sol`, and 200,000 for `gpt-mini-latest`; a `$10.00/month` per-caller `costLimit` (`monthly-caller-budget`) on every model; and `Medium` `contentSafety` thresholds for Hate, Self-Harm, Sexual, and Violence on all models and `toolServers/github`. The `gpt-latest` alias fails over from `gpt-6.1-sol` (priority 0) to `gpt-6-sol` (priority 1) to `gpt-5.4-mini` (priority 2). Only AI Gateway's managed identity receives cross-resource runtime access to the model account through the configured Foundry User RBAC assignment. Only AI Gateway holds the GitHub MCP token. +- **Hub (`infra/ai-gateway/`)**: Standalone AI Gateway (`Microsoft.ApiManagement/aigateways`) that enforces `tokenLimit` on each model at 20,000 tokens/minute per caller identity for `gpt-latest` and `gpt-6-sol`, and 200,000 for `gpt-mini-latest`, plus a `$10.00/month` per-caller `costLimit` (`monthly-caller-budget`) on every model. The `gpt-latest` alias fails over from `gpt-6.1-sol` (priority 0) to `gpt-6-sol` (priority 1) to `gpt-5.4-mini` (priority 2). Only AI Gateway's managed identity receives cross-resource runtime access to the model account through the configured Foundry User RBAC assignment. Only AI Gateway holds the GitHub MCP token. - **Agent Spoke (`infra/foundry-agents/`)**: Hosts the Foundry project, ACR, Storage, and Hosted Agent runtime. Its project account has no model deployments and no RBAC assignment on the separate model account, ensuring the agent cannot bypass AI Gateway to call models or GitHub MCP directly. - **Model Spoke (`infra/foundry-models/`)**: Dedicated model-only Azure AI Services account (`allowProjectManagement: false`, `disableLocalAuth: true`) hosting `gpt-6.1-sol`, `gpt-6-sol`, and `gpt-5.4-mini`, accessible to the agent only through AI Gateway. diff --git a/infra/README.md b/infra/README.md index 2939d17..315952d 100644 --- a/infra/README.md +++ b/infra/README.md @@ -22,11 +22,10 @@ resources. By default, each model has a `tokenLimit` of 1,000 tokens per minute per unit of deployment capacity (20,000 for `gpt-latest` and `gpt-6-sol`; 200,000 for -`gpt-mini-latest`), a `$10.00/month` `costLimit` per caller identity -(`monthly-caller-budget`), and `Medium` `contentSafety` thresholds for Hate, -Self-Harm, Sexual, and Violence. The same content-safety thresholds are applied -to the `toolServers/github` MCP server. You can also pass optional -`backendSubnetResourceId` (`properties.backend.subnet.id`, delegated to +`gpt-mini-latest`) and a `$10.00/month` `costLimit` per caller identity +(`monthly-caller-budget`). Gateway `contentSafety` policy wiring is temporarily +disabled pending `2026-11-01` Content Safety API alignment. You can also pass +optional `backendSubnetResourceId` (`properties.backend.subnet.id`, delegated to `Microsoft.App/environments`) for outbound VNet integration and `allowedCallerCidrRanges` for inbound caller IP filtering (`ipFilter`). The `gpt-latest` alias fails over across `gpt-6.1-sol` (priority 0), `gpt-6-sol` diff --git a/infra/ai-gateway/README.md b/infra/ai-gateway/README.md index f63e242..c95f443 100644 --- a/infra/ai-gateway/README.md +++ b/infra/ai-gateway/README.md @@ -26,10 +26,9 @@ Each registered model receives a per-caller `tokenLimit` of 1,000 times its deployment capacity per minute. With the sample capacities, `gpt-latest` and `gpt-6-sol` allow 20,000 tokens per minute, while `gpt-mini-latest` allows 200,000. Each model also receives a `$10.00/month` `costLimit` per caller -identity (`id: monthly-caller-budget`) and `Medium` `contentSafety` thresholds -for Hate, Self-Harm, Sexual, and Violence. The postprovision configuration adds -the same `Medium` content-safety thresholds to the `toolServers/github` MCP -server. You can optionally pass `allowedCallerCidrRanges` (for example +identity (`id: monthly-caller-budget`). Gateway `contentSafety` policy wiring +is temporarily disabled pending `2026-11-01` Content Safety API alignment. You +can optionally pass `allowedCallerCidrRanges` (for example `['10.0.0.0/8']`) to add an inline `ipFilter` policy (`action: Allow`) to each model registration, and `backendSubnetResourceId` (pointing to a subnet in the same subscription and region delegated to `Microsoft.App/environments`) to @@ -93,7 +92,6 @@ cat > /tmp/ai-gateway.parameters.json < /tmp/ai-gateway.parameters.json < /tmp/ai-gateway.parameters.json <$null) + $exporterType = [string](az rest --method get --uri $exporterUri --query properties.telemetryExporterType -o tsv 2>$null) } catch { $exporterExists = $false - $exporterKind = "" + $exporterType = "" } - if ($exporterExists -and $exporterKind -ne "OpenTelemetry") { - Write-Host "Replacing the legacy Application Insights exporter because exporter kind is immutable." + if ($exporterExists -and $exporterType -ne "OpenTelemetry") { + Write-Host "Replacing the legacy Application Insights exporter because exporter type is immutable." az rest --method delete --uri $exporterUri -o none $exporterDeleted = $false for ($attempt = 1; $attempt -le 30; $attempt++) { @@ -225,19 +225,22 @@ function Configure-GatewayMonitoring($MonitoringEnabled, $GatewayResourceId, $Su $exporterBody = @{ properties = @{ - kind = "OpenTelemetry" + telemetryExporterType = "OpenTelemetry" payloadCapture = $false - applicationInsights = @{ - resourceId = $gatewayAppInsightsId - } openTelemetry = @{ - metricsEndpoint = $metricsEndpoint - logsEndpoint = $logsEndpoint - tracesEndpoint = $tracesEndpoint - credentials = @{ - managedIdentity = @{ - resource = "https://monitor.azure.com" - } + metricsEndpoint = @{ + url = $metricsEndpoint + } + logsEndpoint = @{ + url = $logsEndpoint + } + tracesEndpoint = @{ + url = $tracesEndpoint + } + } + authentication = @{ + managedIdentity = @{ + resource = "https://monitor.azure.com" } } } @@ -390,8 +393,8 @@ if (-not $workspaceChildrenReady) { } $providerUri = "https://management.azure.com${workspaceResourceId}/modelProviders/foundry?api-version=$aiGatewayApiVersion" -$providerAuth = [string](az rest --method get --uri $providerUri --query properties.foundry.authentication.kind -o tsv) -if ($providerAuth -ne "ManagedIdentity") { +$providerAuth = [string](az rest --method get --uri $providerUri --query properties.authentication.managedIdentity.resource -o tsv) +if ($providerAuth -ne "https://cognitiveservices.azure.com/") { throw "Bicep did not configure the Foundry provider for managed identity." } @@ -447,34 +450,38 @@ if ($githubToken.StartsWith("Bearer ", [StringComparison]::OrdinalIgnoreCase)) { $toolServerUri = "https://management.azure.com${workspaceResourceId}/toolServers/github?api-version=$aiGatewayApiVersion" $toolServerBody = @{ properties = @{ + toolServerType = "mcp" displayName = "GitHub repository digest" description = "Read-only GitHub tools for repository digests." - type = "mcp" - failureMode = "failClosed" - policies = @( - @{ - type = "contentSafety" - hateSeverity = "Medium" - selfHarmSeverity = "Medium" - sexualSeverity = "Medium" - violenceSeverity = "Medium" - } - ) + blockList = @() + # Temporarily disabled contentSafety policy pending 2026-11-01 Content Safety API alignment + policies = @() endpoints = @( @{ namespace = "github" kind = "mcp" + mode = "failClosed" mcp = @{ - url = $githubMcpServer + endpoint = @{ + url = $githubMcpServer + } transport = "streamableHttp" } - credentials = @{ - type = "header" - headers = @{ - Authorization = @($githubAuthorization) - "X-MCP-Readonly" = @("true") - "X-MCP-Tools" = @($githubMcpTools) - } + authentication = @{ + headers = @( + @{ + name = "Authorization" + value = $githubAuthorization + }, + @{ + name = "X-MCP-Readonly" + value = "true" + }, + @{ + name = "X-MCP-Tools" + value = $githubMcpTools + } + ) } } ) diff --git a/infra/scripts/configure-ai-gateway.sh b/infra/scripts/configure-ai-gateway.sh index 8ea95d2..3dfc812 100755 --- a/infra/scripts/configure-ai-gateway.sh +++ b/infra/scripts/configure-ai-gateway.sh @@ -2,7 +2,7 @@ set -euo pipefail umask 077 -AI_GATEWAY_API_VERSION="2025-09-01-preview" +AI_GATEWAY_API_VERSION="2026-11-01" LEGACY_AI_GATEWAY_API_VERSION="2025-09-01-preview" FOUNDRY_USER_ROLE_ID="53ca6127-db72-4b80-b1b0-d745d6d5456d" MONITORING_METRICS_PUBLISHER_ROLE_ID="3913510d-42f4-4e42-8a64-420c390055eb" @@ -231,7 +231,7 @@ configure_gateway_monitoring() { local role_definition_id local role_assignment_body local exporter_uri - local exporter_kind + local exporter_type local exporter_body local provider_state @@ -295,9 +295,9 @@ configure_gateway_monitoring() { -o none exporter_uri="https://management.azure.com${gateway_resource_id}/workspaces/default/telemetryExporters/applicationInsights?api-version=${AI_GATEWAY_API_VERSION}" - if exporter_kind="$(az rest --method get --uri "$exporter_uri" --query properties.kind -o tsv 2>/dev/null)" && - [ "$exporter_kind" != "OpenTelemetry" ]; then - echo "Replacing the legacy Application Insights exporter because exporter kind is immutable." + if exporter_type="$(az rest --method get --uri "$exporter_uri" --query properties.telemetryExporterType -o tsv 2>/dev/null)" && + [ "$exporter_type" != "OpenTelemetry" ]; then + echo "Replacing the legacy Application Insights exporter because exporter type is immutable." az rest --method delete --uri "$exporter_uri" -o none exporter_deleted=false for attempt in $(seq 1 30); do @@ -314,7 +314,7 @@ configure_gateway_monitoring() { fi fi - exporter_body="{\"properties\":{\"kind\":\"OpenTelemetry\",\"payloadCapture\":false,\"applicationInsights\":{\"resourceId\":\"$(json_escape "$gateway_app_insights_id")\"},\"openTelemetry\":{\"metricsEndpoint\":\"$(json_escape "$metrics_endpoint")\",\"logsEndpoint\":\"$(json_escape "$logs_endpoint")\",\"tracesEndpoint\":\"$(json_escape "$traces_endpoint")\",\"credentials\":{\"managedIdentity\":{\"resource\":\"https://monitor.azure.com\"}}}}}" + exporter_body="{\"properties\":{\"telemetryExporterType\":\"OpenTelemetry\",\"payloadCapture\":false,\"openTelemetry\":{\"metricsEndpoint\":{\"url\":\"$(json_escape "$metrics_endpoint")\"},\"logsEndpoint\":{\"url\":\"$(json_escape "$logs_endpoint")\"},\"tracesEndpoint\":{\"url\":\"$(json_escape "$traces_endpoint")\"}},\"authentication\":{\"managedIdentity\":{\"resource\":\"https://monitor.azure.com\"}}}}" echo "Configuring the native OpenTelemetry exporter for AI Gateway." az rest --method put --uri "$exporter_uri" --body "$exporter_body" -o none } @@ -480,9 +480,9 @@ fi provider_auth="$(az rest \ --method get \ --uri "https://management.azure.com${workspace_resource_id}/modelProviders/foundry?api-version=${AI_GATEWAY_API_VERSION}" \ - --query properties.foundry.authentication.kind \ + --query properties.authentication.managedIdentity.resource \ -o tsv)" -if [ "$provider_auth" != "ManagedIdentity" ]; then +if [ "$provider_auth" != "https://cognitiveservices.azure.com/" ]; then echo "Bicep did not configure the Foundry provider for managed identity." >&2 exit 1 fi @@ -511,35 +511,41 @@ case "$github_token" in *) github_authorization="Bearer $github_token" ;; esac +# Temporarily omit contentSafety policy pending 2026-11-01 Content Safety API alignment tool_server_body="$(mktemp)" cat > "$tool_server_body" <&2 + echo "Gateway model PUTs must include identity-keyed token and cost limits." >&2 echo "Missing: $policy_token" >&2 echo "Actual: $actual_model_policies" >&2 exit 1 fi done +if grep -Fq "contentSafety" <<< "$actual_model_policies"; then + echo "Gateway model PUTs must omit contentSafety pending 2026-11-01 Content Safety API alignment." >&2 + echo "Actual: $actual_model_policies" >&2 + exit 1 +fi gateway_sku="$(jq -r ' .resources[] @@ -64,6 +64,38 @@ if [ "$gateway_sku" != "Premium" ]; then exit 1 fi +if ! jq -e ' + [ + .resources[] + | select(.type | startswith("Microsoft.ApiManagement/aigateways")) + | select(.apiVersion != "2026-11-01") + ] | length == 0 +' "$compiled_template" >/dev/null; then + echo "All Microsoft.ApiManagement/aigateways resources must target apiVersion 2026-11-01." >&2 + exit 1 +fi + +if ! jq -e ' + .resources[] + | select(.type == "Microsoft.ApiManagement/aigateways/workspaces/modelProviders") + | .properties.modelProviderType == "Foundry" + and (.properties | has("kind") | not) + and (.properties.foundry.endpoint.url != null) + and (.properties.authentication.managedIdentity.resource != null) +' "$compiled_template" >/dev/null; then + echo "Foundry modelProvider must use 2026-11-01 modelProviderType, endpoint.url, and top-level authentication." >&2 + exit 1 +fi + +if ! jq -e ' + .resources[] + | select(.type == "Microsoft.ApiManagement/aigateways/workspaces/modelProviders/models") + | (.properties | has("apiFormat") | not) +' "$compiled_template" >/dev/null; then + echo "2026-11-01 model registrations must omit apiFormat." >&2 + exit 1 +fi + monitoring_ingestion_mode="$(jq -r ' .resources[] | select(.type == "Microsoft.Insights/components") @@ -181,19 +213,22 @@ root_model_input="$(jq -r ' | select(. != null) ' "$compiled_root_template")" for token in \ - "OpenAIChatCompletions" \ "/openai/v1/chat/completions" \ "/openai/v1/responses" \ "mul(variables('gatewayModelDeployments')[copyIndex('value')].capacity, 1000)" \ - "'costLimit', 10" \ - "'contentSafetySeverity', 'Medium'"; do + "'costLimit', 10"; do if ! grep -Fq "$token" <<< "$root_model_input"; then - echo "Root model registrations must use the live RP API, capacity-scaled token limits, and Medium content safety." >&2 + echo "Root model registrations must use the live RP API and capacity-scaled token and cost limits." >&2 echo "Missing: $token" >&2 echo "Actual: $root_model_input" >&2 exit 1 fi done +if grep -Fq "apiFormat" <<< "$root_model_input"; then + echo "Root model registrations must omit apiFormat on 2026-11-01." >&2 + echo "Actual: $root_model_input" >&2 + exit 1 +fi mini_capacity="$(jq -r '.parameters.miniModelCapacity.defaultValue' "$compiled_root_template")" if [ "$mini_capacity" != "200" ]; then @@ -213,7 +248,7 @@ if ! jq -e ' and ($module.properties.mode == "Incremental") and ($module.condition | contains("deployApimGatewayViaBicep") and contains("foundryAgentsProjectName")) and ($template.parameters.gatewayApiKey.type == "securestring") - and ($key | contains("listSecrets(resourceId('\''Microsoft.ApiManagement/aigateways/apiKeys'\'', parameters('\''gatewayName'\''), '\''default'\''), '\''2025-09-01-preview'\'')") and contains("primaryKey")) + and ($key | contains("listSecrets(resourceId('\''Microsoft.ApiManagement/aigateways/apiKeys'\'', parameters('\''gatewayName'\''), '\''default'\''), '\''2026-11-01'\'')") and contains("primaryKey")) and ($module.dependsOn | any(contains("Microsoft.ApiManagement/aigateways/apiKeys"))) and ($module.dependsOn | any(contains("aiGatewayUserRoleDefinitionId"))) and ($template.resources | length == 1) @@ -291,7 +326,8 @@ for hook in "$repo_root/infra/scripts/configure-ai-gateway.sh" "$repo_root/infra 'TracesIngestionEndpoint' \ '3913510d-42f4-4e42-8a64-420c390055eb' \ 'OpenTelemetry' \ - 'credentials' \ + 'telemetryExporterType' \ + 'authentication' \ 'managedIdentity' \ 'https://monitor.azure.com' \ 'workspaces/default/telemetryExporters/applicationInsights'; do diff --git a/tests/test-apim-lifecycle.sh b/tests/test-apim-lifecycle.sh index 8b7963a..383a9a1 100755 --- a/tests/test-apim-lifecycle.sh +++ b/tests/test-apim-lifecycle.sh @@ -387,7 +387,7 @@ assert_contains "$error_file" "run 'azd down'" assert_contains "$marker_file" "state=pending" for token in \ - "2025-09-01-preview" \ + "2026-11-01" \ "Microsoft.ApiManagement/aigateways" \ "Premium" \ "azd-env-name" \ @@ -419,16 +419,14 @@ for postprovision_script in \ assert_contains "$postprovision_script" "Microsoft.ApiManagement/service" assert_contains "$postprovision_script" "frontend.defaultHostname" assert_contains "$postprovision_script" "/default/models/openai/v1/chat/completions" - assert_contains "$postprovision_script" "contentSafety" - assert_contains "$postprovision_script" "hateSeverity" - assert_contains "$postprovision_script" "selfHarmSeverity" - assert_contains "$postprovision_script" "sexualSeverity" - assert_contains "$postprovision_script" "violenceSeverity" - assert_contains "$postprovision_script" "Medium" + assert_not_contains "$postprovision_script" "hateSeverity" + assert_not_contains "$postprovision_script" "selfHarmSeverity" + assert_not_contains "$postprovision_script" "sexualSeverity" + assert_not_contains "$postprovision_script" "violenceSeverity" done -assert_contains "$repo_root/infra/scripts/configure-ai-gateway.sh" '"policies": [{' -assert_contains "$repo_root/infra/scripts/configure-ai-gateway.ps1" 'policies = @(' +assert_contains "$repo_root/infra/scripts/configure-ai-gateway.sh" '"policies": []' +assert_contains "$repo_root/infra/scripts/configure-ai-gateway.ps1" 'policies = @()' assert_not_contains "$repo_root/infra/scripts/configure-ai-gateway.sh" "jq " assert_not_contains "$repo_root/infra/scripts/manage-ai-gateway-lifecycle.sh" "jq "