Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ FROM mcr.microsoft.com/devcontainers/python:1-3.13-bookworm

ENV DEBIAN_FRONTEND=noninteractive \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1
PIP_NO_CACHE_DIR=1 \
PIP_INDEX_URL=https://packagefeedproxy.microsoft.io/pypi/simple

# System tools we use across labs: curl (already present), jq (parsing outputs),
# git (already present), zip/unzip (bundling artifacts).
Expand Down
2 changes: 1 addition & 1 deletion .github/PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Legend: ✅ complete · 🟡 stub/partial · ❌ not started · – not applicab
| Model deployment | ✅ | ✅ | ✅ | `fundamentals/03-deploy-models.md` — full body (azd + portal paths) |
| Prompt Agent creation | ✅ | – | ✅ | `fundamentals/04-create-prompt-agent.md` — references baseline artifact |
| Hosted Agent source (`src/` + `src.original/`) | – | ✅ | ✅ | main.py, agent.yaml, Dockerfile, instructions/, scripts/ ported + rebranded |
| Hosted Agent deploy lab | – | ✅ | ✅ | `fundamentals/05-deploy-hosted-agent.md` — full body |
| Hosted Agent deploy lab | – | ✅ | ✅ | `fundamentals/05-deploy-hosted-agent.md` — portal linker normalizes project name and persists ID + endpoint metadata before deploy |
| Bicep infra (`infra/`) | – | ✅ | ✅ | main.bicep, params, core/{ai,host,monitor,search,storage} ported + rebranded |
| Fundamentals verify lab | – | – | ✅ | `fundamentals/06-verify.md` — canonical question, both agents |
| Core: observability in portal | ✅ | partial | ✅ | `core/01-observe-portal.md` — playground + live evaluators + traces |
Expand Down
19 changes: 0 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
<div align="center">
<table width="100%">
<tr>
<td<div style="background:#111111;color:#f2c200;padding:16px;margin:4px;border-radius:6px;font-family:sans-serif;">

🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛

### 🚧 Work in Progress 🚧

**This workshop is under active development and testing.**. <br/>
Please wait till this banner is removed before using it for self-guided or instructor-led delivery.

🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛🟨⬛

</div></td>
</tr>
</table>
</div>

<div align="center">

# Build, Evaluate & Optimize AI Agents with Microsoft Foundry & GitHub Copilot
Expand Down
53 changes: 53 additions & 0 deletions labs/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,59 @@ independently. See the 404 section for the commands.

---

### `An internal server error occurred` when invoking the hosted agent

**Symptom.** `azd ai agent invoke` (or the Foundry portal playground) returns:

```text
ERROR: agent error (server_error): An internal server error occurred.
```

The agent monitor (`azd ai agent monitor`) logs show:

```text
ERROR azure.ai.agentserver: Resilient task subsystem missing in hosted
environment for response <id>; failing the request
RuntimeWarning: coroutine 'ResponsesHostServer._handle_response' was never awaited
```

An earlier startup line reads:

```text
INFO azure.ai.agentserver: TaskManager NOT initialized (resilient tasks disabled;
enable via set_resilient_tasks_enabled(True)). tasks_declared=True
```

**Cause.** A newer version of `agent-framework-foundry-hosting` (installed via
`remote_build`) requires the resilient task subsystem to be explicitly enabled
before the server starts when running in a hosted environment (`is_hosted=True`).
The function is not called in the default `main.py`, so every request fails.

**Fix.** Add the `set_resilient_tasks_enabled(True)` call in `src/main.py`
before `server.run()`, then redeploy:

```python
# src/main.py — add this import alongside the existing ResponsesHostServer import
from azure.ai.agentserver.core.tasks import set_resilient_tasks_enabled

def main() -> None:
set_resilient_tasks_enabled(True) # required for hosted environment
server = ResponsesHostServer(_build_concierge())
server.run()
```

```bash
azd deploy contoso-travel-concierge
```

**Prevent.** The `azure-ai-agentserver-core` package is a transitive dependency
of `agent-framework-foundry-hosting`; no extra entry in `requirements.txt` is
needed. If the workshop `requirements.txt` pins `agent-framework-foundry-hosting`
to a minimum version, bump the lower bound past the version that introduced this
requirement to catch regressions in CI.

---

## Auth & RBAC

