diff --git a/.devcontainer/03-azure-01-04-ai-07-fraud-intelligence/Dockerfile b/.devcontainer/03-azure-01-04-ai-07-fraud-intelligence/Dockerfile index b46f9a471..835e8842c 100644 --- a/.devcontainer/03-azure-01-04-ai-07-fraud-intelligence/Dockerfile +++ b/.devcontainer/03-azure-01-04-ai-07-fraud-intelligence/Dockerfile @@ -1,4 +1,5 @@ -FROM mcr.microsoft.com/devcontainers/python:3.12-bookworm +# Python 3.13 matches the Azure Functions runtime of the Financial Evidence MCP (azure-functions 2.x needs 3.13). +FROM mcr.microsoft.com/devcontainers/python:3.13-bookworm USER root diff --git a/.devcontainer/03-azure-01-04-ai-07-fraud-intelligence/devcontainer.json b/.devcontainer/03-azure-01-04-ai-07-fraud-intelligence/devcontainer.json index d0f9d75f5..df084064e 100644 --- a/.devcontainer/03-azure-01-04-ai-07-fraud-intelligence/devcontainer.json +++ b/.devcontainer/03-azure-01-04-ai-07-fraud-intelligence/devcontainer.json @@ -46,7 +46,10 @@ "GitHub.copilot-chat" ], "settings": { - "python.defaultInterpreterPath": "/usr/local/bin/python" + "python.defaultInterpreterPath": "/usr/local/bin/python", + "workbench.editorAssociations": { + "*.md": "vscode.markdown.preview.editor" + } } } }, diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/.devcontainer/Dockerfile b/03-Azure/01-04-AI/07_Fraud_Intelligence/.devcontainer/Dockerfile index b46f9a471..835e8842c 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/.devcontainer/Dockerfile +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/.devcontainer/Dockerfile @@ -1,4 +1,5 @@ -FROM mcr.microsoft.com/devcontainers/python:3.12-bookworm +# Python 3.13 matches the Azure Functions runtime of the Financial Evidence MCP (azure-functions 2.x needs 3.13). +FROM mcr.microsoft.com/devcontainers/python:3.13-bookworm USER root diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-02.md b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-02.md index b387abacf..f27858bb4 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-02.md +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-02.md @@ -111,6 +111,12 @@ Copy the value of the `mcp_extension` key and add it to `hackenv`: echo 'financialEvidenceMcpSystemKey=' >> hackenv ``` +Or read the key from the terminal instead of the portal: + +```bash +echo "financialEvidenceMcpSystemKey=$(az functionapp keys list -g "$rg" -n "$functionAppName" --query systemKeys.mcp_extension -o tsv)" >> hackenv +``` + Load the new environment variables into your shell: ```bash @@ -127,13 +133,13 @@ In the Azure portal, open your **Microsoft Foundry** resource and select **Go to #### Explore the Foundry project -The provided Microsoft Foundry project contains two model deployments: a chat model used by the agent and an embedding model. Find both deployments and review their details. +The provided Microsoft Foundry project contains two model deployments: a chat model used by the agent and an embedding model. Open **Models** under **Build** to find both deployments and review their details. Next, connect the Application Insights resource deployed in your environment to the Foundry project. This connection allows you to monitor agent performance and investigate issues. -Open **Manage** and select **Project details** from the left menu. Select **Connected resources**, then **Add connection**. +Open **Manage** and select **Project details** from the left menu. Select the **Connections** tab, then **Add connection**. -![Connected resources in Microsoft Foundry](./images/foundry-connected-resources.png) +![Project connections in Microsoft Foundry](./images/foundry-connected-resources.png) Select **Application Insights**, then select **Continue**. Choose the Application Insights resource deployed for your lab, leave **API key** as the authentication method, and select **Connect**. @@ -145,11 +151,9 @@ Under **Build**, open **Agents**, select **New agent**, then select **Build an a Name the agent `EvidenceEnrichmentAgent`. -The new agent opens with a blank configuration: - -![Blank agent in Microsoft Foundry](./images/foundry-blank-agent.png) +The new agent opens with a blank configuration. Its **Model** may default to `model-router`, listed under **Models**. Open the **Model** list and select `gpt-5.6-luna` under **Deployments**. This is the chat model deployed for the lab; the embedding deployment is not a chat model. -The chat model is selected automatically because it is the only deployed model that can power this agent. The embedding deployment is not a chat model. +![Select the gpt-5.6-luna deployment in Microsoft Foundry](./images/foundry-blank-agent.png) Select **Instructions** and copy the contents of `walkthrough/challenge-02/evidence-enrichment-agent/instructions.md` into the instruction editor. @@ -173,9 +177,9 @@ Configure these values: Select **Connect**. Foundry returns to the agent page and displays the new MCP tool. -Open the MCP tool's `...` menu and select **Configure**: +Open the MCP tool's `...` menu and select **Edit**: -![Configure MCP tool menu in Microsoft Foundry](./images/foundry-configure-mcp-tool-menu.png) +![Edit MCP tool menu in Microsoft Foundry](./images/foundry-configure-mcp-tool-menu.png) Then enable **Always auto-approve all tools**. diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-03.md b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-03.md index 7a05bf089..e1d4f7977 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-03.md +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-03.md @@ -52,9 +52,11 @@ After the resource is created, select **Create a knowledge base** and set the fo - **Name**: kb-aml - **Description**: Synthetic AML / CFT / KYC corpus for Fraud Intelligence -- **Chat completion model**: gpt-5-mini (or gpt-5.4-mini, new models are being added/delete to/from this configuration section) + +Then expand **Improve retrieval** and set: + +- **Chat completions model**: `gpt-5.6-luna` (the chat model deployed in your lab; it is the only one in the list) - **Retrieval reasoning effort**: Minimal -- **Output mode**: Extractive data - **Retrieval instructions**: You have to always retrieve first the global policies and rules. ![Foundry IQ Knowledge Base Creation](./images/foundry-iq-knowledge-base-creation.png) @@ -150,7 +152,7 @@ Because this is the second agent, follow the same **Microsoft Foundry** agent cr Relevant steps you should not miss include: - Define the agent's name as `RegulatoryAssessmentAgent` -- Set the model: `gpt-5.6-luna` +- Set the model: `gpt-5.6-luna` (under **Deployments**, not `model-router`) - Set instructions: find them under `walkthrough/challenge-03/regulatory-assessment-agent/instructions.md`. Review and validate content. - Remove the `Web Search` tool, irrelevant for this agent. @@ -367,7 +369,7 @@ Next, add the internal and regional policy sources. Return to **Knowledge** and select the `kb-aml` knowledge base you created. -First, modify the **Retrieval instructions** to include the internal and regional policy sources after the global policies: +First, expand **Improve retrieval** and modify the **Retrieval instructions** to include the internal and regional policy sources after the global policies: ```text You have to always retrieve first the global policies and rules, then the internal rules and policies, and finally the regional rules and policies based on the transaction's bank origin and destination. Only the ones for these countries if documentation exists. diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-04.md b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-04.md index f2ab35b7a..a6464fdbf 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-04.md +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-04.md @@ -43,7 +43,7 @@ The report must preserve source identifiers so an analyst can trace each finding This is the third agent you will build, so follow the same creation and configuration process used for the previous agents. Configure the following settings: - Define the agent's name as `AMLReportAgent` -- Set the model: `gpt-5.6-luna` +- Set the model: `gpt-5.6-luna` (under **Deployments**, not `model-router`) - Set instructions: find them under `walkthrough/challenge-04/aml-report-agent/instructions.md`. Review and validate content. - Remove the `Web Search` tool, irrelevant for this agent. @@ -803,9 +803,9 @@ The source code is in the `orchestration` directory under `challenge-04`. Review - `src/main.py`: The main entry point for the orchestration logic. That is where we will initialize and coordinate the various agents involved in the process. - `azure.yaml`: Configuration file for the agent that is required during the phase of deploying the agent as **Hosted Agent** in **Microsoft Foundry**. -Ensure that the agents are defined correctly in the `main.py` file and that their names and versions match those running in the Foundry environment. Open the **Agents** section in the portal to verify these values. +The orchestration finds each agent by name and uses its **latest** saved version, so you do not need to edit `main.py`. The names must match the agents you created: `EvidenceEnrichmentAgent`, `RegulatoryAssessmentAgent` and `AMLReportAgent`. Open the **Agents** section in the portal to check the names and versions. -Those names and versions should be set correctly in the `main.py` file: +To pin a version, or if you named an agent differently, add it to the `.env` file you create below, for example `AML_REPORT_AGENT_VERSION=3` or `AML_REPORT_AGENT_NAME=MyReportAgent`. The prefixes are `EVIDENCE_ENRICHMENT_AGENT`, `REGULATORY_ASSESSMENT_AGENT`, `AML_REPORT_AGENT` and, from Challenge 5, `ALERT_MANAGER_AGENT`. ![Agents versions](./images/agents-versions.png) @@ -912,6 +912,22 @@ Track the deployment progress in the **Output** panel in Visual Studio Code by s ![Deployment progress in Output panel](./images/deployment-progress-in-output-panel.png) +#### Allow the orchestration to call your agents + +The hosted orchestration runs with its own managed identity. Give that identity the **Foundry User** role on the Foundry account so it can read and invoke the three agents. Run this once, after the first deployment: + +```bash +agentPrincipalId=$(az rest --method get --resource https://ai.azure.com \ + --url "https://$foundryAccountName.services.ai.azure.com/api/projects/$foundryProjectName/agents/fraud-intelligence-orchestration?api-version=v1" \ + --query "versions.latest.instance_identity.principal_id" -o tsv) + +az role assignment create --assignee-object-id "$agentPrincipalId" --assignee-principal-type ServicePrincipal \ + --role "Foundry User" \ + --scope "$(az cognitiveservices account show --name $foundryAccountName --resource-group $rg --query id -o tsv)" +``` + +Wait one to two minutes for the role to take effect, then start a **new** conversation in the playground. Without the role, the playground returns `424 session_not_ready` because the orchestration cannot read the agents when it starts. + Once the deployment is complete, you can run a test using the **Hosted Agent Playground**: ![Hosted Agent Playground](./images/hosted-agent-playground.png) @@ -944,6 +960,7 @@ Add idempotent case identifiers and checkpointing so a transient failure can res ## 🛠️ Troubleshooting +- **The hosted agent returns `424 session_not_ready`:** The orchestration container failed to start. If its logs show `does not have permissions for .../agents/read`, run the role assignment in [Allow the orchestration to call your agents](#allow-the-orchestration-to-call-your-agents), wait two minutes, and start a new conversation. - **A remote agent cannot be invoked:** Verify the project endpoint, agent name and version, managed identity, and role assignments. - **A handoff fails validation:** Compare the producing agent's output with the consuming schema and inspect the raw response in the trace. - **The report changes the decision:** Ensure the report agent receives the assessment as authoritative and has no instruction to reassess it. diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-05.md b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-05.md index 2502c5912..17ac72e2e 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-05.md +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-05.md @@ -4,7 +4,7 @@ ## 🎯 Objective -Introduce the **AI Gateway tier (preview)** for MCP access, generate an MCP interface from the Fraud Alert Manager API, build an **Alert Manager Agent**, and run alert creation in parallel with report generation. +Put MCP access behind **Azure AI Gateway**, generate an MCP interface from the Fraud Alert Manager API, build an **Alert Manager Agent**, and run alert creation in parallel with report generation. ## 🧭 Context and Background @@ -18,7 +18,7 @@ flowchart LR ALERT --> AMCP[Fraud Alert Manager MCP] AMCP --> API[Fraud Alert Manager API] - ORCH[Hosted orchestration] --> GATEWAY[AI Gateway tier] + ORCH[Hosted orchestration] --> GATEWAY[Azure AI Gateway] GATEWAY --> FMCP[Financial Evidence MCP] GATEWAY --> AMCP ``` @@ -35,63 +35,51 @@ source hackenv ### 1. Deploy the AI Gateway -An **AI Gateway** is a centralized control point for securing and managing MCP traffic between AI agents and external services. It routes requests and responses through a governance layer that can enforce authentication, authorization, rate limiting, and other policies. This helps protect sensitive information, support compliance, and provide observability into AI-driven workflows. - -In Azure, API Management provides the AI Gateway. In this lab, you will deploy a dedicated API Management instance using the preview `AIGateway` SKU, then route MCP calls through this centralized governance layer. +**Azure AI Gateway** is a centralized control point for securing and managing traffic between AI agents and models or tools. It routes requests through a governance layer that can enforce authentication, rate limits and other policies, and it gives you one place to observe AI traffic. Each gateway includes 10,000 free requests per month, which is plenty for this lab. #### Create the Gateway -During the preview, you can create the `AIGateway` SKU through the **AI Gateway portal**, but not through the public Azure CLI or ARM REST API. - -Open the [AI Gateway portal](https://ai.gateway.azure.com/) and sign in with the lab account. Create a new AI Gateway with these settings: - -- **Name**: enter a globally unique name -- **Subscription**: the lab subscription -- **Region**: `swedencentral` -- **Resource group**: the existing lab resource group -- **Enable managed identity** - -![AI Gateway deployment screenshot](./images/ai-gateway-deployment.png) - -### 2. Proxy the Financial Evidence MCP - -The **AI Gateway** can proxy existing Model Context Protocol (MCP) servers. This applies access, authentication, and rate-limiting policies at the gateway without requiring changes to the MCP implementation. - -Next, onboard the existing `financial evidence` MCP to the AI Gateway. In the **AI Gateway** portal, open the **MCP servers** section and select **Add MCP server**: - -![Add MCP server in the AI Gateway portal](./images/add-mcp-server-in-ai-gateway-portal.png) +Install the `aigateway` Azure CLI extension in the Codespace terminal, then create a gateway in your lab resource group and save it as the default for the next commands. A new gateway is ready in about a minute and a half. -The portal supports three backend types: - -![Supported backend types in the AI Gateway portal](./images/supported-backend-types-in-ai-gateway-portal.png) +```bash +curl -fsSL https://aka.ms/aigateway-cli-install | bash +az aig version -Select **MCP server**, then provide the details required to connect to the existing Financial Evidence MCP: +GW="aigw-fraud-$RANDOM" +az aig create --resource-group "$rg" --name "$GW" --location swedencentral +az configure --defaults group="$rg" aigateway="$GW" +``` -- **Backend Name**: A friendly name for the MCP server, for instance, `financial-evidence-mcp`. -- **URL**: The URL of the existing `financial evidence` MCP server. Use the value returned by `echo "$financialEvidenceMcpEndpoint"` -- **Authentication**: set **API Key**, with: - - **Header Name**: `x-functions-key` - - **Value:** Use the value returned by `echo "$financialEvidenceMcpSystemKey"`. +Create a runtime API key for your agents and keep it in a variable: -Select **Next**, validate the configuration, and select **Create** to add the MCP server to the **AI Gateway**. +```bash +az aig api-key create --name lab --display-name "Lab key" --state active +gatewayApiKey=$(az aig api-key list-secrets --name lab --query primaryKey -o tsv) +gatewayHost=$(az aig show --query properties.frontend.defaultHostname -o tsv) +echo "https://$gatewayHost" +``` -You can now test the MCP from the **AI Gateway**. Select **Use**: +> **Portal alternative:** open the [AI Gateway portal](https://ai.gateway.azure.com/), sign in with the lab account and create the gateway in the lab subscription and resource group, in `swedencentral`. The portal also shows your runtime keys. -![Test the MCP from the AI Gateway](./images/test-mcp-from-ai-gateway.png) +### 2. Proxy the Financial Evidence MCP -Select the **Try it** tab, then select **List tools**. You should see all tools exposed by the Financial Evidence MCP: +The **AI Gateway** can proxy existing Model Context Protocol (MCP) servers. This applies access, authentication and rate-limiting policies at the gateway without changing the MCP implementation. -![List tools in the financial evidence MCP](./images/list-tools-in-financial-evidence-mcp.png) +Register the existing Financial Evidence MCP with the gateway. The gateway calls the Function App with its system key, so the key stays in the gateway and never reaches the agent: -Select the **Get Bank Information** operation, enter `0121` as the bank ID, and select **Run tool**: +```bash +az aig mcp create --name financial-evidence-mcp \ + --url "$financialEvidenceMcpEndpoint" \ + --credentials "{\"type\":\"header\",\"headers\":{\"x-functions-key\":[\"$financialEvidenceMcpSystemKey\"]}}" -![Run Get Bank Information tool in the financial evidence MCP](./images/run-get-bank-information-tool-in-financial-evidence-mcp.png) +az aig mcp show --name financial-evidence-mcp --query "properties.gatewayEndpoints[0].url" -o tsv +``` -The result should display information for bank ID `0121`. Expand the `data` element to view the details: +The last command prints the gateway URL of the MCP, in the form `https:///default/toolservers/financial-evidence-mcp/mcp`. Callers authenticate with the runtime key in an `api-key` header. -![View detailed bank information in the financial evidence MCP](./images/view-detailed-bank-information-in-financial-evidence-mcp.png) +You can test it in the **AI Gateway** portal: open **MCP servers**, select `financial-evidence-mcp`, then **Use** > **Try it** > **List tools**. Run **Get Bank Information** with bank ID `0121` and check that the bank details come back. -You can now interact with the Financial Evidence MCP through the **AI Gateway**. Next, configure `EvidenceEnrichmentAgent` to use it. +> The gateway prefixes each tool with the MCP server name, for example `financial-evidence-mcp_get_bank_information`. Agents still pick the right tools; the instructions do not need to change. #### Update the EvidenceEnrichmentAgent Configuration @@ -99,12 +87,12 @@ Return to the **Microsoft Foundry** portal. Under **Build**, select **Agents**, ![Remove existing tool from the EvidenceEnrichmentAgent](./images/remove-existing-tool-from-evidenceenrichmentagent.png) -Select **Save**, then open the **Tools** menu on the left side of the page. +Select **Save**, then select **Tools** in the left navigation. The page opens on **Toolboxes**; select the **Tools** tab to see the `financial-evidence-mcp` connection. Select the `financial-evidence-mcp` tool and update its URL and authentication: -- **Remote MCP Server endpoint**: Use the Financial Evidence MCP URL exposed through the **AI Gateway**. -- **Credential**: Set the header name to `api-key` and use an existing key from your **AI Gateway** configuration. +- **Remote MCP Server endpoint**: the gateway URL of `financial-evidence-mcp` from the previous step. +- **Credential**: set the header name to `api-key` and the value to the runtime key (`echo "$gatewayApiKey"`). Then select **Update**. @@ -122,42 +110,31 @@ Under the `EvidenceEnrichmentAgent` **Tools** section, verify that the `financia Test the agent and inspect its traces to verify that it uses `financial-evidence-mcp` through the **AI Gateway**. -To explore additional gateway policies, open the **Policies** section for `financial-evidence-mcp`. Because the **AI Gateway** is in preview, some MCP features, including the **Monitoring** tab, may still be unavailable. +To explore additional gateway policies, open **Policies** for `financial-evidence-mcp` in the **AI Gateway** portal, or list them with `az aig policy list`. ### 3. Generate an MCP from the Fraud Alert Manager API -The **AI Gateway** can also expose an existing API as an MCP, bringing agent integration and policy management to APIs that were not originally designed as MCP servers. - -For this scenario, the Fraud Alert Manager API manages financial alerts so that operational users can review them and take action. A simple web interface is also available for validation. +The **AI Gateway** can also expose an existing API as an MCP, bringing agent integration and policy management to APIs that were not designed as MCP servers. -First, retrieve the API endpoint so that the AI Gateway can read its OpenAPI specification. The API runs on **Azure Container Apps**: +The Fraud Alert Manager API manages financial alerts so that operational users can review them and act on them. It runs on **Azure Container Apps** and publishes an OpenAPI specification. Create an MCP server from that specification: ```bash endpoint=$(az containerapp show --name alert-manager --resource-group $rg --query properties.configuration.ingress.fqdn -o tsv) -echo "https://$endpoint/openapi.json" -``` -Copy the URL; you will use it to configure the MCP in the **AI Gateway**. - -Return to **MCP servers** in the **AI Gateway** portal. Follow the previous process using a different backend. - -Select **Add MCP server**, choose **OpenAPI Specification**, and complete the form with the following details: -- **Name**: Provide a name for the MCP server, e.g., `alert-manager-mcp`. -- **Spec source**: Select **Fetch from URL** -- **Spec URL**: Paste the URL you obtained from the previous step. -- **Authentication**: Select **None** because the lab API does not require authentication. +az aig mcp create --name alert-manager-mcp \ + --endpoints "[{\"kind\":\"openApi\",\"namespace\":\"alert-manager-mcp\",\"openApi\":{\"specSource\":{\"type\":\"url\",\"url\":\"https://$endpoint/openapi.json\"}}}]" -![Add MCP server](./images/add-mcp-server-from-api.png) - -Select **Next**, validate the configuration, and select **Create** to add the MCP server. +az aig mcp show --name alert-manager-mcp --query "properties.gatewayEndpoints[0].url" -o tsv +``` -Explore the new MCP server in the **AI Gateway** playground. For example, list the existing alerts: +The lab API needs no authentication of its own. The gateway generates one tool per API operation: `create_alert`, `list_alerts`, `get_alert`, `replace_alert`, `patch_alert`, `delete_alert` and `health`. -![List existing alerts](./images/list-existing-alerts.png) +> **Portal alternative:** in the **AI Gateway** portal open **MCP servers** > **Add MCP server**, choose **OpenAPI Specification**, select **Fetch from URL**, paste `https:///openapi.json` and set **Authentication** to **None**. +Try the new MCP server in the **AI Gateway** playground, for example by listing the existing alerts. -Next, create `AlertManagerAgent` to interact with `alert-manager-mcp` through the **AI Gateway**, then add the agent to the full orchestration. +Next, create `AlertManagerAgent` to work with `alert-manager-mcp` through the **AI Gateway**, then add the agent to the full orchestration. ### 4. Create the AlertManagerAgent @@ -166,8 +143,8 @@ This is the fourth agent in the workflow. `AlertManagerAgent` uses `alert-manage Use the following configuration: - Use the agent instructions in `walkthrough/challenge-05/alert-manager-agent/instructions.md`. -- Select the model: `gpt-5.6-luna` -- Onboard the MCP in **Microsoft Foundry** following the usual steps for MCP integration. Remember to add authentication with **API Key**, using header name `api-key` and value a valid API key provided by the **AI Gateway**. +- Select the model: `gpt-5.6-luna` (under **Deployments**, not `model-router`) +- Onboard the MCP in **Microsoft Foundry** following the usual steps for MCP integration, with the gateway URL of `alert-manager-mcp`. Add authentication with **API Key**, header name `api-key` and the runtime key as the value. - Configure the MCP for the agent and enable auto-approval for all tools. - Save the agent configuration. @@ -778,8 +755,8 @@ Review the addition of the Alert Manager Agent: alert_manager_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="AlertManagerAgent", - agent_version="7", + env_prefix="ALERT_MANAGER_AGENT", + default_name="AlertManagerAgent", ) ``` @@ -801,7 +778,9 @@ The workflow then runs the AML Report Agent and Alert Manager Agent as parallel ) ``` -> **Important:** Review your agent versions in case you need to update them before deployment. +> **Important:** The orchestration uses the latest version of each agent. To pin a version, set it in `.env` (see Challenge 4). + +> **Tip:** to try the orchestration locally before you deploy it, create `$walkthroughHome/challenge-05/orchestration/src/.env` with `FOUNDRY_PROJECT_ENDPOINT` and run `$walkthroughHome/challenge-05/orchestration/run-agent.sh`, as in Challenge 4. Deploy the updated orchestration. diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-06.md b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-06.md index 6ce1f559f..27f0e57eb 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-06.md +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/challenge-06.md @@ -44,7 +44,7 @@ Explore the sections and panels to understand the default telemetry and how it r Next, inspect a complete orchestration trace to see how the components interact and how telemetry is correlated across the workflow. -Select **View Traces with Agent Runs**, then choose a **Dependency**: +In the **Agent invocations** panel, select **View traces**. In the **Search** pane, select **View as individual items**, then choose a **Dependency**: ![View Traces with Agent Runs](./images/view-traces-with-agent-runs.png) @@ -79,7 +79,7 @@ Review this code to understand how each custom metric is defined and recorded. After reviewing the custom telemetry setup, redeploy the orchestration to generate telemetry. -> **Important:** Review your agent versions in case you need to update them before redeployment. +> **Important:** The orchestration uses the latest version of each agent. To pin a version, set it in `.env` (see Challenge 4). As in previous deployments, copy `src` and `azure.yaml` to the project root before redeploying: @@ -106,7 +106,7 @@ $walkthroughHome/challenge-06/orchestration/run-tests.sh \ --count 10 ``` -The script sends the number of requests specified by the `--count` argument. +The script sends the number of requests specified by the `--count` argument. It waits 30 seconds between requests (`--delay`) and retries a request that comes back empty: each run of the orchestration uses about 80,000 tokens, so back-to-back requests can exceed the model's per-minute quota and an agent in the workflow gets rate limited. ### 4. Verify custom telemetry in Application Insights @@ -187,7 +187,7 @@ Next, create **Graphical Dashboards** to visualize these custom metrics interact Use Grafana to create interactive dashboards for the custom metrics queried in Application Insights. -Return to the **Agents (Preview)** section introduced at the beginning of the lab, then select **Explore in Grafana** to open the Grafana integration: +Return to the **Agents** page of Application Insights (under **Investigate**) that you opened at the beginning of this challenge, then select **Explore in Grafana** in the toolbar to open the Grafana integration: ![Explore in Grafana](./images/explore-in-grafana.png) @@ -210,7 +210,7 @@ Then, use the following settings: - **Azure Monitor Datasource**: Azure Monitor -Select the correct **Application Insights** resource, whose name starts with `appi-fraud`. The imported dashboard should display panels similar to those below: +The dashboard can open on another Application Insights resource in the subscription and show **No data**. In the **Application Insights** selector at the top, choose the resource whose name starts with `appi-fraud`. The imported dashboard should display panels similar to those below: ![Custom metrics Grafana Dashboards](./images/custom-metrics-grafana-dashboards.png) diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/add-azure-blob-storage-source.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/add-azure-blob-storage-source.png index da2cc029f..eb4194f26 100644 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/add-azure-blob-storage-source.png and b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/add-azure-blob-storage-source.png differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/add-mcp-server-from-api.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/add-mcp-server-from-api.png deleted file mode 100644 index a67d1b447..000000000 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/add-mcp-server-from-api.png and /dev/null differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/add-mcp-server-in-ai-gateway-portal.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/add-mcp-server-in-ai-gateway-portal.png deleted file mode 100644 index cc49f6c89..000000000 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/add-mcp-server-in-ai-gateway-portal.png and /dev/null differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/agents-appins-dashboard.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/agents-appins-dashboard.png index 16cc895d0..e13759e5c 100644 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/agents-appins-dashboard.png and b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/agents-appins-dashboard.png differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/agents-versions.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/agents-versions.png index a54bbbf6d..75d0bf1a3 100644 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/agents-versions.png and b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/agents-versions.png differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/ai-gateway-deployment.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/ai-gateway-deployment.png deleted file mode 100644 index 63132ebc8..000000000 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/ai-gateway-deployment.png and /dev/null differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/explore-in-grafana.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/explore-in-grafana.png index 20b21df96..b0efca7c0 100644 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/explore-in-grafana.png and b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/explore-in-grafana.png differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-blank-agent.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-blank-agent.png index 451963c27..5cd90e48e 100644 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-blank-agent.png and b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-blank-agent.png differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-configure-mcp-tool-menu.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-configure-mcp-tool-menu.png index cf0c4d4f5..66d890ee5 100644 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-configure-mcp-tool-menu.png and b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-configure-mcp-tool-menu.png differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-connected-resources.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-connected-resources.png index c4b700091..734cd7eae 100644 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-connected-resources.png and b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-connected-resources.png differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-iq-knowledge-base-creation.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-iq-knowledge-base-creation.png index 46c53d846..c45bae4ce 100644 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-iq-knowledge-base-creation.png and b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-iq-knowledge-base-creation.png differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-new-agent.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-new-agent.png index c5163b178..1c4505860 100644 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-new-agent.png and b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/foundry-new-agent.png differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/list-existing-alerts.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/list-existing-alerts.png deleted file mode 100644 index c5b47460c..000000000 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/list-existing-alerts.png and /dev/null differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/list-tools-in-financial-evidence-mcp.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/list-tools-in-financial-evidence-mcp.png deleted file mode 100644 index 331b0b5be..000000000 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/list-tools-in-financial-evidence-mcp.png and /dev/null differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/run-get-bank-information-tool-in-financial-evidence-mcp.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/run-get-bank-information-tool-in-financial-evidence-mcp.png deleted file mode 100644 index 063cbb032..000000000 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/run-get-bank-information-tool-in-financial-evidence-mcp.png and /dev/null differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/supported-backend-types-in-ai-gateway-portal.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/supported-backend-types-in-ai-gateway-portal.png deleted file mode 100644 index a6ae8efa0..000000000 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/supported-backend-types-in-ai-gateway-portal.png and /dev/null differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/test-mcp-from-ai-gateway.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/test-mcp-from-ai-gateway.png deleted file mode 100644 index 4a41f6a77..000000000 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/test-mcp-from-ai-gateway.png and /dev/null differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/view-detailed-bank-information-in-financial-evidence-mcp.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/view-detailed-bank-information-in-financial-evidence-mcp.png deleted file mode 100644 index cc0b68a77..000000000 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/view-detailed-bank-information-in-financial-evidence-mcp.png and /dev/null differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/view-traces-with-agent-runs.png b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/view-traces-with-agent-runs.png index 8982e3391..4315702d8 100644 Binary files a/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/view-traces-with-agent-runs.png and b/03-Azure/01-04-AI/07_Fraud_Intelligence/challenges/images/view-traces-with-agent-runs.png differ diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/labautomation/shared-deploy-lab.ps1 b/03-Azure/01-04-AI/07_Fraud_Intelligence/labautomation/shared-deploy-lab.ps1 index be4f926aa..97166d8ff 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/labautomation/shared-deploy-lab.ps1 +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/labautomation/shared-deploy-lab.ps1 @@ -32,7 +32,11 @@ $requiredProviders = @( "Microsoft.ApiManagement", "Microsoft.OperationalInsights", "Microsoft.Insights", - "Microsoft.Storage" + "Microsoft.Storage", + # Participants deploy the Financial Evidence MCP Function App in Challenge 2. + "Microsoft.Web", + # Saving the imported Grafana dashboard in Challenge 6 creates a Microsoft.Dashboard resource. + "Microsoft.Dashboard" ) foreach($provider in $requiredProviders) { diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-01/prepare-scripts.sh b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-01/prepare-scripts.sh old mode 100644 new mode 100755 diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-01/solution-01.md b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-01/solution-01.md index c72e88b16..dc2fe8b37 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-01/solution-01.md +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-01/solution-01.md @@ -1,6 +1,6 @@ # Solution 1 - Prepare the Environment -**[Home](../README.md)** | [Next solution](solution-02.md) +**[Home](../../README.md)** | [Next solution](../challenge-02/solution-02.md) ## 🎯 Objective @@ -128,7 +128,7 @@ bash "$walkthroughHome/challenge-01/prepare-scripts.sh" ## 🚀 Go Further -Review the [solution architecture](../README.md#architecture) and identify where each deployed Azure resource is used in the five build challenges. +Review the [solution architecture](../../README.md#architecture) and identify where each deployed Azure resource is used in the five build challenges. ## 🛠️ Troubleshooting @@ -139,4 +139,4 @@ Review the [solution architecture](../README.md#architecture) and identify where ## 🧠 Conclusion -You have verified the Azure resources and opened the configured development environment. Continue to [Challenge 2](solution-02.md) to build the Evidence Enrichment Agent. \ No newline at end of file +You have verified the Azure resources and opened the configured development environment. Continue to [Challenge 2](../challenge-02/solution-02.md) to build the Evidence Enrichment Agent. \ No newline at end of file diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-02/cosmos/load-cosmos.sh b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-02/cosmos/load-cosmos.sh old mode 100644 new mode 100755 diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-02/financial-evidence-mcp/deploy.sh b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-02/financial-evidence-mcp/deploy.sh old mode 100644 new mode 100755 diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-02/solution-02.md b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-02/solution-02.md index e2a9ba099..f333c7ef8 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-02/solution-02.md +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-02/solution-02.md @@ -1,6 +1,6 @@ # Challenge 2 - Build the Evidence Enrichment Agent -[Previous challenge](solution-01.md) | **[Home](../README.md)** | [Next challenge](solution-03.md) +[Previous challenge](../challenge-01/solution-01.md) | **[Home](../../README.md)** | [Next challenge](../challenge-03/solution-03.md) ## 🎯 Objective @@ -111,6 +111,12 @@ Copy the value of the `mcp_extension` key and add it to `hackenv`: echo 'financialEvidenceMcpSystemKey=' >> hackenv ``` +Or read the key from the terminal instead of the portal: + +```bash +echo "financialEvidenceMcpSystemKey=$(az functionapp keys list -g "$rg" -n "$functionAppName" --query systemKeys.mcp_extension -o tsv)" >> hackenv +``` + Load the new environment variables into your shell: ```bash @@ -127,13 +133,13 @@ In the Azure portal, open your **Microsoft Foundry** resource and select **Go to #### Explore the Foundry project -The provided Microsoft Foundry project contains two model deployments: a chat model used by the agent and an embedding model. Find both deployments and review their details. +The provided Microsoft Foundry project contains two model deployments: a chat model used by the agent and an embedding model. Open **Models** under **Build** to find both deployments and review their details. Next, connect the Application Insights resource deployed in your environment to the Foundry project. This connection allows you to monitor agent performance and investigate issues. -Open **Manage** and select **Project details** from the left menu. Select **Connected resources**, then **Add connection**. +Open **Manage** and select **Project details** from the left menu. Select the **Connections** tab, then **Add connection**. -![Connected resources in Microsoft Foundry](../../challenges/images/foundry-connected-resources.png) +![Project connections in Microsoft Foundry](../../challenges/images/foundry-connected-resources.png) Select **Application Insights**, then select **Continue**. Choose the Application Insights resource deployed for your lab, leave **API key** as the authentication method, and select **Connect**. @@ -145,11 +151,9 @@ Under **Build**, open **Agents**, select **New agent**, then select **Build an a Name the agent `EvidenceEnrichmentAgent`. -The new agent opens with a blank configuration: - -![Blank agent in Microsoft Foundry](../../challenges/images/foundry-blank-agent.png) +The new agent opens with a blank configuration. Its **Model** may default to `model-router`, listed under **Models**. Open the **Model** list and select `gpt-5.6-luna` under **Deployments**. This is the chat model deployed for the lab; the embedding deployment is not a chat model. -The chat model is selected automatically because it is the only deployed model that can power this agent. The embedding deployment is not a chat model. +![Select the gpt-5.6-luna deployment in Microsoft Foundry](../../challenges/images/foundry-blank-agent.png) Select **Instructions** and copy the contents of `walkthrough/challenge-02/evidence-enrichment-agent/instructions.md` into the instruction editor. @@ -173,9 +177,9 @@ Configure these values: Select **Connect**. Foundry returns to the agent page and displays the new MCP tool. -Open the MCP tool's `...` menu and select **Configure**: +Open the MCP tool's `...` menu and select **Edit**: -![Configure MCP tool menu in Microsoft Foundry](../../challenges/images/foundry-configure-mcp-tool-menu.png) +![Edit MCP tool menu in Microsoft Foundry](../../challenges/images/foundry-configure-mcp-tool-menu.png) Then enable **Always auto-approve all tools**. @@ -232,4 +236,4 @@ Run the Financial Evidence MCP locally with Azure Functions Core Tools, invoke e ## 🧠 Conclusion -You have built an Evidence Enrichment Agent that retrieves traceable financial evidence from Azure Cosmos DB through a read-only MCP. Continue to [Challenge 3](solution-03.md), where the enriched transaction will be assessed against global and regional regulations. +You have built an Evidence Enrichment Agent that retrieves traceable financial evidence from Azure Cosmos DB through a read-only MCP. Continue to [Challenge 3](../challenge-03/solution-03.md), where the enriched transaction will be assessed against global and regional regulations. diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-03/regulatory-assesment-agent/instructions.md b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-03/regulatory-assessment-agent/instructions.md similarity index 100% rename from 03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-03/regulatory-assesment-agent/instructions.md rename to 03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-03/regulatory-assessment-agent/instructions.md diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-03/solution-03.md b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-03/solution-03.md index 7a4819e29..d370c38c3 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-03/solution-03.md +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-03/solution-03.md @@ -1,6 +1,6 @@ # Challenge 3 - Build the Regulatory Assessment Agent -[Previous challenge](solution-02.md) | **[Home](../README.md)** | [Next challenge](solution-04.md) +[Previous challenge](../challenge-02/solution-02.md) | **[Home](../../README.md)** | [Next challenge](../challenge-04/solution-04.md) ## 🎯 Objective @@ -52,9 +52,11 @@ After the resource is created, select **Create a knowledge base** and set the fo - **Name**: kb-aml - **Description**: Synthetic AML / CFT / KYC corpus for Fraud Intelligence -- **Chat completion model**: gpt-5-mini (or gpt-5.4-mini, new models are being added/delete to/from this configuration section) + +Then expand **Improve retrieval** and set: + +- **Chat completions model**: `gpt-5.6-luna` (the chat model deployed in your lab; it is the only one in the list) - **Retrieval reasoning effort**: Minimal -- **Output mode**: Extractive data - **Retrieval instructions**: You have to always retrieve first the global policies and rules. ![Foundry IQ Knowledge Base Creation](../../challenges/images/foundry-iq-knowledge-base-creation.png) @@ -150,7 +152,7 @@ Because this is the second agent, follow the same **Microsoft Foundry** agent cr Relevant steps you should not miss include: - Define the agent's name as `RegulatoryAssessmentAgent` -- Set the model: `gpt-5.6-luna` +- Set the model: `gpt-5.6-luna` (under **Deployments**, not `model-router`) - Set instructions: find them under `walkthrough/challenge-03/regulatory-assessment-agent/instructions.md`. Review and validate content. - Remove the `Web Search` tool, irrelevant for this agent. @@ -367,7 +369,7 @@ Next, add the internal and regional policy sources. Return to **Knowledge** and select the `kb-aml` knowledge base you created. -First, modify the **Retrieval instructions** to include the internal and regional policy sources after the global policies: +First, expand **Improve retrieval** and modify the **Retrieval instructions** to include the internal and regional policy sources after the global policies: ```text You have to always retrieve first the global policies and rules, then the internal rules and policies, and finally the regional rules and policies based on the transaction's bank origin and destination. Only the ones for these countries if documentation exists. @@ -422,4 +424,4 @@ Test a cross-border transaction for which one country has incomplete guidance. C ## 🧠 Conclusion -You have added a policy-grounded Regulatory Assessment Agent that evaluates global, internal, and country-specific AML requirements. Continue to [Challenge 4](solution-04.md) to generate an investigation report and orchestrate the first three agents. +You have added a policy-grounded Regulatory Assessment Agent that evaluates global, internal, and country-specific AML requirements. Continue to [Challenge 4](../challenge-04/solution-04.md) to generate an investigation report and orchestrate the first three agents. diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/orchestration/azure.yaml b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/orchestration/azure.yaml index df201114c..55a29883f 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/orchestration/azure.yaml +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/orchestration/azure.yaml @@ -32,7 +32,7 @@ services: memory: 1.0Gi environmentVariables: - name: AZURE_AI_AGENTSERVER_DISABLE_EXPERIMENTAL_WARNING - value: true + value: 'true' codeConfiguration: runtime: python_3_14 entryPoint: main.py diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/orchestration/run-agent.sh b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/orchestration/run-agent.sh old mode 100644 new mode 100755 diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/orchestration/src/main.py b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/orchestration/src/main.py index cde9eccd2..66e416fb9 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/orchestration/src/main.py +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/orchestration/src/main.py @@ -6,6 +6,7 @@ from agent_framework.foundry import FoundryAgent from agent_framework_foundry_hosting import ResponsesHostServer from azure.ai.agentserver.core.tasks import set_resilient_tasks_enabled +from azure.ai.projects import AIProjectClient from azure.identity import DefaultAzureCredential from dotenv import load_dotenv @@ -17,9 +18,16 @@ def get_foundry_agent( *, project_endpoint: str, credential: DefaultAzureCredential, - agent_name: str, - agent_version: str, + env_prefix: str, + default_name: str, ) -> FoundryAgent: + # Names and versions come from .env, for example AML_REPORT_AGENT_VERSION=3. + # Without a version, the latest version saved in Microsoft Foundry is used. + agent_name = os.getenv(f"{env_prefix}_NAME") or default_name + agent_version = os.getenv(f"{env_prefix}_VERSION") + if not agent_version: + with AIProjectClient(endpoint=project_endpoint, credential=credential) as client: + agent_version = client.agents.get(agent_name=agent_name).versions.latest.version print(f"Getting Foundry agent: {agent_name} v{agent_version}") return FoundryAgent( project_endpoint=project_endpoint, @@ -39,22 +47,22 @@ def main(): evidence_enrichment_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="evidenceenrichmentagent", - agent_version="2", + env_prefix="EVIDENCE_ENRICHMENT_AGENT", + default_name="EvidenceEnrichmentAgent", ) regulatory_assessment_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="RegulatoryAssessmentAgent", - agent_version="3", + env_prefix="REGULATORY_ASSESSMENT_AGENT", + default_name="RegulatoryAssessmentAgent", ) aml_report_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="AMLReportAgent", - agent_version="2", + env_prefix="AML_REPORT_AGENT", + default_name="AMLReportAgent", ) # Set the context mode to `last_agent` so that each agent only sees the output of the diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/solution-04.md b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/solution-04.md index 315be5fc4..5749104b6 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/solution-04.md +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-04/solution-04.md @@ -1,6 +1,6 @@ # Challenge 4 - Build and Orchestrate the Investigation -[Previous challenge](solution-03.md) | **[Home](../README.md)** | [Next challenge](solution-05.md) +[Previous challenge](../challenge-03/solution-03.md) | **[Home](../../README.md)** | [Next challenge](../challenge-05/solution-05.md) ## 🎯 Objective @@ -43,7 +43,7 @@ The report must preserve source identifiers so an analyst can trace each finding This is the third agent you will build, so follow the same creation and configuration process used for the previous agents. Configure the following settings: - Define the agent's name as `AMLReportAgent` -- Set the model: `gpt-5.6-luna` +- Set the model: `gpt-5.6-luna` (under **Deployments**, not `model-router`) - Set instructions: find them under `walkthrough/challenge-04/aml-report-agent/instructions.md`. Review and validate content. - Remove the `Web Search` tool, irrelevant for this agent. @@ -803,9 +803,9 @@ The source code is in the `orchestration` directory under `challenge-04`. Review - `src/main.py`: The main entry point for the orchestration logic. That is where we will initialize and coordinate the various agents involved in the process. - `azure.yaml`: Configuration file for the agent that is required during the phase of deploying the agent as **Hosted Agent** in **Microsoft Foundry**. -Ensure that the agents are defined correctly in the `main.py` file and that their names and versions match those running in the Foundry environment. Open the **Agents** section in the portal to verify these values. +The orchestration finds each agent by name and uses its **latest** saved version, so you do not need to edit `main.py`. The names must match the agents you created: `EvidenceEnrichmentAgent`, `RegulatoryAssessmentAgent` and `AMLReportAgent`. Open the **Agents** section in the portal to check the names and versions. -Those names and versions should be set correctly in the `main.py` file: +To pin a version, or if you named an agent differently, add it to the `.env` file you create below, for example `AML_REPORT_AGENT_VERSION=3` or `AML_REPORT_AGENT_NAME=MyReportAgent`. The prefixes are `EVIDENCE_ENRICHMENT_AGENT`, `REGULATORY_ASSESSMENT_AGENT`, `AML_REPORT_AGENT` and, from Challenge 5, `ALERT_MANAGER_AGENT`. ![Agents versions](../../challenges/images/agents-versions.png) @@ -912,6 +912,22 @@ Track the deployment progress in the **Output** panel in Visual Studio Code by s ![Deployment progress in Output panel](../../challenges/images/deployment-progress-in-output-panel.png) +#### Allow the orchestration to call your agents + +The hosted orchestration runs with its own managed identity. Give that identity the **Foundry User** role on the Foundry account so it can read and invoke the three agents. Run this once, after the first deployment: + +```bash +agentPrincipalId=$(az rest --method get --resource https://ai.azure.com \ + --url "https://$foundryAccountName.services.ai.azure.com/api/projects/$foundryProjectName/agents/fraud-intelligence-orchestration?api-version=v1" \ + --query "versions.latest.instance_identity.principal_id" -o tsv) + +az role assignment create --assignee-object-id "$agentPrincipalId" --assignee-principal-type ServicePrincipal \ + --role "Foundry User" \ + --scope "$(az cognitiveservices account show --name $foundryAccountName --resource-group $rg --query id -o tsv)" +``` + +Wait one to two minutes for the role to take effect, then start a **new** conversation in the playground. Without the role, the playground returns `424 session_not_ready` because the orchestration cannot read the agents when it starts. + Once the deployment is complete, you can run a test using the **Hosted Agent Playground**: ![Hosted Agent Playground](../../challenges/images/hosted-agent-playground.png) @@ -944,6 +960,7 @@ Add idempotent case identifiers and checkpointing so a transient failure can res ## 🛠️ Troubleshooting +- **The hosted agent returns `424 session_not_ready`:** The orchestration container failed to start. If its logs show `does not have permissions for .../agents/read`, run the role assignment in [Allow the orchestration to call your agents](#allow-the-orchestration-to-call-your-agents), wait two minutes, and start a new conversation. - **A remote agent cannot be invoked:** Verify the project endpoint, agent name and version, managed identity, and role assignments. - **A handoff fails validation:** Compare the producing agent's output with the consuming schema and inspect the raw response in the trace. - **The report changes the decision:** Ensure the report agent receives the assessment as authoritative and has no instruction to reassess it. @@ -952,4 +969,4 @@ Add idempotent case identifiers and checkpointing so a transient failure can res ## 🧠 Conclusion -You have composed evidence enrichment, regulatory assessment, and reporting into a deployable investigation workflow. Continue to [Challenge 5](solution-05.md) to govern MCP traffic and add operational alerting. \ No newline at end of file +You have composed evidence enrichment, regulatory assessment, and reporting into a deployable investigation workflow. Continue to [Challenge 5](../challenge-05/solution-05.md) to govern MCP traffic and add operational alerting. \ No newline at end of file diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/orchestration/azure.yaml b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/orchestration/azure.yaml index df201114c..55a29883f 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/orchestration/azure.yaml +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/orchestration/azure.yaml @@ -32,7 +32,7 @@ services: memory: 1.0Gi environmentVariables: - name: AZURE_AI_AGENTSERVER_DISABLE_EXPERIMENTAL_WARNING - value: true + value: 'true' codeConfiguration: runtime: python_3_14 entryPoint: main.py diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/orchestration/run-agent.sh b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/orchestration/run-agent.sh old mode 100644 new mode 100755 diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/orchestration/src/main.py b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/orchestration/src/main.py index 3bf2830a7..312bfe3e9 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/orchestration/src/main.py +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/orchestration/src/main.py @@ -6,6 +6,7 @@ from agent_framework.foundry import FoundryAgent from agent_framework_foundry_hosting import ResponsesHostServer from azure.ai.agentserver.core.tasks import set_resilient_tasks_enabled +from azure.ai.projects import AIProjectClient from azure.identity import DefaultAzureCredential from dotenv import load_dotenv @@ -16,9 +17,16 @@ def get_foundry_agent( *, project_endpoint: str, credential: DefaultAzureCredential, - agent_name: str, - agent_version: str, + env_prefix: str, + default_name: str, ) -> FoundryAgent: + # Names and versions come from .env, for example AML_REPORT_AGENT_VERSION=3. + # Without a version, the latest version saved in Microsoft Foundry is used. + agent_name = os.getenv(f"{env_prefix}_NAME") or default_name + agent_version = os.getenv(f"{env_prefix}_VERSION") + if not agent_version: + with AIProjectClient(endpoint=project_endpoint, credential=credential) as client: + agent_version = client.agents.get(agent_name=agent_name).versions.latest.version print(f"Getting Foundry agent: {agent_name} v{agent_version}") return FoundryAgent( project_endpoint=project_endpoint, @@ -38,29 +46,29 @@ def main(): evidence_enrichment_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="EvidenceEnrichmentAgent", - agent_version="7", + env_prefix="EVIDENCE_ENRICHMENT_AGENT", + default_name="EvidenceEnrichmentAgent", ) regulatory_assessment_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="RegulatoryAssessmentAgent", - agent_version="2", + env_prefix="REGULATORY_ASSESSMENT_AGENT", + default_name="RegulatoryAssessmentAgent", ) aml_report_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="AMLReportAgent", - agent_version="2", + env_prefix="AML_REPORT_AGENT", + default_name="AMLReportAgent", ) alert_manager_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="AlertManagerAgent", - agent_version="7", + env_prefix="ALERT_MANAGER_AGENT", + default_name="AlertManagerAgent", ) # Set the context mode to `last_agent` so that each agent only sees the output of the diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/solution-05.md b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/solution-05.md index 1a74f48d5..82e824e9e 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/solution-05.md +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-05/solution-05.md @@ -1,10 +1,10 @@ # Challenge 5 - Govern MCP Servers -[Previous challenge](solution-04.md) | **[Home](../README.md)** | [Next challenge](solution-06.md) +[Previous challenge](../challenge-04/solution-04.md) | **[Home](../../README.md)** | [Next challenge](../challenge-06/solution-06.md) ## 🎯 Objective -Introduce the **AI Gateway tier (preview)** for MCP access, generate an MCP interface from the Fraud Alert Manager API, build an **Alert Manager Agent**, and run alert creation in parallel with report generation. +Put MCP access behind **Azure AI Gateway**, generate an MCP interface from the Fraud Alert Manager API, build an **Alert Manager Agent**, and run alert creation in parallel with report generation. ## 🧭 Context and Background @@ -18,7 +18,7 @@ flowchart LR ALERT --> AMCP[Fraud Alert Manager MCP] AMCP --> API[Fraud Alert Manager API] - ORCH[Hosted orchestration] --> GATEWAY[AI Gateway tier] + ORCH[Hosted orchestration] --> GATEWAY[Azure AI Gateway] GATEWAY --> FMCP[Financial Evidence MCP] GATEWAY --> AMCP ``` @@ -35,63 +35,51 @@ source hackenv ### 1. Deploy the AI Gateway -An **AI Gateway** is a centralized control point for securing and managing MCP traffic between AI agents and external services. It routes requests and responses through a governance layer that can enforce authentication, authorization, rate limiting, and other policies. This helps protect sensitive information, support compliance, and provide observability into AI-driven workflows. - -In Azure, API Management provides the AI Gateway. In this lab, you will deploy a dedicated API Management instance using the preview `AIGateway` SKU, then route MCP calls through this centralized governance layer. +**Azure AI Gateway** is a centralized control point for securing and managing traffic between AI agents and models or tools. It routes requests through a governance layer that can enforce authentication, rate limits and other policies, and it gives you one place to observe AI traffic. Each gateway includes 10,000 free requests per month, which is plenty for this lab. #### Create the Gateway -During the preview, you can create the `AIGateway` SKU through the **AI Gateway portal**, but not through the public Azure CLI or ARM REST API. - -Open the [AI Gateway portal](https://ai.gateway.azure.com/) and sign in with the lab account. Create a new AI Gateway with these settings: - -- **Name**: enter a globally unique name -- **Subscription**: the lab subscription -- **Region**: `swedencentral` -- **Resource group**: the existing lab resource group -- **Enable managed identity** - -![AI Gateway deployment screenshot](../../challenges/images/ai-gateway-deployment.png) - -### 2. Proxy the Financial Evidence MCP - -The **AI Gateway** can proxy existing Model Context Protocol (MCP) servers. This applies access, authentication, and rate-limiting policies at the gateway without requiring changes to the MCP implementation. - -Next, onboard the existing `financial evidence` MCP to the AI Gateway. In the **AI Gateway** portal, open the **MCP servers** section and select **Add MCP server**: - -![Add MCP server in the AI Gateway portal](../../challenges/images/add-mcp-server-in-ai-gateway-portal.png) +Install the `aigateway` Azure CLI extension in the Codespace terminal, then create a gateway in your lab resource group and save it as the default for the next commands. A new gateway is ready in about a minute and a half. -The portal supports three backend types: - -![Supported backend types in the AI Gateway portal](../../challenges/images/supported-backend-types-in-ai-gateway-portal.png) +```bash +curl -fsSL https://aka.ms/aigateway-cli-install | bash +az aig version -Select **MCP server**, then provide the details required to connect to the existing Financial Evidence MCP: +GW="aigw-fraud-$RANDOM" +az aig create --resource-group "$rg" --name "$GW" --location swedencentral +az configure --defaults group="$rg" aigateway="$GW" +``` -- **Backend Name**: A friendly name for the MCP server, for instance, `financial-evidence-mcp`. -- **URL**: The URL of the existing `financial evidence` MCP server. Use the value returned by `echo "$financialEvidenceMcpEndpoint"` -- **Authentication**: set **API Key**, with: - - **Header Name**: `x-functions-key` - - **Value:** Use the value returned by `echo "$financialEvidenceMcpSystemKey"`. +Create a runtime API key for your agents and keep it in a variable: -Select **Next**, validate the configuration, and select **Create** to add the MCP server to the **AI Gateway**. +```bash +az aig api-key create --name lab --display-name "Lab key" --state active +gatewayApiKey=$(az aig api-key list-secrets --name lab --query primaryKey -o tsv) +gatewayHost=$(az aig show --query properties.frontend.defaultHostname -o tsv) +echo "https://$gatewayHost" +``` -You can now test the MCP from the **AI Gateway**. Select **Use**: +> **Portal alternative:** open the [AI Gateway portal](https://ai.gateway.azure.com/), sign in with the lab account and create the gateway in the lab subscription and resource group, in `swedencentral`. The portal also shows your runtime keys. -![Test the MCP from the AI Gateway](../../challenges/images/test-mcp-from-ai-gateway.png) +### 2. Proxy the Financial Evidence MCP -Select the **Try it** tab, then select **List tools**. You should see all tools exposed by the Financial Evidence MCP: +The **AI Gateway** can proxy existing Model Context Protocol (MCP) servers. This applies access, authentication and rate-limiting policies at the gateway without changing the MCP implementation. -![List tools in the financial evidence MCP](../../challenges/images/list-tools-in-financial-evidence-mcp.png) +Register the existing Financial Evidence MCP with the gateway. The gateway calls the Function App with its system key, so the key stays in the gateway and never reaches the agent: -Select the **Get Bank Information** operation, enter `0121` as the bank ID, and select **Run tool**: +```bash +az aig mcp create --name financial-evidence-mcp \ + --url "$financialEvidenceMcpEndpoint" \ + --credentials "{\"type\":\"header\",\"headers\":{\"x-functions-key\":[\"$financialEvidenceMcpSystemKey\"]}}" -![Run Get Bank Information tool in the financial evidence MCP](../../challenges/images/run-get-bank-information-tool-in-financial-evidence-mcp.png) +az aig mcp show --name financial-evidence-mcp --query "properties.gatewayEndpoints[0].url" -o tsv +``` -The result should display information for bank ID `0121`. Expand the `data` element to view the details: +The last command prints the gateway URL of the MCP, in the form `https:///default/toolservers/financial-evidence-mcp/mcp`. Callers authenticate with the runtime key in an `api-key` header. -![View detailed bank information in the financial evidence MCP](../../challenges/images/view-detailed-bank-information-in-financial-evidence-mcp.png) +You can test it in the **AI Gateway** portal: open **MCP servers**, select `financial-evidence-mcp`, then **Use** > **Try it** > **List tools**. Run **Get Bank Information** with bank ID `0121` and check that the bank details come back. -You can now interact with the Financial Evidence MCP through the **AI Gateway**. Next, configure `EvidenceEnrichmentAgent` to use it. +> The gateway prefixes each tool with the MCP server name, for example `financial-evidence-mcp_get_bank_information`. Agents still pick the right tools; the instructions do not need to change. #### Update the EvidenceEnrichmentAgent Configuration @@ -99,12 +87,12 @@ Return to the **Microsoft Foundry** portal. Under **Build**, select **Agents**, ![Remove existing tool from the EvidenceEnrichmentAgent](../../challenges/images/remove-existing-tool-from-evidenceenrichmentagent.png) -Select **Save**, then open the **Tools** menu on the left side of the page. +Select **Save**, then select **Tools** in the left navigation. The page opens on **Toolboxes**; select the **Tools** tab to see the `financial-evidence-mcp` connection. Select the `financial-evidence-mcp` tool and update its URL and authentication: -- **Remote MCP Server endpoint**: Use the Financial Evidence MCP URL exposed through the **AI Gateway**. -- **Credential**: Set the header name to `api-key` and use an existing key from your **AI Gateway** configuration. +- **Remote MCP Server endpoint**: the gateway URL of `financial-evidence-mcp` from the previous step. +- **Credential**: set the header name to `api-key` and the value to the runtime key (`echo "$gatewayApiKey"`). Then select **Update**. @@ -122,42 +110,31 @@ Under the `EvidenceEnrichmentAgent` **Tools** section, verify that the `financia Test the agent and inspect its traces to verify that it uses `financial-evidence-mcp` through the **AI Gateway**. -To explore additional gateway policies, open the **Policies** section for `financial-evidence-mcp`. Because the **AI Gateway** is in preview, some MCP features, including the **Monitoring** tab, may still be unavailable. +To explore additional gateway policies, open **Policies** for `financial-evidence-mcp` in the **AI Gateway** portal, or list them with `az aig policy list`. ### 3. Generate an MCP from the Fraud Alert Manager API -The **AI Gateway** can also expose an existing API as an MCP, bringing agent integration and policy management to APIs that were not originally designed as MCP servers. - -For this scenario, the Fraud Alert Manager API manages financial alerts so that operational users can review them and take action. A simple web interface is also available for validation. +The **AI Gateway** can also expose an existing API as an MCP, bringing agent integration and policy management to APIs that were not designed as MCP servers. -First, retrieve the API endpoint so that the AI Gateway can read its OpenAPI specification. The API runs on **Azure Container Apps**: +The Fraud Alert Manager API manages financial alerts so that operational users can review them and act on them. It runs on **Azure Container Apps** and publishes an OpenAPI specification. Create an MCP server from that specification: ```bash endpoint=$(az containerapp show --name alert-manager --resource-group $rg --query properties.configuration.ingress.fqdn -o tsv) -echo "https://$endpoint/openapi.json" -``` -Copy the URL; you will use it to configure the MCP in the **AI Gateway**. - -Return to **MCP servers** in the **AI Gateway** portal. Follow the previous process using a different backend. - -Select **Add MCP server**, choose **OpenAPI Specification**, and complete the form with the following details: -- **Name**: Provide a name for the MCP server, e.g., `alert-manager-mcp`. -- **Spec source**: Select **Fetch from URL** -- **Spec URL**: Paste the URL you obtained from the previous step. -- **Authentication**: Select **None** because the lab API does not require authentication. +az aig mcp create --name alert-manager-mcp \ + --endpoints "[{\"kind\":\"openApi\",\"namespace\":\"alert-manager-mcp\",\"openApi\":{\"specSource\":{\"type\":\"url\",\"url\":\"https://$endpoint/openapi.json\"}}}]" -![Add MCP server](../../challenges/images/add-mcp-server-from-api.png) - -Select **Next**, validate the configuration, and select **Create** to add the MCP server. +az aig mcp show --name alert-manager-mcp --query "properties.gatewayEndpoints[0].url" -o tsv +``` -Explore the new MCP server in the **AI Gateway** playground. For example, list the existing alerts: +The lab API needs no authentication of its own. The gateway generates one tool per API operation: `create_alert`, `list_alerts`, `get_alert`, `replace_alert`, `patch_alert`, `delete_alert` and `health`. -![List existing alerts](../../challenges/images/list-existing-alerts.png) +> **Portal alternative:** in the **AI Gateway** portal open **MCP servers** > **Add MCP server**, choose **OpenAPI Specification**, select **Fetch from URL**, paste `https:///openapi.json` and set **Authentication** to **None**. +Try the new MCP server in the **AI Gateway** playground, for example by listing the existing alerts. -Next, create `AlertManagerAgent` to interact with `alert-manager-mcp` through the **AI Gateway**, then add the agent to the full orchestration. +Next, create `AlertManagerAgent` to work with `alert-manager-mcp` through the **AI Gateway**, then add the agent to the full orchestration. ### 4. Create the AlertManagerAgent @@ -166,8 +143,8 @@ This is the fourth agent in the workflow. `AlertManagerAgent` uses `alert-manage Use the following configuration: - Use the agent instructions in `walkthrough/challenge-05/alert-manager-agent/instructions.md`. -- Select the model: `gpt-5.6-luna` -- Onboard the MCP in **Microsoft Foundry** following the usual steps for MCP integration. Remember to add authentication with **API Key**, using header name `api-key` and value a valid API key provided by the **AI Gateway**. +- Select the model: `gpt-5.6-luna` (under **Deployments**, not `model-router`) +- Onboard the MCP in **Microsoft Foundry** following the usual steps for MCP integration, with the gateway URL of `alert-manager-mcp`. Add authentication with **API Key**, header name `api-key` and the runtime key as the value. - Configure the MCP for the agent and enable auto-approval for all tools. - Save the agent configuration. @@ -765,7 +742,7 @@ You can view the alert details or remove the alert to avoid duplicates in later The final task is to add `AlertManagerAgent` to the orchestration so it can process transactions that require operational alerting. -As in [Challenge 4](solution-04.md), update the orchestration to include and connect the new agent. +As in [Challenge 4](../challenge-04/solution-04.md), update the orchestration to include and connect the new agent. The source code is under the `walkthrough/challenge-05/orchestration` directory. The relevant files are: @@ -778,8 +755,8 @@ Review the addition of the Alert Manager Agent: alert_manager_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="AlertManagerAgent", - agent_version="7", + env_prefix="ALERT_MANAGER_AGENT", + default_name="AlertManagerAgent", ) ``` @@ -801,7 +778,9 @@ The workflow then runs the AML Report Agent and Alert Manager Agent as parallel ) ``` -> **Important:** Review your agent versions in case you need to update them before deployment. +> **Important:** The orchestration uses the latest version of each agent. To pin a version, set it in `.env` (see Challenge 4). + +> **Tip:** to try the orchestration locally before you deploy it, create `$walkthroughHome/challenge-05/orchestration/src/.env` with `FOUNDRY_PROJECT_ENDPOINT` and run `$walkthroughHome/challenge-05/orchestration/run-agent.sh`, as in Challenge 4. Deploy the updated orchestration. @@ -814,7 +793,7 @@ cp -Rf \ "$hackFolder/" ``` -For the complete **Foundry Toolkit** deployment procedure, refer to [Challenge 4](solution-04.md). For this deployment: +For the complete **Foundry Toolkit** deployment procedure, refer to [Challenge 4](../challenge-04/solution-04.md). For this deployment: - Keep **Deployment method** set to **Code** and **Package mode** set to **Remote**. - Set **Deploy to** to **Existing agent** because this deployment updates the orchestration with `AlertManagerAgent`. @@ -874,4 +853,4 @@ Add per-agent quotas and compare their effects under a short concurrent workload ## 🧠 Conclusion -You have placed MCP traffic behind a governance boundary and added operational alerting in parallel with report generation. Continue to [Challenge 6](solution-06.md) to add operational and business observability to the complete workflow. +You have placed MCP traffic behind a governance boundary and added operational alerting in parallel with report generation. Continue to [Challenge 6](../challenge-06/solution-06.md) to add operational and business observability to the complete workflow. diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/azure.yaml b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/azure.yaml index df201114c..55a29883f 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/azure.yaml +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/azure.yaml @@ -32,7 +32,7 @@ services: memory: 1.0Gi environmentVariables: - name: AZURE_AI_AGENTSERVER_DISABLE_EXPERIMENTAL_WARNING - value: true + value: 'true' codeConfiguration: runtime: python_3_14 entryPoint: main.py diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/run-agent.sh b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/run-agent.sh old mode 100644 new mode 100755 diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/run-tests.sh b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/run-tests.sh old mode 100644 new mode 100755 diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/src/hosted_agent_client.py b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/src/hosted_agent_client.py index 22d60fd95..37cc46bc8 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/src/hosted_agent_client.py +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/src/hosted_agent_client.py @@ -3,6 +3,7 @@ import os import random import string +import time import uuid from dataclasses import dataclass from typing import Any @@ -17,6 +18,11 @@ DEFAULT_BANK_CONTAINER = "dim-bank" DEFAULT_PATTERN_CONTAINER = "fact-laundering-pattern-txn" MAX_BANK_SELECTION_ATTEMPTS = 20 +# One orchestration run uses roughly 80-90K tokens, so back-to-back runs can exceed the +# lab's per-minute model quota. An empty answer means an agent in the workflow was throttled. +DEFAULT_DELAY_SECONDS = 30 +MAX_INVOKE_ATTEMPTS = 3 +RETRY_WAIT_SECONDS = 60 CURRENCIES = ("EUR", "USD", "GBP", "CHF", "JPY", "CAD", "AUD") ORIGINATOR_NAMES = ( @@ -243,10 +249,21 @@ def invoke_hosted_agent( payload: dict[str, Any], ) -> str: openai_client = project_client.get_openai_client(agent_name=agent_name) - response = openai_client.responses.create( - input=json.dumps(payload), - ) - return response.output_text + for attempt in range(1, MAX_INVOKE_ATTEMPTS + 1): + try: + response = openai_client.responses.create( + input=json.dumps(payload), + ) + if response.output_text.strip(): + return response.output_text + problem = "empty response (an agent in the workflow was probably rate limited)" + except Exception as error: # noqa: BLE001 - report and retry any service error + problem = str(error)[:200] + if attempt < MAX_INVOKE_ATTEMPTS: + wait = RETRY_WAIT_SECONDS * attempt + print(f"Attempt {attempt} failed: {problem}. Retrying in {wait}s...") + time.sleep(wait) + return f"No response after {MAX_INVOKE_ATTEMPTS} attempts: {problem}" def parse_args() -> argparse.Namespace: @@ -256,6 +273,12 @@ def parse_args() -> argparse.Namespace: parser.add_argument("--count", type=int, default=1, help="Number of independent requests to send") parser.add_argument("--seed", type=int, help="Seed for reproducible data selection") parser.add_argument("--dry-run", action="store_true", help="Print payloads without invoking the agent") + parser.add_argument( + "--delay", + type=int, + default=DEFAULT_DELAY_SECONDS, + help="Seconds to wait between requests to stay within the model quota", + ) parser.add_argument("--project-endpoint", default=os.getenv("FOUNDRY_PROJECT_ENDPOINT")) parser.add_argument("--agent-name", default=os.getenv("FOUNDRY_HOSTED_AGENT_NAME", DEFAULT_AGENT_NAME)) parser.add_argument("--cosmos-endpoint", default=os.getenv("AZURE_COSMOS_ENDPOINT")) @@ -317,6 +340,8 @@ def main() -> None: payload=payload, ) print(f"Response:\n{result}") + if request_index < args.count - 1 and args.delay > 0: + time.sleep(args.delay) finally: if project_client is not None: project_client.close() diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/src/main.py b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/src/main.py index 40fe88211..ece2ccbbf 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/src/main.py +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/orchestration/src/main.py @@ -6,6 +6,7 @@ from agent_framework.foundry import FoundryAgent from agent_framework_foundry_hosting import ResponsesHostServer from azure.ai.agentserver.core.tasks import set_resilient_tasks_enabled +from azure.ai.projects import AIProjectClient from azure.identity import DefaultAzureCredential from business_metrics import alert_metrics_executor, evidence_metrics_executor, regulatory_metrics_executor from dotenv import load_dotenv @@ -17,9 +18,16 @@ def get_foundry_agent( *, project_endpoint: str, credential: DefaultAzureCredential, - agent_name: str, - agent_version: str, + env_prefix: str, + default_name: str, ) -> FoundryAgent: + # Names and versions come from .env, for example AML_REPORT_AGENT_VERSION=3. + # Without a version, the latest version saved in Microsoft Foundry is used. + agent_name = os.getenv(f"{env_prefix}_NAME") or default_name + agent_version = os.getenv(f"{env_prefix}_VERSION") + if not agent_version: + with AIProjectClient(endpoint=project_endpoint, credential=credential) as client: + agent_version = client.agents.get(agent_name=agent_name).versions.latest.version print(f"Getting Foundry agent: {agent_name} v{agent_version}") return FoundryAgent( project_endpoint=project_endpoint, @@ -39,29 +47,29 @@ def main(): evidence_enrichment_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="evidenceenrichmentagent", - agent_version="6", + env_prefix="EVIDENCE_ENRICHMENT_AGENT", + default_name="EvidenceEnrichmentAgent", ) regulatory_assessment_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="RegulatoryAssessmentAgent", - agent_version="3", + env_prefix="REGULATORY_ASSESSMENT_AGENT", + default_name="RegulatoryAssessmentAgent", ) aml_report_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="AMLReportAgent", - agent_version="2", + env_prefix="AML_REPORT_AGENT", + default_name="AMLReportAgent", ) alert_manager_agent = get_foundry_agent( project_endpoint=project_endpoint, credential=credential, - agent_name="AlertManagerAgent", - agent_version="2", + env_prefix="ALERT_MANAGER_AGENT", + default_name="AlertManagerAgent", ) # Set the context mode to `last_agent` so that each agent only sees the output of the diff --git a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/solution-06.md b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/solution-06.md index 9b2634875..77cee0cb7 100644 --- a/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/solution-06.md +++ b/03-Azure/01-04-AI/07_Fraud_Intelligence/walkthrough/challenge-06/solution-06.md @@ -1,6 +1,6 @@ # Challenge 6 - Observe Fraud Intelligence -[Previous challenge](solution-05.md) | **[Home](../README.md)** | [Finish](finish.md) +[Previous challenge](../challenge-05/solution-05.md) | **[Home](../../README.md)** | [Finish](../../challenges/finish.md) ## 🎯 Objective @@ -44,7 +44,7 @@ Explore the sections and panels to understand the default telemetry and how it r Next, inspect a complete orchestration trace to see how the components interact and how telemetry is correlated across the workflow. -Select **View Traces with Agent Runs**, then choose a **Dependency**: +In the **Agent invocations** panel, select **View traces**. In the **Search** pane, select **View as individual items**, then choose a **Dependency**: ![View Traces with Agent Runs](../../challenges/images/view-traces-with-agent-runs.png) @@ -79,7 +79,7 @@ Review this code to understand how each custom metric is defined and recorded. After reviewing the custom telemetry setup, redeploy the orchestration to generate telemetry. -> **Important:** Review your agent versions in case you need to update them before redeployment. +> **Important:** The orchestration uses the latest version of each agent. To pin a version, set it in `.env` (see Challenge 4). As in previous deployments, copy `src` and `azure.yaml` to the project root before redeploying: @@ -106,7 +106,7 @@ $walkthroughHome/challenge-06/orchestration/run-tests.sh \ --count 10 ``` -The script sends the number of requests specified by the `--count` argument. +The script sends the number of requests specified by the `--count` argument. It waits 30 seconds between requests (`--delay`) and retries a request that comes back empty: each run of the orchestration uses about 80,000 tokens, so back-to-back requests can exceed the model's per-minute quota and an agent in the workflow gets rate limited. ### 4. Verify custom telemetry in Application Insights @@ -187,7 +187,7 @@ Next, create **Graphical Dashboards** to visualize these custom metrics interact Use Grafana to create interactive dashboards for the custom metrics queried in Application Insights. -Return to the **Agents (Preview)** section introduced at the beginning of the lab, then select **Explore in Grafana** to open the Grafana integration: +Return to the **Agents** page of Application Insights (under **Investigate**) that you opened at the beginning of this challenge, then select **Explore in Grafana** in the toolbar to open the Grafana integration: ![Explore in Grafana](../../challenges/images/explore-in-grafana.png) @@ -209,7 +209,7 @@ Then, use the following settings: - **Region**: swedencentral - **Azure Monitor Datasource**: Azure Monitor -Select the correct **Application Insights** resource, whose name starts with `appi-fraud`. The imported dashboard should display panels similar to those below: +The dashboard can open on another Application Insights resource in the subscription and show **No data**. In the **Application Insights** selector at the top, choose the resource whose name starts with `appi-fraud`. The imported dashboard should display panels similar to those below: ![Custom metrics Grafana Dashboards](../../challenges/images/custom-metrics-grafana-dashboards.png) @@ -236,5 +236,5 @@ Create an Azure Monitor alert for sustained workflow failures or alert-delivery ## 🧠 Conclusion -You have instrumented the complete fraud intelligence workflow and created technical and business views of its behavior. Continue to the [finish page](finish.md) to complete the MicroHack. +You have instrumented the complete fraud intelligence workflow and created technical and business views of its behavior. Continue to the [finish page](../../challenges/finish.md) to complete the MicroHack.