Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions IMPLEMENTATION_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -351,45 +351,39 @@ 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
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
- `deployment.modelName` set to the Foundry deployment name from the final
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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 4 additions & 5 deletions infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
23 changes: 9 additions & 14 deletions infra/ai-gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,23 +92,20 @@ cat > /tmp/ai-gateway.parameters.json <<EOF
"armName": "gpt-latest",
"modelName": "gpt-6.1-sol",
"modelVersion": "2026-09-29",
"apiFormat": "OpenAIChatCompletions",
"supportedEndpoints": ["/openai/v1/chat/completions", "/openai/v1/responses"],
"resourceId": "$FOUNDRY_ACCOUNT_ID/deployments/gpt-latest"
},
{
"armName": "gpt-6-sol",
"modelName": "gpt-6-sol",
"modelVersion": "2026-09-22",
"apiFormat": "OpenAIChatCompletions",
"supportedEndpoints": ["/openai/v1/chat/completions", "/openai/v1/responses"],
"resourceId": "$FOUNDRY_ACCOUNT_ID/deployments/gpt-6-sol"
},
{
"armName": "gpt-mini-latest",
"modelName": "gpt-5.4-mini",
"modelVersion": "2026-03-17",
"apiFormat": "OpenAIChatCompletions",
"supportedEndpoints": ["/openai/v1/chat/completions", "/openai/v1/responses"],
"resourceId": "$FOUNDRY_ACCOUNT_ID/deployments/gpt-mini-latest"
}
Expand Down Expand Up @@ -162,7 +158,7 @@ project and has `metadata.type: custom_MCP`.
If `useManagedIdentityForFoundryConnections` is set to `false`, the connection
falls back to `CustomKeys` using
`runtimeApiKey.listSecrets().?primaryKey ?? runtimeApiKey.listSecrets().?key`
(the live `2025-09-01-preview` `listSecrets` payload returns `primaryKey` and
(the live `2026-11-01` `listSecrets` payload returns `primaryKey` and
`secondaryKey`) passed only through the connection module's `@secure()`
`gatewayApiKey` parameter. No deployment output contains the secret. Stable
names and incremental deployment keep repeat provisioning idempotent.
Expand All @@ -185,14 +181,13 @@ Application Insights has created its managed DCR/DCE and OTLP endpoints:
blocks creating this nested role assignment from ARM/Bicep.
4. Create
`Microsoft.ApiManagement/aigateways/{gatewayName}/workspaces/default/telemetryExporters/applicationInsights`
as `kind: OpenTelemetry`, using the Application Insights resource ID, the
metrics/logs/traces OTLP endpoints, and `openTelemetry.credentials.managedIdentity`
as `telemetryExporterType: OpenTelemetry`, using the metrics/logs/traces OTLP
endpoint objects (`{ url: ... }`) and `authentication.managedIdentity`
audience `https://monitor.azure.com`.

Exporter `kind` is immutable. The hook deletes an existing exporter with a
different kind before recreating it as OpenTelemetry. The preview service can
omit `tracesEndpoint` from exporter GET responses; metrics and logs are enough
for the portal dashboard eligibility check.
Exporter `telemetryExporterType` is immutable. The hook deletes an existing
exporter with a different type before recreating it as OpenTelemetry. Metrics
and logs are enough for the portal dashboard eligibility check.

## Postprovision configuration

Expand Down
47 changes: 24 additions & 23 deletions infra/ai-gateway/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ param allowedCallerCidrRanges array = []
@secure()
param toolServerConfigs object = {}

var aiGatewayApiVersion = '2025-09-01-preview'
var aiGatewayApiVersion = '2026-11-01'
var appInsightsApiVersion = '2020-02-02'
var logAnalyticsApiVersion = '2023-09-01'
var telemetryWorkspaceName = 'default'
Expand All @@ -48,7 +48,7 @@ var optionalIpFilterPolicies = empty(allowedCallerCidrRanges)
}
]
#disable-next-line BCP081
resource aiGateway 'Microsoft.ApiManagement/aigateways@2025-09-01-preview' = if (deployApimGatewayViaBicep) {
resource aiGateway 'Microsoft.ApiManagement/aigateways@2026-11-01' = if (deployApimGatewayViaBicep) {
name: gatewayName
location: gatewayLocation
tags: tags
Expand All @@ -70,7 +70,7 @@ resource aiGateway 'Microsoft.ApiManagement/aigateways@2025-09-01-preview' = if
}

#disable-next-line BCP081
resource defaultWorkspace 'Microsoft.ApiManagement/aigateways/workspaces@2025-09-01-preview' existing = if (deployApimGatewayViaBicep) {
resource defaultWorkspace 'Microsoft.ApiManagement/aigateways/workspaces@2026-11-01' existing = if (deployApimGatewayViaBicep) {
parent: aiGateway
name: telemetryWorkspaceName
}
Expand Down Expand Up @@ -114,37 +114,37 @@ resource gatewayAppInsights 'Microsoft.Insights/components@2020-02-02' = if (ena
}

#disable-next-line BCP081
resource foundryProvider 'Microsoft.ApiManagement/aigateways/workspaces/modelProviders@2025-09-01-preview' = if (deployFoundryProvider && deployApimGatewayViaBicep) {
resource foundryProvider 'Microsoft.ApiManagement/aigateways/workspaces/modelProviders@2026-11-01' = if (deployFoundryProvider && deployApimGatewayViaBicep) {
parent: defaultWorkspace
name: foundryProviderName
dependsOn: [
foundryUserRoleAssignments
]
properties: {
kind: 'Foundry'
modelProviderType: 'Foundry'
displayName: foundryProviderDisplayName
description: empty(foundryProviderDescription) ? null : foundryProviderDescription
foundry: {
endpoint: normalizedFoundryEndpoint
endpoint: {
url: normalizedFoundryEndpoint
}
resourceIds: foundryResourceIds
authentication: {
kind: 'ManagedIdentity'
managedIdentity: {
resource: foundryManagedIdentityResource
}
}
authentication: {
managedIdentity: {
resource: foundryManagedIdentityResource
}
}
}
}

#disable-next-line BCP081
resource foundryCatalogModels 'Microsoft.ApiManagement/aigateways/workspaces/modelProviders/models@2025-09-01-preview' = [for model in foundryModels: if (deployFoundryProvider && deployApimGatewayViaBicep) {
resource foundryCatalogModels 'Microsoft.ApiManagement/aigateways/workspaces/modelProviders/models@2026-11-01' = [for model in foundryModels: if (deployFoundryProvider && deployApimGatewayViaBicep) {
parent: foundryProvider
name: model.armName
properties: {
description: model.?description ?? null
displayName: model.modelName
apiFormat: model.apiFormat
supportedEndpoints: model.supportedEndpoints
deployment: {
resourceId: model.resourceId
Expand All @@ -170,21 +170,22 @@ resource foundryCatalogModels 'Microsoft.ApiManagement/aigateways/workspaces/mod
'identity'
]
}
{
type: 'contentSafety'
hateSeverity: model.?contentSafetySeverity ?? 'Medium'
selfHarmSeverity: model.?contentSafetySeverity ?? 'Medium'
sexualSeverity: model.?contentSafetySeverity ?? 'Medium'
violenceSeverity: model.?contentSafetySeverity ?? 'Medium'
}
// Temporarily disabled pending 2026-11-01 Content Safety API alignment
// {
// type: 'contentSafety'
// hateSeverity: model.?contentSafetySeverity ?? 'Medium'
// selfHarmSeverity: model.?contentSafetySeverity ?? 'Medium'
// sexualSeverity: model.?contentSafetySeverity ?? 'Medium'
// violenceSeverity: model.?contentSafetySeverity ?? 'Medium'
// }
],
optionalIpFilterPolicies
)
}
}]

#disable-next-line BCP081
resource modelAliases 'Microsoft.ApiManagement/aigateways/workspaces/aliases@2025-09-01-preview' = [for alias in modelAliasesConfig: if (deployFoundryProvider && deployApimGatewayViaBicep) {
resource modelAliases 'Microsoft.ApiManagement/aigateways/workspaces/aliases@2026-11-01' = [for alias in modelAliasesConfig: if (deployFoundryProvider && deployApimGatewayViaBicep) {
parent: defaultWorkspace
name: alias.armName
dependsOn: [
Expand All @@ -208,14 +209,14 @@ resource modelAliases 'Microsoft.ApiManagement/aigateways/workspaces/aliases@202
}]

#disable-next-line BCP081
resource toolServers 'Microsoft.ApiManagement/aigateways/workspaces/toolServers@2025-09-01-preview' = [for config in items(toolServerConfigs): if (deployApimGatewayViaBicep) {
resource toolServers 'Microsoft.ApiManagement/aigateways/workspaces/toolServers@2026-11-01' = [for config in items(toolServerConfigs): if (deployApimGatewayViaBicep) {
parent: defaultWorkspace
name: config.key
properties: config.value
}]

#disable-next-line BCP081
resource runtimeApiKey 'Microsoft.ApiManagement/aigateways/apiKeys@2025-09-01-preview' = if (deployApimGatewayViaBicep) {
resource runtimeApiKey 'Microsoft.ApiManagement/aigateways/apiKeys@2026-11-01' = if (deployApimGatewayViaBicep) {
parent: aiGateway
name: 'default'
properties: {
Expand Down
Loading
Loading