### Missing RBAC roles for hosted-agent deploy
Expand Down
14 changes: 13 additions & 1 deletion labs/fundamentals/05-deploy-hosted-agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,19 @@ host). You'll enable both below.
> ```
>
> The script auto-discovers the RG, Foundry account, and project, then binds
> them into an `azd env` named `contoso-travel`. Idempotent — safe to re-run.
> them into an `azd env` named `contoso-travel`. Verify the project metadata
> before provisioning:
>
> ```bash
> azd env get-values | grep -E \
> "AZURE_AI_PROJECT_(NAME|ID|ENDPOINT)|FOUNDRY_PROJECT_ENDPOINT"
> azd ai project show
> ```
>
> `AZURE_AI_PROJECT_NAME` must contain only the child name (for example,
> `contoso-travel-project`), not `account/project`. The project ID and both
> endpoint values must also be present, and `azd ai project show` must resolve
> the same endpoint. The linker is idempotent and safe to re-run.
> **Skip this if you did Lab 01 (`azd`) already.**

1. **Make sure the hosted-agents extension is installed.**
Expand Down
27 changes: 21 additions & 6 deletions scripts/link-portal-rg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ az account show >/dev/null 2>&1 || {
echo "❌ 'az' is not logged in. Run: az login --use-device-code"; exit 1; }

# --- discover the RG + Foundry resources -----------------------------------
LOC=$(az group show -n "$RG" --query location -o tsv 2>/dev/null) || {
RG_LOC=$(az group show -n "$RG" --query location -o tsv 2>/dev/null) || {
echo "❌ Resource group '$RG' not found in the current subscription."
echo " Pass a different name: ./scripts/link-portal-rg.sh <rg-name>"
exit 1
Expand All @@ -44,10 +44,17 @@ if [[ -z "$ACCT" || "$ACCT" == "null" ]]; then
exit 1
fi

# Project name — best-effort. Older API versions omit the 'project list' verb;
# in that case the workshop uses the default pattern 'ai-project-<env>'.
PROJ=$(az cognitiveservices account project list \
-g "$RG" --name "$ACCT" --query "[0].name" -o tsv 2>/dev/null || true)
# Project metadata — best-effort. Azure returns the name as 'account/project',
# while Bicep expects only the child project name.
PROJ_JSON=$(az cognitiveservices account project list \
-g "$RG" --name "$ACCT" --query "[0]" -o json 2>/dev/null || true)
[[ -n "$PROJ_JSON" ]] || PROJ_JSON='{}'
PROJ_QUALIFIED=$(jq -r '.name // empty' <<<"$PROJ_JSON")
PROJ="${PROJ_QUALIFIED##*/}"
PROJ_ID=$(jq -r '.id // empty' <<<"$PROJ_JSON")
PROJ_ENDPOINT=$(jq -r '.properties.endpoints["AI Foundry API"] // empty' <<<"$PROJ_JSON")
PROJ_LOC=$(jq -r '.location // empty' <<<"$PROJ_JSON")
LOC="${PROJ_LOC:-$RG_LOC}"

# --- bind the azd env ------------------------------------------------------
if azd env list -o json 2>/dev/null | jq -e ".[] | select(.Name==\"$ENV\")" >/dev/null; then
Expand All @@ -61,6 +68,14 @@ azd env set AZURE_RESOURCE_GROUP "$RG"
azd env set AZURE_LOCATION "$LOC"
azd env set AZURE_AI_ACCOUNT_NAME "$ACCT"
[[ -n "$PROJ" && "$PROJ" != "null" ]] && azd env set AZURE_AI_PROJECT_NAME "$PROJ"
if [[ -n "$PROJ_ID" && "$PROJ_ID" != "null" ]]; then
azd env set AZURE_AI_PROJECT_ID "$PROJ_ID"
azd env set AZURE_AI_FOUNDRY_PROJECT_ID "$PROJ_ID"
fi
if [[ -n "$PROJ_ENDPOINT" && "$PROJ_ENDPOINT" != "null" ]]; then
azd env set AZURE_AI_PROJECT_ENDPOINT "$PROJ_ENDPOINT"
azd env set FOUNDRY_PROJECT_ENDPOINT "$PROJ_ENDPOINT"
fi
azd env set USE_EXISTING_AI_PROJECT true
azd env set AI_PROJECT_DEPLOYMENTS "[]" # sidestep the JSON-escape gotcha in Lab 05

Expand All @@ -71,7 +86,7 @@ echo " Foundry account: $ACCT"
[[ -n "$PROJ" && "$PROJ" != "null" ]] && echo " Foundry project: $PROJ"
echo ""
echo "Values now set (subscription id truncated for readability):"
azd env get-values | grep -E "^(AZURE_(SUBSCRIPTION_ID|RESOURCE_GROUP|LOCATION|AI_ACCOUNT_NAME|AI_PROJECT_NAME))|^USE_EXISTING_AI_PROJECT|^AI_PROJECT_DEPLOYMENTS" \
azd env get-values | grep -E "^(AZURE_(SUBSCRIPTION_ID|RESOURCE_GROUP|LOCATION|AI_ACCOUNT_NAME|AI_PROJECT_NAME|AI_PROJECT_ID|AI_FOUNDRY_PROJECT_ID|AI_PROJECT_ENDPOINT)|FOUNDRY_PROJECT_ENDPOINT)|^USE_EXISTING_AI_PROJECT|^AI_PROJECT_DEPLOYMENTS" \
| sed -E 's|(AZURE_SUBSCRIPTION_ID=")([^"]{4})[^"]*(")|\1\2…\3|'
echo ""
echo "Next: run Lab 05 Step 2 (azd provision) — it will reuse '$RG' instead of"
Expand Down
4 changes: 3 additions & 1 deletion specs/course.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ phases:
loop_node: deploy
time_min: 15
prereqs: ["fundamentals/03-deploy-models"]
produces: [{type: config, name: hosted-agent-endpoint}]
produces:
- {type: config, name: portal-azd-project-link}
- {type: config, name: hosted-agent-endpoint}
consumes: []
- id: "06-verify"
title: Smoke-test both agents
Expand Down
2 changes: 2 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from agent_framework import Agent, tool
from agent_framework.foundry import FoundryChatClient
from agent_framework_foundry_hosting import ResponsesHostServer
from azure.ai.agentserver.core.tasks import set_resilient_tasks_enabled
from azure.identity import DefaultAzureCredential
from dotenv import load_dotenv
from pydantic import Field
Expand Down Expand Up @@ -231,6 +232,7 @@ def _build_concierge() -> Agent:


def main() -> None:
set_resilient_tasks_enabled(True) # required for hosted environment
server = ResponsesHostServer(_build_concierge())
server.run()

Expand Down
91 changes: 91 additions & 0 deletions tests/test_link_portal_rg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""Portal-first linker writes canonical Foundry project metadata."""
from __future__ import annotations

import os
import subprocess
from pathlib import Path

from conftest import REPO_ROOT


LINKER = REPO_ROOT / "scripts" / "link-portal-rg.sh"


def _write_executable(path: Path, content: str) -> None:
path.write_text(content)
path.chmod(0o755)


def test_linker_normalizes_project_name_and_sets_project_metadata(tmp_path):
bin_dir = tmp_path / "bin"
bin_dir.mkdir()
azd_log = tmp_path / "azd.log"

_write_executable(
bin_dir / "az",
"""#!/usr/bin/env bash
set -euo pipefail
case "$*" in
"account show") echo '{}' ;;
"account show --query id -o tsv") echo '00000000-0000-0000-0000-000000000000' ;;
"group show -n rg-test --query location -o tsv") echo 'eastus' ;;
"cognitiveservices account list -g rg-test --query "*) echo 'foundry-test' ;;
"cognitiveservices account project list -g rg-test --name foundry-test --query [0] -o json")
cat <<'JSON'
{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-test/providers/Microsoft.CognitiveServices/accounts/foundry-test/projects/travel-project","location":"eastus2","name":"foundry-test/travel-project","properties":{"endpoints":{"AI Foundry API":"https://foundry-test.services.ai.azure.com/api/projects/travel-project"}}}
JSON
;;
*) echo "unexpected az command: $*" >&2; exit 1 ;;
esac
""",
)
_write_executable(
bin_dir / "azd",
"""#!/usr/bin/env bash
set -euo pipefail
case "$*" in
"env list -o json") echo '[]' ;;
"env new test-env --no-prompt") ;;
"env set "*) printf '%s\n' "$*" >> "$AZD_LOG" ;;
"env get-values")
cat <<'VALUES'
AZURE_SUBSCRIPTION_ID="00000000-0000-0000-0000-000000000000"
AZURE_RESOURCE_GROUP="rg-test"
AZURE_LOCATION="eastus2"
AZURE_AI_ACCOUNT_NAME="foundry-test"
AZURE_AI_PROJECT_NAME="travel-project"
AZURE_AI_PROJECT_ID="project-id"
AZURE_AI_FOUNDRY_PROJECT_ID="project-id"
AZURE_AI_PROJECT_ENDPOINT="project-endpoint"
FOUNDRY_PROJECT_ENDPOINT="project-endpoint"
USE_EXISTING_AI_PROJECT="true"
AI_PROJECT_DEPLOYMENTS="[]"
VALUES
;;
*) echo "unexpected azd command: $*" >&2; exit 1 ;;
esac
""",
)

env = os.environ.copy()
env["PATH"] = f"{bin_dir}:{env['PATH']}"
env["AZD_LOG"] = str(azd_log)
result = subprocess.run(
[str(LINKER), "rg-test", "test-env"],
cwd=REPO_ROOT,
env=env,
capture_output=True,
text=True,
)

assert result.returncode == 0, result.stderr
writes = azd_log.read_text().splitlines()
assert "env set AZURE_LOCATION eastus2" in writes
assert "env set AZURE_AI_PROJECT_NAME travel-project" in writes
assert not any("foundry-test/travel-project" in write for write in writes)
project_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-test/providers/Microsoft.CognitiveServices/accounts/foundry-test/projects/travel-project"
assert f"env set AZURE_AI_PROJECT_ID {project_id}" in writes
assert f"env set AZURE_AI_FOUNDRY_PROJECT_ID {project_id}" in writes
endpoint = "https://foundry-test.services.ai.azure.com/api/projects/travel-project"
assert f"env set AZURE_AI_PROJECT_ENDPOINT {endpoint}" in writes
assert f"env set FOUNDRY_PROJECT_ENDPOINT {endpoint}" in writes
Loading