agentleFS
MicrosoftKnown publishermicrosoft-foundry/foundry-agent-webapp/.github/copilot-instructions.md

foundry-agent-webapp

Copilot instructions128 starsChanged 7 months agoMITView on GitHub

Azure AI Foundry Agent Service sample app — Entra ID auth, SSE streaming, Container Apps deployment. Key Flow: React → MSAL token → POST /api/chat/stream → AI Foundry → SSE chunks → UI azd up phases: preprovision → provision (Bicep) → postprovision → predeploy → deploy What's intentionally CLI (not Bicep): - Entra redirect URI + identifierUri update — Entra app is created by Bicep (infra/entra-app.bicep), but identifierUri (api://{appId}) can't reference the auto-generated appId in the same declaration, and redirect…

The file

Files
copilot-instructions.md

Azure AI Foundry Agent Service sample app — Entra ID auth, SSE streaming, Container Apps deployment.

Architecture

LayerTechPortEntry Point
FrontendReact 19 + Vite5173frontend/src/App.tsx
BackendASP.NET Core 98080backend/WebApp.Api/Program.cs
AuthMSAL.js → JWT Bearer—frontend/src/config/authConfig.ts
AI SDKAzure.AI.Projects (GA) + Azure.AI.Extensions.OpenAI—backend/.../AgentFrameworkService.cs
DeployAzure Container Apps—infra/main.bicep

Key Flow: React → MSAL token → POST /api/chat/stream → AI Foundry → SSE chunks → UI

Design Decisions

  • Single container — Backend serves API (/api/*) and React SPA from wwwroot, deployed as one Container App resource.
  • Credential strategy — Production: ManagedIdentityCredential (user-assigned MI) or OnBehalfOfCredential (OBO) — mutually exclusive, controlled by ENTRA_BACKEND_CLIENT_ID env var. Development: ChainedTokenCredential(AzureCliCredential, AzureDeveloperCliCredential).
  • OBO admin consent — AIProjectClient scope https://ai.azure.com/.default resolves to Azure Machine Learning Services (appId 18a66f5f-...). Admin consent must target this service principal.
  • OBO scope — OnBehalfOfCredential authenticates Agent Service API calls. Agent tools (MCP, OpenAPI, Logic Apps) use the agent's own identity from Foundry portal.
  • User-assigned MI — Created in the infrastructure module; used for ACR pull (AcrPull role) and reused for OBO FIC when enabled.
  • .npmrc — Configures --legacy-peer-deps for React 19 peer-dep resolution. Run npm install from frontend/ directory.
  • Observability — Separate Application Insights resources for backend (OpenTelemetry via Azure.Monitor.OpenTelemetry.AspNetCore) and frontend (@microsoft/applicationinsights-web), sharing one Log Analytics workspace. Backend connection string is an env var; frontend connection string is injected at Docker build time via VITE_APPLICATIONINSIGHTS_CONNECTION_STRING.

Deployment (Non-Obvious)

azd up phases: preprovision → provision (Bicep) → postprovision → predeploy → deploy

What's intentionally CLI (not Bicep):

  • Entra redirect URI + identifierUri update — Entra app is created by Bicep (infra/entra-app.bicep), but identifierUri (api://{appId}) can't reference the auto-generated appId in the same declaration, and redirect URIs need the Container App FQDN which isn't available until after provision. Both are set in postprovision.ps1.
  • Federated Identity Credential (FIC) — FIC is a child of the backend app registration. Graph API eventual consistency causes the FIC to fail when created in the same Bicep deployment as its parent app. Created in postprovision.ps1 after Graph has replicated.
  • AI Foundry discovery — Discovers user's existing external AI Foundry resource via az cognitiveservices account list. This is a data-plane discovery operation, not resource deployment.
  • Cross-RG RBAC — Done via CLI so azd down only deletes our resource group, not the external AI Foundry resources.
  • Entra app deletion — Microsoft Graph resources are not tied to Azure resource groups; azd down (which deletes the RG) won't clean them up. postdown.ps1 handles this.

Health probes are conditional: disabled when placeholder image is deployed (first provision), enabled when real image exists.

Service Management Reference: Some orgs (notably Microsoft) require this on Entra app registrations. Set via azd env set ENTRA_SERVICE_MANAGEMENT_REFERENCE <guid> before running azd up; Bicep passes it to the Microsoft Graph extension.

Documentation Rules

  • Reference *.csproj or package.json for versions — keep docs version-free
  • State current behavior — not how we got here
  • State each fact once, cross-reference elsewhere
  • Document only non-obvious behavior that cannot be inferred from code

Development

# Ctrl+Shift+B → "Start Dev (VS Code Terminals)"
# Or: azd up

Hooks

HookEventWhat It Does
Commit GatepreToolUseBlocks direct git commit. Follow committing-code skill → commit via -F COMMIT_MESSAGE.md.
Test ReminderpreToolUseAdvisory: reminds to run tests if test files exist for staged changes.
Doc SyncpostToolUseReminds to update ARCHITECTURE-FLOW.md when architecture-sensitive files are edited.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.