RepoMicrosoftMicrosoftpublished Jun 3, 2026seen 5d

microsoft/Pharmcat-Foundry-Agent

Python

Open original ↗

Captured source

source ↗

microsoft/Pharmcat-Foundry-Agent

Language: Python

License: MIT

Stars: 0

Forks: 0

Open issues: 2

Created: 2026-06-03T16:51:39Z

Pushed: 2026-06-08T15:44:41Z

Default branch: main

Fork: no

Archived: no

README:

PharmCAT — Pharmacogenomics AI Foundry Agent

A web app that accepts a patient VCF file, runs it through the PharmCAT analysis API, and opens a streaming AI chat powered by an Azure AI Foundry agent for pharmacogenomics interpretation.

Architecture

Browser
│ upload VCF
▼
app/app.py (Flask)
│ forward VCF
├─────────────────► api/ (FastAPI + PharmCAT container)
│ returns phenotype JSON
│ profile text
◄─────────────────
│ upload phenotype JSON / user-delegation SAS
├─────────────────► Azure Blob Storage
│ stream chat
├─────────────────► Azure AI Foundry agent
│ └── Azure AI Search (RAG knowledge base)
│ citation page lookup
└─────────────────► Azure AI Search

Project Structure

app/ # Flask web UI (this service)
app.py # Routes, agent wiring, patient data extraction
requirements.txt # Python dependencies
Dockerfile # Container image (gunicorn, port 8000)
templates/index.html # Single-page chat UI
static/css/styles.css # Styles
static/favicon.ico # Microsoft favicon
.env.example # Environment variable template

api/ # PharmCAT analysis service (FastAPI + Docker)
main.py # REST API entry point
Dockerfile # Container image
requirements.txt # API dependencies

deploy/ # Azure deployment
deploy.bicep # Full infrastructure (ACR, Log Analytics, Container Apps, App Service, Foundry, Storage)
deploy.bicepparam.example # Param file template — copy to deploy.bicepparam and fill in values
deploy.ps1 # PowerShell deploy script (Windows)
deploy.sh # Bash deploy script (Linux / macOS / WSL)
agent-instructions.txt # System prompt for the Foundry agent (deployed by the scripts)

rag_files/ # KNMP pharmacogenetics source PDFs (git-ignored, not committed)

samples/ # Example input files
pharmcat.example.vcf
pharmcat.example.phenotype.json

scripts/ # Standalone CLI utilities
setup_rag.py # Build the AI Search RAG index from the KNMP PDF
call_api.py # POST a VCF to the PharmCAT API, save phenotype JSON
extract_patient_data.py # Extract the gene/phenotype table from a phenotype JSON
call_agent.py # Send a message to the Foundry agent directly (CLI testing)

Quick Start

1. Configure environment

cp app/.env.example app/.env

Edit app/.env:

FOUNDRY_PROJECT_ENDPOINT=https://your-resource.services.ai.azure.com/api/projects/your-project
FOUNDRY_AGENT_NAME=pharmcat-agent
FOUNDRY_AGENT_VERSION=1.0 # optional
PHARMCAT_API_URL=https://your-pharmcat-api.azurecontainerapps.io
PORT=8000 # optional, default 8000

Authentication uses DefaultAzureCredential. Run az login locally.

2. Create a virtual environment

python -m venv .venv

Activate it:

  • Windows: .venv\Scripts\activate
  • Linux / macOS / WSL: source .venv/bin/activate

3. Install dependencies

pip install -r app/requirements.txt

4. Run the app

cd app
python app.py

Open http://localhost:5000

> When running inside Docker the app listens on port 8000. Set PORT=8000 in .env to match.

Usage

1. Drop or browse to a .vcf file and click Start Analysis 2. The VCF is forwarded to the PharmCAT API — the gene/diplotype/phenotype profile loads as a card 3. Ask questions in the chat — the profile is sent as context on the first message 4. Click New Analysis to reset and upload a different file

API Routes

| Method | Path | Description | |--------|------|-------------| | GET | / | Serves the chat UI | | GET | /api/me | Returns the authenticated user (Easy Auth header) | | POST | /api/analyze | Accepts a VCF file, returns patient_profile text, gene_results array, and optional download_url | | POST | /api/chat/stream | Streaming SSE chat via the Foundry agent | | POST | /api/new-session | Clears the current agent session |

Azure Deployment

The deploy/ folder contains a complete Bicep template that provisions all infrastructure in a single command and two deploy scripts (PowerShell and Bash) that build the container images and run the deployment.

Resources provisioned by `deploy.bicep`:

| Resource | Notes | |---|---| | Azure Container Registry | Image store for API and App containers | | Log Analytics Workspace | Container Apps log sink | | Container Apps Environment | Shared environment for the API container | | pharmcat-api Container App | FastAPI + PharmCAT pipeline, port 8000 | | App Service Plan (Linux) | Compute plan for the Flask UI (default P0v3 PremiumV3) | | pharmcat-app App Service | Flask UI served from ACR container image, port 8000 | | Storage Account + 2 blob containers | pharmcat-results (phenotype JSON + SAS); pharmcat-rag (RAG source PDFs) | | Azure AI Foundry resource | Microsoft.CognitiveServices/accounts (kind: AIServices) | | Foundry project | Child project under the Foundry resource | | Model deployment | GPT-4.1 (configurable) for use by agents | | Embedding model deployment | text-embedding-3-large — used by AI Search integrated vectorizer | | Azure AI Search service | Hosts the KNMP pharmacogenetics RAG index (knmp-pharmacogenetics) | | Role assignments | AcrPull; Storage Blob Data Contributor (app, API, deployer); Azure AI User (app, deployer, Foundry project); Search Index Data Reader (app, Foundry project); Search Service Contributor (Foundry project); Cognitive Services OpenAI User (AI Search vectorizer); Storage Blob Data Reader (AI Search ingestion) |

> Note: The Foundry agent (instructions, tools, model config) cannot be created via Bicep — the deploy scripts create and update it automatically via the Foundry Agent Service API using deploy/agent-instructions.txt. The foundryAgentName param controls the agent name.

1. Prerequisites

  • Azure CLI with the containerapp extension
  • Logged in: az login
  • A resource group (the scripts create one if it does not exist)

2. Create the param file

cp deploy/deploy.bicepparam.example deploy/deploy.bicepparam

Edit deploy/deploy.bicepparam — it is git-ignored and never committed:

param prefix = 'pharmcat'
param containerRegistryName = 'yourregistryname' // globally unique, alphanumeric only
param aiFoundryName = 'yourfoundryname' // globally unique, becomes…

Excerpt shown — open the source for the full document.

Notability

notability 4.0/10

New repo from Microsoft, routine release.