This guide helps you set up a local development environment to test and modify the AI agents application. Make sure you first deployed the app to Azure before running the development server.
- Python 3.8 or later
- Node.js (v20 or later)
- pnpm
- An Azure deployment of the application (completed via
azd up)
Create a Python virtual environment and activate it:
On Windows:
python -m venv .venv
.venv\scripts\activateOn Linux:
python3 -m venv .venv
source .venv/bin/activateNavigate to the src directory and install Python packages:
cd src
python -m pip install -r requirements.txtNavigate to the frontend directory and setup for React UI:
cd src/frontend
pnpm run setupImportant: The environment variables are stored in the .azure/<environment-name>/.env file, not in the root or src directory. This file is automatically created when running azd up and contains all the Azure resource configuration needed for local development.
The application automatically loads environment variables from .env in .azure folder when running locally.
If you have changes in src/frontend, build the React application:
cd src/frontend
pnpm buildThe build output will be placed in the ../api/static/react directory, where the backend can serve it.
If you have changes in gunicorn.conf.py, test the agent configuration:
cd src
python gunicorn.conf.py Run the local development server:
cd src
python -m uvicorn "api.main:create_app" --factory --reloadClick 'http://127.0.0.1:8000' in the terminal, which should open a new tab in the browser. Enter your message in the box to test the agent.
VS Code provides two debug configurations for easy debugging:
- Debug: Initialize Agent (Gunicorn) - Runs
gunicorn.conf.pyto test agent initialization and configuration - Debug: FastAPI Server (Uvicorn) - Runs the FastAPI server with hot-reload for API development
- Click on the Run and Debug icon in the VS Code left sidebar
- Select the desired launch profile from the dropdown at the top
- Click the green Start Debugging button
- Set breakpoints in your code by clicking on the left margin of the editor
When debugging the FastAPI Server, you must specify the AZURE_EXISTING_AGENT_ID environment variable in your .azure/<environment-name>/.env file. This tells the application to use an existing agent instead of creating a new one.
Example:
AZURE_EXISTING_AGENT_ID="agent-template-assistant:1"If you want to modify the frontend application, the key component to understand is src/frontend/src/components/agents/AgentPreview.tsx. This component handles:
- Backend Communication: Contains the main logic for calling the backend API endpoints
- Message Handling: Manages the flow of user messages and agent responses
- UI State Management: Controls the display of conversation history and loading states
- Agent Interaction Flow: Modify how users interact with agents by updating the message handling logic in
AgentPreview.tsx - UI Components: Customize the chat interface, message bubbles, and response formatting
- API Integration: Extend or modify the backend communication patterns established in this component
- Make changes to React components in
src/frontend/src/ - Run
pnpm buildto compile the frontend - The build output is automatically placed in
../api/static/reactfor the backend to serve - Restart the local server to see your changes
Start with AgentPreview.tsx to understand how the frontend communicates with the backend and how messages are populated in the UI.
To customize agent instructions or tools when creating new agents, modify the agent creation logic in src/gunicorn.conf.py:
- Agent Instructions: Update the
instructionsvariable in thecreate_agent()function (around line 175) - Agent Tools: Modify the
get_available_tool()function to add or change tools available to the agent - Agent Model: Change the model by updating the
AZURE_AI_AGENT_DEPLOYMENT_NAMEenvironment variable
Important: If you want to modify an existing agent that's already deployed, it's recommended to use the Microsoft Foundry UI instead of the script:
- Go to your Microsoft Foundry project
- Navigate to the Agents section
- Select your agent
- Update instructions, tools, or settings directly in the UI
This approach is safer for existing agents as it preserves the agent's conversation history and avoids potential conflicts with running instances.
If you want to add new files to the src/files/ folder that your agent uses, you must do this BEFORE agent creation. The agent creation process in src/gunicorn.conf.py uploads these files to the vector store for OpenAI File Search and to blob storage so Azure AI Search can index them when enabled.
Single source of truth:
- Files in
src/files/power both OpenAI File Search and Azure AI Search (when enabled).
- Before Agent Creation: Add or update files in
src/files/directory - Agent Creation: Run the agent creation process (via local development or deployment)
- Files Embedded: Files are uploaded to the vector store and indexed for Azure AI Search
If you've already created an agent and need to add or update files, you have two options:
- Go to your Microsoft Foundry UI
- Navigate to the Agents section
- Delete the existing agent
- Update files in
src/files/directory - Restart your local development server or run
azd deployagain - The agent will be recreated with the updated files
- Update files in
src/files/directory - Run
azd deployagain - This will trigger the agent recreation process with updated files
- The agent creation script only processes files during the initial setup
- File embedding and search indexing happen once during agent initialization
- Existing agents don't automatically detect file changes
- The agent's vector store/search index needs to be rebuilt with new content
Important: Once an agent has been created and is being used by the application, it operates in a read-only mode for file operations:
- No File Upload: The agent will NOT upload new files from the
src/files/directory - No Vector Store Creation: It will NOT create new vector stores for additional files
- No Reindexing/Re-embedding: It will NOT rebuild the vector store or Azure AI Search index for changed files
- Uses Existing Resources: The agent continues to use only the files, vector stores, and search indexes that were created during its initial setup
This means that any changes you make to files in src/files/ after the agent is created will be completely ignored by the running agent. The agent initialization logic in src/gunicorn.conf.py only runs during the initial agent creation process, not during normal application operation.
Best Practice: Plan your file structure and content before creating agents to minimize the need for recreation.
