Challenge 4 - Build the Claims Workflow with Agent Framework and Deploy It as a Hosted Agent¶
Home | Challenge 3 | Challenge 5 | Challenge 6
Expected Duration: 45 minutes (+ 20 minutes for the optional deployment)
Overview¶
Challenges 2 and 3 created the intake and intelligence agents. This challenge connects them with Microsoft Agent Framework's workflow support. The workflow is a graph: each node does one job and each edge says where the result goes next.
The intake agent retrieves the indexed accident statement. The intelligence agent retrieves the policy, then evaluates coverage using that policy and the claim details. The graph routes an escalated or low-confidence decision to a human reviewer before returning the final result.
You will:
- Inspect the graph and its routing logic.
- Run claims locally and inspect the coverage decision.
- Respond to a human-review request when the workflow pauses.
- Optionally inspect the local server with the Foundry Toolkit and deploy it as a hosted agent.
The workflow reuses claims-intake-agent and claims-intelligence-agent; it does not
create replacement agents or copy their stored instructions. After this challenge,
continue to Challenge 5 to observe and evaluate the agent calls.
The two Foundry agents are nodes of the graph. The small nodes between them only build the
next prompt from the previous answer. The route node decides which branch runs.
Note
The workflow reads the accident statement from the index populated in Challenge 2. If you pass an image path, only its file name is used to find the indexed statement, so the image must already be indexed. This command does not upload the image or run OCR.
Prerequisites¶
In this page, workshop root means the root of your cloned repository, containing
azure.yaml, pyproject.toml, docs/, and agent-framework/.
- Complete Challenge 2 and Challenge 3. Both agents must exist, and the crash statements must be indexed.
- Use the standard Python environment (
uv sync) from the earlier challenges for Tasks 1-3. The optional local hosting server in Task 4 needs a separate Python 3.11 environment because its hosting adapter uses a newer Agent Framework.
Starting directly at Challenge 4 (optional setup)
Use this section if you are joining here, using a fresh checkout, or have deleted your local environments. These are the prerequisites that would already be in place if you had followed Challenges 1-3. A fresh local setup does not recreate the Azure agents or their indexed data.
Azure prerequisites from Challenges 1-3 (expand to check before starting)
| Earlier challenge | What must already exist | How to check |
|---|---|---|
| Challenge 1 | Access to the correct subscription, resource group, and Foundry project, with its model deployment (the lab uses gpt-5.4), Azure AI Search service, and Storage policy documents |
Open the assigned project in the Foundry portal; obtain its project endpoint, tenant ID, and subscription ID from your coach or existing deployment |
| Challenge 2 | claims-intake-agent, a populated crash-statements search index, and its configured retrieval tool/connection |
Check Agents in Foundry and the Search index; crash1_front.jpeg and crash3_front.jpeg must be indexed for the examples below |
| Challenge 3 | claims-intelligence-agent, the policies-kb knowledge base, and working policy retrieval connections |
Check Agents and its tools; verify that COMP-AUTO-001 can be retrieved from the policy knowledge base |
| Access | Your signed-in user can invoke both agents, and their configured connections can access the data | Have Foundry User on the project (or equivalent permissions); being able to see a resource group alone does not grant agent access |
The workflow reuses these two agents; it does not create them, index documents, or repair retrieval connections. If any item is missing, complete the linked challenge or ask your coach for a prepared project before proceeding. The local workflow reads indexed statements, so it does not need to run Mistral OCR again.
1. Open the correct folder and install local tools¶
Open the cloned repository root, not just agent-framework/ or docs/. It contains
pyproject.toml, uv.lock, .env.example, azure.yaml,
docs/, and agent-framework/.
You need Python 3.11, uv,
and Azure CLI.
The Claims Hack Codespace supplies these tools. For a local workstation, install them
first. VS Code with the Foundry Toolkit is only required for the optional Inspector
and Toolkit deployment steps; azd is only needed if you choose the azd deployment route.
Neither Docker nor a hosted-agent deployment is required to run the local CLI.
2. Create and activate the participant environment¶
Run from the workshop root:
uv sync --refresh --python 3.11 --default-index https://pypi.org/simple
source .venv/bin/activate
python --version
uv sync --refresh --python 3.11 --default-index https://pypi.org/simple
.\.venv\Scripts\Activate.ps1
python --version
The Python version must be 3.11.x. This installs the pinned root dependencies for
Tasks 1-3 and Challenges 5-6. Do not install agent-framework/requirements.txt
into this environment: Task 4 creates a separate hosting environment with different
package versions.
In a new terminal, return to this folder and activate .venv again. Avoid bare
uv run while the hosting environment is active: it may select the root project
environment instead of the hosting environment.
3. Sign in to the existing Azure environment¶
Replace the placeholders with the tenant and subscription that own your lab:
az login --use-device-code --tenant "<tenant-id>"
az account set --subscription "<subscription-id>"
The CLI uses DefaultAzureCredential, which can use your Azure CLI login.
Use the same lab identity that has access to the two prompt agents. See
Azure Identity authentication
for credential-chain behavior.
4. Restore the workshop-root environment file¶
If you still have a valid .env, keep it. If it was deleted, choose one method:
Existing Claims MicroHack deployment: from the workshop root, regenerate the configuration as in Challenge 1. In Bash/zsh:
bash labautomation/get-keys.sh --resource-group "<your-resource-group-name>"
In PowerShell:
.\labautomation\get-keys.ps1 -ResourceGroup "<your-resource-group-name>"
This replaces the root .env. It requires permission to read deployment outputs and
list resource keys, even though the workflow itself only needs agent invocation
permissions. Both scripts write the same file. It does not redeploy Azure resources or
recreate the two agents.
Alternatively, use the manual method below.
Existing prepared Foundry project / no key-list permissions: copy the template
only if .env does not exist:
cp -n .env.example .env
if (-not (Test-Path .env)) { Copy-Item .env.example .env }
Edit the workshop-root .env in VS Code. For the local workflow, set both
endpoint entries to the same existing project endpoint, not the resource endpoint:
FOUNDRY_PROJECT_ENDPOINT=https://<foundry-resource>.services.ai.azure.com/api/projects/<project-name>
AI_FOUNDRY_PROJECT_ENDPOINT=https://<foundry-resource>.services.ai.azure.com/api/projects/<project-name>
HUMAN_REVIEW_CONFIDENCE_THRESHOLD=0.9
The workflow uses the existing agents' deployed models and retrieval connections.
The local CLI does not need Search keys, a Storage connection string, or a Mistral key.
Those other template values are needed only if you rerun earlier setup scripts.
If your prepared agents use different names, also set CLAIMS_INTAKE_AGENT_NAME and
CLAIMS_INTELLIGENCE_AGENT_NAME in .env.
Keep this file local; do not commit credentials.
5. Check imports, then run an indexed claim¶
From the workshop root, with .venv active:
python -c "from agent_framework import WorkflowBuilder; from agent_framework.foundry import FoundryAgent; from azure.identity.aio import DefaultAzureCredential; from dotenv import load_dotenv; print('Local imports OK')"
python docs/claims-framework-workflow.py --help
cd docs
python claims-framework-workflow.py --indexed-claim crash1 --policy COMP-AUTO-001
Imports and --help are offline checks; they do not prove Azure access or retrieval
works. The final command calls the existing agents, consumes model tokens, and may
pause for human review. Answer approve, escalate, or deny if requested.
If it fails with 401/403, check the signed-in tenant and project permissions.
If it cannot find a statement or policy, revisit the Challenge 2/3 prerequisites.
After this check, return to the workshop root with cd .. and continue with Task 1.
Task 2 starts with cd docs; do not run that command a second time while already in
docs.
Tasks¶
Task 1: Look at the workflow (no action needed)¶
Open agent-framework/workflow.py. It has three kinds of building blocks:
| Part | What it is |
|---|---|
FoundryAgent(...) |
Connects to an existing Foundry agent by name. The workflow uses the agents from Challenges 2 and 3. |
Executor classes (Prepare, PolicyPrompt, ...) |
Small nodes. Each receives the previous result, does one step, and sends a message on. |
WorkflowBuilder(...).add_edge(a, b) |
The edges. A condition= on an edge picks the branch, as route does for human review. |
Important
Do not modify the workflow code. It uses the policy and decision instructions that are
already stored in claims-intelligence-agent.
Task 2: Run the workflow locally¶
From the workshop root, enter docs and run the comprehensive-policy example.
The file name identifies the indexed accident statement, and --policy COMP-AUTO-001
selects the comprehensive policy for coverage evaluation:
cd docs
python claims-framework-workflow.py ../data/claims/crash1/raw/statements/crash1_front.jpeg --policy COMP-AUTO-001
The runner accepts these inputs:
| Argument | What it controls |
|---|---|
| Image path | Identifies an already-indexed statement by file name; does not upload or OCR the image |
--indexed-claim |
Identifies an indexed statement directly, for example crash1; use this instead of an image path |
--policy |
Overrides the policy number retrieved from the statement; omit it to use the statement's policy |
--claim-id |
Sets the claim identifier in the result (default: CLM-2026-001) |
--amount |
Sets the amount to evaluate against coverage limits and deductibles (default: 15000 USD) |
Run these examples from docs to exercise different inputs:
# default liability-only denial path
python claims-framework-workflow.py ../data/claims/crash1/raw/statements/crash1_front.jpeg
# override claim id and amount
python claims-framework-workflow.py ../data/claims/crash1/raw/statements/crash1_front.jpeg --policy COMM-AUTO-001 --claim-id CLM-2026-007 --amount 28000
# an indexed claim by reference
python claims-framework-workflow.py --indexed-claim crash1 --policy COMP-AUTO-001
The first example without --policy uses the statement's liability-only policy and
should deny own-vehicle collision damage. The commercial-policy example tests a different
policy and claimed amount. The indexed-reference example retrieves the statement without
requiring a local image path.
The console reports intake as Step 1 and intelligence processing as Step 2, then prints
the result JSON. Check status, the retrieved policy_info, and coverage_decision,
including its reasoning, deductible, and approved amount. If review is required,
Step 3 waits for your response before printing the final decision.
Task 3: Complete human-in-the-loop review when requested¶
If the intelligence agent escalates, or its confidence is below the threshold (0.90, or
HUMAN_REVIEW_CONFIDENCE_THRESHOLD in the workshop-root .env), the workflow pauses at the
human_review node:
[Step 3] Human review requested...
Decision status: APPROVED | confidence: 0.74 | threshold: 0.90
Workflow paused. Waiting for human-in-the-loop input.
Type 'approve' to accept, 'escalate' for manual review, or 'deny' to override.
Enter one of these reviewer actions:
approveaccepts the agent's original statusescalatesets the final status toESCALATEDdenyoverrides the final status toDENIED
An answer can be followed by a comment (deny missing police report), which is stored in
human_review.comment. Any other answer asks again.
The workflow keeps the review request as data instead of blocking on the keyboard. That is what lets the same workflow wait for a reviewer when it runs as a hosted agent in Task 5.
Important
Run the command in an interactive terminal so you can answer a review request. A non-interactive run fails explicitly if review is required.
Task 4: Test the local workflow server (optional)¶
Use either VS Code with Agent Inspector or the terminal client script below. Both send requests to the same local Responses API server. VS Code is not required for the script path. Unlike Tasks 2-3, which call the graph directly, this task tests the HTTP hosting layer used by the deployed hosted agent.
Start the server (both paths)¶
- Keep the workshop-root
.envand Azure CLI login from the earlier tasks. -
In a new terminal at the workshop root, create a separate environment for hosting (it needs a newer Agent Framework than the other challenges):
cd agent-framework python3.11 -m venv .venv source .venv/bin/activate pip install -r requirements-dev.txtSet-Location agent-framework py -3.11 -m venv .venv .\.venv\Scripts\Activate.ps1 pip install -r requirements-dev.txt -
From
agent-framework, with its.venvactive, start the server:python main.pyLeave this terminal running. The server must be listening on port
8088before you use either client below. Do not start a second server on the same port.💡 Why
ResponsesHostServermatters1. One workflow, two ways to call it¶
Tasks 2-3 call the graph directly in Python.
main.pymakes that same graph available over HTTP withResponsesHostServer:ResponsesHostServer( workflow=create_workflow, parse_response=parse_response, checkpoint_store_provider=CheckpointStoreProvider(), ).run(port=int(os.getenv("PORT", "8088")))2. What each part does¶
create_workflowbuilds a fresh intake-to-review graph for each request. Foundry prompt agents can finish asynchronously; the graph waits for each completed response before moving to the next step.parse_responsedistinguishes a new claim from a review answer.CheckpointStoreProviderlinks a paused review to its own claim, instead of sharing another claim's pending review.ResponsesHostServer(...).run(...)serves/responseson port8088(orPORT) without custom HTTP handlers.
3. Why you'll use it¶
- Local test: Agent Inspector and
invoke-hosted-claims-workflow.py --localsend requests to the server instead of importing Python code. - Human review: the server returns a
request_infocall; the client sendsfunction_call_outputwith thecall_id,previous_response_id, and the sameagent_session_idso it resumes the right claim. The client, not the server terminal, collects the reviewer's answer. - Hosted agent (Task 5): the hosted agent runs the same
main.py. Foundry routes requests using theresponsesprotocol inazure.yaml.
Local is not deployed: starting the server creates no Azure resource. It still needs Azure access for the existing Foundry agents; keep it running while testing and stop it with
Ctrl+C. The adapter alone does not provide durable recovery after a local server restart; resume a paused review before stopping the server.4. LangChain/LangGraph equivalent (optional)¶
The commented example in
main.pyusesResponsesHostServerfromlangchain_azure_ai.agents.hostingto serve a compiled LangGraph graph directly. Clients still call/responses. This is not an automatic conversion: it needs separate dependencies, and human-review payloads need a different client. See the official LangChain/LangGraph hosting guide if you want to try it.
Test with VS Code and Agent Inspector¶
- Open the workshop root in VS Code and install the Foundry Toolkit extension.
- With the server running, open the Command Palette and run
Foundry Toolkit: Open Agent Inspector. Select the local server at
http://localhost:8088if prompted. -
Send this request in the Inspector:
--indexed-claim crash3 --policy COMP-AUTO-001 -
Inspect the final decision or pending
request_infofunction call. Review controls depend on your Toolkit version. To test the complete interactive review flow reliably, use the terminal script below. It starts its own claim run; it does not attach to or resume a run started in Agent Inspector.
Optional local tracing: start the Toolkit trace collector, stop the workflow server
with Ctrl+C, and restart it with the collector's OTLP endpoint (use the port shown by
your Toolkit):
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 \
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf python main.py
$env:OTEL_EXPORTER_OTLP_ENDPOINT = "http://localhost:4318"
$env:OTEL_EXPORTER_OTLP_PROTOCOL = "http/protobuf"
python main.py
Trace and graph views depend on your Toolkit version and instrumentation; opening Agent Inspector alone does not enable trace export. Local workflow spans and remote prompt-agent traces can be separate.
Test with the terminal client script (no VS Code required)¶
-
Keep the server running in the first terminal. Open a second, interactive terminal at the workshop root. Activate the hosting environment and run the client:
source agent-framework/.venv/bin/activate python docs/invoke-hosted-claims-workflow.py --local --indexed-claim crash3 --policy COMP-AUTO-001.\agent-framework\.venv\Scripts\Activate.ps1 python docs/invoke-hosted-claims-workflow.py --local --indexed-claim crash3 --policy COMP-AUTO-001 -
--localsends the request tohttp://localhost:8088/responses; it does not call a deployed hosted agent. The server still invokes your existing Foundry prompt agents. - If review is requested, enter
approve,escalate, ordenyin the client terminal. The script returns your answer through the API and prints the final decision. The server terminal only shows server activity; it does not ask for reviewer input.
Force human review for a local test¶
To force the review branch for testing, stop the server if it is running, then restart it
from the agent-framework directory with the threshold set for that process:
HUMAN_REVIEW_CONFIDENCE_THRESHOLD=1.01 python main.py
$env:HUMAN_REVIEW_CONFIDENCE_THRESHOLD = "1.01"
python main.py
This threshold forces every valid confidence score below 1.01 into human review.
Run the terminal client command above again and answer the review prompt.
After testing, stop the server and restart with python main.py to use the
threshold from .env (default: 0.90). The Bash/zsh assignment applies only
to that server process. In PowerShell, clear the session override first:
Remove-Item Env:HUMAN_REVIEW_CONFIDENCE_THRESHOLD
Run offline tests¶
In a terminal with the hosting environment active, run from agent-framework:
pytest
These tests use fake agents and need neither Azure access nor a running server.
Task 5: Deploy the workflow as a hosted agent¶
A hosted agent runs your code in a managed runtime inside your Foundry project. Choose one packaging method and one deployment tool; you do not need to deploy twice.
| Method | What you supply | What builds/runs it | Use it when |
|---|---|---|---|
Container (current azure.yaml) |
agent-framework/Dockerfile and source |
ACR builds the Python 3.11 image; Foundry runs it | You want to keep this lab's runtime or control the image and system dependencies |
| Code ZIP (alternative below) | Source, requirements.txt, and codeConfiguration |
The tool uploads a ZIP; Foundry builds dependencies and runs the selected Python runtime | You want source deployment without managing a Dockerfile or ACR |
Both start agent-framework/main.py and expose the
same Responses API. The claim inputs and human-review client remain unchanged.
See the official container deployment
and source-code deployment
guides for availability and service prerequisites.
Important
Check these before you deploy:
- You need the Foundry Project Manager role on the Foundry project to create the agent.
- Run the deployment commands from the workshop root, where
azure.yamlis. The service's source directory isagent-framework/. - Deploying can incur charges. A successful upload does not prove readiness; wait for the agent version to become active and run the test below.
Choose the package: container or code ZIP¶
Follow one tab from configuration through deployment. Within that tab, use
either Foundry Toolkit or azd to deploy; then continue to the shared
access and test steps below.
Final azure.yaml for Container¶
This is the checked-in azure.yaml; leave it unchanged.
The highlighted lines select the Dockerfile and remote container build.
name: claims-framework
requiredVersions:
azd: '>=1.27.1'
extensions:
azure.ai.agents: '>=1.0.0-beta.9'
services:
ai-project:
host: azure.ai.project
endpoint: ${FOUNDRY_PROJECT_ENDPOINT}
deployments: []
claims-workflow-hosted:
name: ClaimProcessingWorkflow
project: agent-framework
host: azure.ai.agent
language: docker
kind: hosted
description: Claims workflow over the existing intake and intelligence prompt
agents, with human review.
docker:
path: Dockerfile
context: .
remoteBuild: true
uses:
- ai-project
protocols:
- protocol: responses
version: 2.0.0
container:
resources:
cpu: '0.5'
memory: 1.0Gi
env:
CLAIMS_INTAKE_AGENT_NAME: claims-intake-agent
CLAIMS_INTELLIGENCE_AGENT_NAME: claims-intelligence-agent
HUMAN_REVIEW_CONFIDENCE_THRESHOLD: '0.9'
infra:
provider: microsoft.foundry
What changes with Container?
ACR builds a Python 3.11 image from
agent-framework/Dockerfile; no local
Docker daemon is required. An Azure Container Registry (ACR) is
required: azd deploy cannot publish the image without one. Creating
an ACR incurs Azure charges. The Dockerfile installs requirements.txt,
so check that the remote builder can reach its package index.
Deploy with Foundry Toolkit (VS Code)¶
- Open the workshop root in VS Code. Install the Foundry Toolkit extension if needed, and sign in to Azure.
- Run Foundry Toolkit: Deploy Hosted Agent from the Command Palette. Select
your existing Foundry project and the workspace root containing
azure.yaml. - Choose Container. Select the default ACR or an appropriate existing ACR;
use the supplied Dockerfile and
agent-framework/as the build context. - Confirm the target project, agent name
ClaimProcessingWorkflow, Responses protocol, and resources. Deploy and wait for the version to become active. See the Toolkit deployment guide if your wizard looks different.
Or deploy with azd from the workshop root. Install
Azure Developer CLI
and select your Foundry project's subscription in Azure CLI. Follow your OS
commands below. The helper configures azd for your existing project
without copying secrets from .env.
Already have a claims-framework environment? Use
azd env select claims-framework instead of azd env new claims-framework.
source agent-framework/.venv/bin/activate
azd ext install azure.ai.agents
azd auth login
azd env new claims-framework
python docs/configure_azd_env.py
If you already have an ACR in the selected subscription, skip the
az acr create command. Otherwise, choose a globally unique, lowercase
registry name in place of youruniqueregistryname and create one
(Basic tier is billable). Use its login server as the endpoint:
az acr create --resource-group "$(azd env get-value AZURE_RESOURCE_GROUP -e claims-framework)" --name youruniqueregistryname --sku Basic
azd env set AZURE_CONTAINER_REGISTRY_ENDPOINT "$(az acr show --name youruniqueregistryname --query loginServer -o tsv)" -e claims-framework
azd deploy claims-workflow-hosted
For an existing ACR, replace youruniqueregistryname in the last
two commands with its name and run only azd env set and azd deploy.
If deployment reports [ImageError] Container registry authentication
failed, grant the Foundry project managed identity AcrPull on
that registry, then retry (Azure RBAC can take a few minutes):
az role assignment create --assignee-object-id "$(az resource show --ids "$(azd env get-value AZURE_AI_PROJECT_ID -e claims-framework)" --query identity.principalId -o tsv)" --assignee-principal-type ServicePrincipal --role AcrPull --scope "$(az acr show --name youruniqueregistryname --query id -o tsv)"
azd deploy claims-workflow-hosted
.\agent-framework\.venv\Scripts\Activate.ps1
azd ext install azure.ai.agents
azd auth login
azd env new claims-framework
python docs/configure_azd_env.py
If you already have an ACR in the selected subscription, skip the
az acr create command. Otherwise, choose a globally unique, lowercase
registry name in place of youruniqueregistryname and create one
(Basic tier is billable). Use its login server as the endpoint:
az acr create --resource-group "$(azd env get-value AZURE_RESOURCE_GROUP -e claims-framework)" --name youruniqueregistryname --sku Basic
azd env set AZURE_CONTAINER_REGISTRY_ENDPOINT "$(az acr show --name youruniqueregistryname --query loginServer -o tsv)" -e claims-framework
azd deploy claims-workflow-hosted
For an existing ACR, replace youruniqueregistryname in the last
two commands with its name and run only azd env set and azd deploy.
If deployment reports [ImageError] Container registry authentication
failed, grant the Foundry project managed identity AcrPull on
that registry, then retry (Azure RBAC can take a few minutes):
az role assignment create --assignee-object-id "$(az resource show --ids "$(azd env get-value AZURE_AI_PROJECT_ID -e claims-framework)" --query identity.principalId -o tsv)" --assignee-principal-type ServicePrincipal --role AcrPull --scope "$(az acr show --name youruniqueregistryname --query id -o tsv)"
azd deploy claims-workflow-hosted
Expect an image build and push. When the version is active, continue to Give the agent access to your project below.
🛠️ Container troubleshooting
| Symptom | What to check |
|---|---|
| Container publish cannot determine the registry endpoint | Create or select an ACR, then set AZURE_CONTAINER_REGISTRY_ENDPOINT to its loginServer using the commands above. |
Deployment fails with [ImageError] Container registry authentication failed |
Grant the Foundry project managed identity AcrPull on the ACR (commands above), wait for RBAC propagation, and redeploy. |
| Image build fails installing packages on a restricted network | Pass your mirror to the build: --build-arg PIP_INDEX_URL=<mirror>. |
Check compatibility and use the final azure.yaml¶
ZIP deployment supports Python 3.13 or 3.14, not the lab's Python 3.11 environment. Verify that the pinned packages and workflow work under Python 3.13 before choosing this path; otherwise use Container. You do not need to create a ZIP yourself or change the Python 3.11 environment for other labs.
Replace the workshop-root azure.yaml with this complete
file if you have not customized it. If you have, preserve your top-level
project settings and change only services.claims-workflow-hosted to match.
The highlighted lines select source packaging and Python 3.13.
name: claims-framework
requiredVersions:
azd: '>=1.27.1'
extensions:
azure.ai.agents: '>=1.0.0-beta.9'
services:
ai-project:
host: azure.ai.project
endpoint: ${FOUNDRY_PROJECT_ENDPOINT}
deployments: []
claims-workflow-hosted:
name: ClaimProcessingWorkflow
project: agent-framework
host: azure.ai.agent
language: python
kind: hosted
description: Claims workflow over the existing intake and intelligence prompt
agents, with human review.
codeConfiguration:
runtime: python_3_13
entryPoint: main.py
dependencyResolution: remote_build
uses:
- ai-project
protocols:
- protocol: responses
version: 2.0.0
container:
resources:
cpu: '0.5'
memory: 1.0Gi
env:
CLAIMS_INTAKE_AGENT_NAME: claims-intake-agent
CLAIMS_INTELLIGENCE_AGENT_NAME: claims-intelligence-agent
HUMAN_REVIEW_CONFIDENCE_THRESHOLD: '0.9'
infra:
provider: microsoft.foundry
What changes with Code ZIP?
codeConfiguration replaces docker; do not add an image setting.
The container.resources block sets compute, not the package type.
The tool uploads the contents of agent-framework/, with main.py,
workflow.py, and requirements.txt at the ZIP root; you do not make a
ZIP by hand. Review .agentignore
so local secrets, environments, caches, and tests stay out.
Azure installs dependencies remotely and does not inherit your pip settings or Dockerfile package index. For private dependencies, use a supported packaging approach; never put credentials or a macOS/Windows or Python 3.11 virtual environment in the ZIP.
Deploy with Foundry Toolkit (VS Code)¶
- Open the workshop root in VS Code. Install the Foundry Toolkit extension if needed, and sign in to Azure.
- Run Foundry Toolkit: Deploy Hosted Agent from the Command Palette.
Select your existing Foundry project and the workspace root containing
the edited
azure.yaml. - Choose Code, Remote package mode, Python 3.13, and the
main.pyentry point (python3 main.pyif asked for a startup command). Confirm the source directory isagent-framework/, not the workshop root. - Confirm the target project, agent name
ClaimProcessingWorkflow, Responses protocol, and resources. Deploy and wait for the version to become active. See the Toolkit deployment guide if your wizard looks different.
Or deploy with azd from the workshop root. Install
Azure Developer CLI
and select your Foundry project's subscription in Azure CLI. Follow your OS
commands below; ZIP deployment needs a current agents extension with
codeConfiguration support. The helper configures azd for your existing
project without copying secrets from .env.
Already have a claims-framework environment? Use
azd env select claims-framework instead of azd env new claims-framework.
source agent-framework/.venv/bin/activate
azd ext install azure.ai.agents
azd auth login
azd env new claims-framework
python docs/configure_azd_env.py
azd deploy claims-workflow-hosted
.\agent-framework\.venv\Scripts\Activate.ps1
azd ext install azure.ai.agents
azd auth login
azd env new claims-framework
python docs/configure_azd_env.py
azd deploy claims-workflow-hosted
No ACR or infrastructure provisioning is needed when deploying ZIP to your existing project. Expect source packaging and a remote dependency build. When the version is active, continue to Give the agent access to your project below.
🛠️ Code ZIP troubleshooting
| Symptom | What to check |
|---|---|
The output says Packaging container or builds through ACR |
Check the claims-workflow-hosted service has codeConfiguration and language: python, with no docker or image setting. |
| Dependency build or startup fails | Check Python 3.13 compatibility, remote package-feed access, and that main.py, workflow.py, and requirements.txt are at the ZIP root. The local Python 3.11 environment is not the ZIP runtime. |
Both configurations retain Responses version 2.0.0 and reference the
existing Foundry project without replacing its prompt agents or models.
The Toolkit may save participant-specific settings in the Git-ignored
.foundry/.deployment.json; the checked-in
placeholder example is not a
deployment configuration. Every successful deployment creates a new version
of ClaimProcessingWorkflow, not a second agent.
💡 Why did I run this step?
Why deploy at all. Running the workflow on your laptop proves the logic. A hosted agent runs the same code inside your Foundry project, with its own identity, so other people and services can call it without your machine.
Why azd and a single service name. azd records the environment values (project endpoint, subscription,
resource group) once and reuses them. azure.yaml decides whether the service is packaged as a container or a ZIP.
Why every deploy makes a new version. Foundry keeps each deployed version of the agent. Switching the packaging method for the same agent name creates a new version, not a second agent, so you can compare or roll back.
What to take away. A deployed agent is code plus configuration plus identity. Check each one when a run fails.
Give the agent access to your project¶
The hosted agent identity calls the existing intake and intelligence agents. If those calls fail with a permissions error, grant Foundry User to the hosted agent identity at the project scope. An HTTP 404 saying an agent version was not found is not a permissions error; redeploy the latest workflow code instead.
- In the Azure portal, open your Foundry project, then Access control (IAM).
- Add a role assignment: role Foundry User (previously named Azure AI User). When
selecting members, search for the hosted agent's identity,
ClaimProcessingWorkflow. You may need to wait a few minutes for RBAC to apply.
Alternatively, for an azd deployment, get the exact hosted agent principal
from azd ai agent show and assign the role without guessing an identity:
project_id="$(azd env get-value AZURE_AI_PROJECT_ID -e claims-framework)"
agent_principal="$(azd ai agent show claims-workflow-hosted -o json | python -c "import json,sys; print(json.load(sys.stdin)['instance_identity']['principal_id'])")"
az role assignment create --assignee-object-id "$agent_principal" --assignee-principal-type ServicePrincipal --role "Foundry User" --scope "$project_id"
$projectId = azd env get-value AZURE_AI_PROJECT_ID -e claims-framework
$agentPrincipal = azd ai agent show claims-workflow-hosted -o json | python -c "import json,sys; print(json.load(sys.stdin)['instance_identity']['principal_id'])"
az role assignment create --assignee-object-id $agentPrincipal --assignee-principal-type ServicePrincipal --role "Foundry User" --scope $projectId
If model inference also fails because the project managed identity has insufficient access to its parent Foundry account, grant that identity Foundry User at the account scope (usually set up when the project is created). This is separate from the hosted agent's project role:
project_id="$(azd env get-value AZURE_AI_PROJECT_ID -e claims-framework)"
project_principal="$(az resource show --ids "$project_id" --query identity.principalId -o tsv)"
az role assignment create --assignee-object-id "$project_principal" --assignee-principal-type ServicePrincipal --role "Foundry User" --scope "${project_id%/projects/*}"
$projectId = azd env get-value AZURE_AI_PROJECT_ID -e claims-framework
$projectPrincipal = az resource show --ids $projectId --query identity.principalId -o tsv
az role assignment create --assignee-object-id $projectPrincipal --assignee-principal-type ServicePrincipal --role "Foundry User" --scope ($projectId -replace '/projects/[^/]+$', '')
Assign roles only if missing; your Azure identity needs permission to create role assignments. If you deploy a new agent identity, repeat the hosted-agent role assignment for that identity.
💡 Why did I run this step?
Why the same inputs as the local run. Using the same claim and policy lets you compare the hosted result with the local result from Challenge 4. A difference points to the deployment, not the logic.
Why the script answers the review. A hosted run can pause for human review. The script sends the answer and continues the same run, the way a reviewer would in production. Without it, the run waits forever.
Why the agent name matters. The script calls a specific deployed agent. A typo or the azure.yaml key
sends the request to nothing, so use the exact name shown in Foundry.
What to take away. Test a deployed agent the way it will be used, with the same input, and check its logs when the result differs.
Test the hosted agent¶
Use the same inputs as before. This script calls the deployed agent and handles the review request:
cd docs
python invoke-hosted-claims-workflow.py --agent-name ClaimProcessingWorkflow --indexed-claim crash3 --policy COMP-AUTO-001
Note
If you deployed the hosted agent with another name, replace ClaimProcessingWorkflow
in --agent-name with that exact name. Use the name shown in Foundry (the service's
name: value), not the services: key used by azd.
To inspect a claim in the Foundry Toolkit or portal playground, start a new conversation and send:
--indexed-claim crash3 --policy COMP-AUTO-001
If review is requested, the playground shows a pending function call. Do not
send approve as another chat message: that is new workflow input, not a
review response, and fails input validation. Use the terminal client above in
an interactive terminal to complete review; it sends the required
function_call_output with the original call and session IDs. Start a new
playground conversation for another claim rather than reusing one awaiting
review. With azd, azd ai agent invoke sends a message, and
azd ai agent monitor streams the logs.
To test the same script against a local server instead, start python main.py as in Task 4
and add --local.
How the workflow operates¶
| Node | Foundry resource | Input | Output |
|---|---|---|---|
prepare |
none | claim request text | indexed statement lookup prompt |
intake_agent |
claims-intake-agent |
statement lookup prompt | statement summary with the policy number |
policy_prompt |
none | statement summary | policy extraction prompt |
policy_agent |
claims-intelligence-agent |
policy extraction prompt | policy JSON from the policy knowledge base |
decision_prompt |
none | policy JSON, claim details | coverage decision prompt |
decision_agent |
claims-intelligence-agent |
coverage decision prompt | decision JSON |
route |
none | decision JSON | claim result and the branch to take |
human_review |
none | escalated or low-confidence result | reviewer-confirmed or overridden status |
auto_finish |
none | confident result | final result |
Result fields¶
The workflow returns the following JSON fields. Challenge 6 consumes this decision before attempting protected downstream actions.
| Field | Meaning |
|---|---|
claim_id |
Identifier supplied with the request |
status |
Final APPROVED, DENIED, or ESCALATED result, after any human review |
policy_info |
Policy fields extracted from the knowledge base; effective/expiry dates and a retrieval score are not included |
coverage_decision |
Coverage outcome, approved amount, deductible, exclusions, reasoning, confidence, consistency, and escalation details |
errors |
Structured warnings when the agent requests escalation; may be empty |
human_review |
Present only when review ran; records the agent's original status, reviewer action, and optional comment |
The response does not include an audit_trail or intelligence_duration_ms.
When hosted review is pending, the server returns a request_info call carrying
the PENDING_HUMAN_REVIEW result; answering it resumes the workflow.
Validation checklist¶
- The console reports intake (Step 1) before intelligence processing (Step 2).
- The workflow reuses
claims-intake-agentandclaims-intelligence-agentwithout creating replacement agents. - The result includes the requested claim ID, retrieved policy, coverage reasoning, approved amount, and final status.
- The liability-only command returns
DENIEDwithcollisionorown_vehicle_damageinexclusions_matched. - A requested review pauses until a valid answer is entered, and an invalid answer asks again.
-
pytestpasses inagent-framework. - If you deployed: the hosted agent returns the same decision, and a review request can be answered.
🛠️ Troubleshooting
| Symptom | What to check |
|---|---|
Foundry hosted requests require a trusted user ID and call ID |
The deployed agent uses an old protocol version. Check that azure.yaml declares responses 2.0.0, then redeploy. |
Build fails with file not found for requirements.txt |
Deploy from the repository root; the service source/build folder is agent-framework/. |
Hosted run says Agent ... with version ... not found |
The hosted agent's version was passed to an existing prompt agent. Redeploy the updated workflow code; do not fix this 404 with a role assignment. |
Playground says Native workflow input validation failed on the first claim |
Redeploy the current code. Older versions rejected the playground's default options (such as tools: []), so main.py now ignores caller-supplied model options; the Foundry agents define their own. |
Playground says Native workflow input validation failed after review |
A plain-text reply such as approve cannot satisfy the pending function call. Complete review with the interactive terminal client, or start a new playground conversation for a new claim. |
No policy number found ... |
The statement is not indexed. Complete Challenge 2, or pass --policy. |
| The first hosted run fails with a permission error | Assign the Foundry User role to the hosted agent's identity (see above). |
Human review is required, but ... non-interactive terminal |
Run in an interactive terminal, or call the hosted agent and answer through the API. |
| The Inspector or server does not start | Run it with the agent-framework/.venv environment, not the lab environment. |
| Package install fails on a restricted network | Pass your mirror: pip install -r requirements-dev.txt --index-url <mirror>. |
Next step¶
Continue with Challenge 5, then Challenge 6.
For FIDES in Challenge 6, add --workflow framework to its commands.
Optional reference: manual sequential implementation
The manual sequential workflow calls the agents from a Python script instead of using a graph. It is a separate reference implementation, not a prerequisite or an additional task for this challenge.