Python: Fix AzureFunctions Integration Tests (#2116)

* Add Identity Auth to samples

* Update python/samples/getting_started/azure_functions/README.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update python/samples/getting_started/azure_functions/01_single_agent/function_app.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update python/samples/getting_started/azure_functions/02_multi_agent/function_app.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update python/samples/getting_started/azure_functions/06_multi_agent_orchestration_conditionals/README.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Laveesh Rohra
2025-11-12 09:13:23 -08:00
committed by GitHub
Unverified
parent 2329bd4841
commit ebab25b196
24 changed files with 126 additions and 234 deletions
@@ -17,61 +17,32 @@ an HTTP API that can be polled by a web client or dashboard.
## Prerequisites
- Python 3.10+
- [Azure Functions Core Tools 4.x](https://learn.microsoft.com/azure/azure-functions/functions-run-local?tabs=windows%2Cpython%2Cv2&pivots=programming-language-python#install-the-azure-functions-core-tools)
- [Azurite storage emulator](https://learn.microsoft.com/azure/storage/common/storage-use-azurite?tabs=visual-studio) running locally so the sample can use `AzureWebJobsStorage=UseDevelopmentStorage=true`
- Access to an Azure OpenAI deployment with `AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME`, and `AZURE_OPENAI_API_KEY` configured (either in `local.settings.json` or exported in your shell)
- Dependencies from `requirements.txt` installed in your environment
Complete the shared environment setup steps in `../README.md`, including creating a virtual environment, installing dependencies, and configuring Azure OpenAI credentials and storage settings.
> **Note:** The sample stores callback events in memory for simplicity. For production scenarios you
> should persist events to Application Insights, Azure Storage, Cosmos DB, or another durable store.
## Running the Sample
1. Create and activate a virtual environment:
Send a prompt to the agent:
**Windows (PowerShell):**
```powershell
python -m venv .venv
.venv\Scripts\Activate.ps1
```
**Linux/macOS:**
```bash
python -m venv .venv
source .venv/bin/activate
```
2. Install dependencies (from the repository root or this directory):
```powershell
pip install -r requirements.txt
```
3. Copy `local.settings.json.template` to `local.settings.json` and update `AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME`, and `AZURE_OPENAI_API_KEY` (or export them as environment variables) for your Azure resources, making sure `TASKHUB_NAME` remains `default` unless you have changed the durable task hub name.
4. Start the Functions host:
```powershell
func start
```
5. Use the [`demo.http`](./demo.http) file (VS Code REST Client) or any HTTP client to:
- Send a message to the agent: `POST /api/agents/CallbackAgent/run`
- Query callback telemetry: `GET /api/agents/CallbackAgent/callbacks/{conversationId}`
- Clear stored events: `DELETE /api/agents/CallbackAgent/callbacks/{conversationId}`
Example workflow after the host starts:
```text
POST /api/agents/CallbackAgent/run # send a conversation message
GET /api/agents/CallbackAgent/callbacks/test-session # inspect streaming + final events
DELETE /api/agents/CallbackAgent/callbacks/test-session # reset telemetry for the session
```bash
curl -X POST http://localhost:7071/api/agents/CallbackAgent/run \
-H "Content-Type: application/json" \
-d '{"message": "Tell me a short joke"}'
```
The GET endpoint returns an array of events captured by the callback, including timestamps,
streaming chunk previews, and the final response metadata. This makes it easy to build real-time
UI updates or audit logs on top of Durable Agents.
Poll callback telemetry (replace `<conversationId>` with the value from the POST response):
```bash
curl http://localhost:7071/api/agents/CallbackAgent/callbacks/<conversationId>
```
Reset stored events:
```bash
curl -X DELETE http://localhost:7071/api/agents/CallbackAgent/callbacks/<conversationId>
```
## Expected Output
@@ -17,6 +17,7 @@ from typing import Any, DefaultDict
import azure.functions as func
from agent_framework import AgentRunResponseUpdate
from agent_framework.azure import AzureOpenAIChatClient
from azure.identity import AzureCliCredential
from agent_framework.azurefunctions import AgentFunctionApp, AgentCallbackContext, AgentResponseCallbackProtocol
@@ -105,7 +106,7 @@ class ConversationAuditTrail(AgentResponseCallbackProtocol):
# 2. Create the agent that will emit streaming updates and final responses.
callback_agent = AzureOpenAIChatClient().create_agent(
callback_agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
name="CallbackAgent",
instructions=(
"You are a friendly assistant that narrates actions while responding. "
@@ -1,3 +1,2 @@
agent-framework-azurefunctions
azure-identity
packaging
azure-identity