Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Azure OpenAI Configuration
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=your-deployment-name
AZURE_OPENAI_API_KEY=your-api-key-here
FUNCTIONS_WORKER_RUNTIME=python
RUN_INTEGRATION_TESTS=true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ def _should_skip_azure_functions_integration_tests() -> tuple[bool, str]:
if not deployment_name or deployment_name == "your-deployment-name":
return True, "No real AZURE_OPENAI_CHAT_DEPLOYMENT_NAME provided; skipping integration tests."

api_key = os.getenv("AZURE_OPENAI_API_KEY", "").strip()
if not api_key or api_key == "your-api-key-here":
return True, "No real AZURE_OPENAI_API_KEY provided; skipping integration tests."

return False, "Integration tests enabled."


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,21 @@ This sample demonstrates how to use the Durable Extension for Agent Framework to
- Managing conversation state with session identifiers, so multiple clients can
interact with the agent concurrently without sharing context.

## Environment Setup
## Prerequisites

### 1. Create and activate a virtual environment

**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

- [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) – install so you can run `func start` locally.
- [Azurite storage emulator](https://learn.microsoft.com/azure/storage/common/storage-use-azurite?tabs=visual-studio) – install and start Azurite before launching the app (the sample uses `AzureWebJobsStorage=UseDevelopmentStorage=true`).
- Python dependencies – from this folder, run `pip install -r requirements.txt` (or the equivalent in your active virtual environment).
- Copy `local.settings.json.template` to `local.settings.json`, then update `AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME`, and `AZURE_OPENAI_API_KEY` so the Azure OpenAI SDK can authenticate; keep `TASKHUB_NAME` set to `default` unless you plan to change the durable task hub name.
Follow the common setup steps in `../README.md` to install tooling, configure Azure OpenAI credentials, and install the Python dependencies for this sample.

## Running the Sample

With the environment configured and the Functions host running, you can interact
with the Joker agent using the provided `demo.http` file or any HTTP client. For
example:
Send a prompt to the Joker agent:

```bash
curl -X POST http://localhost:7071/api/agents/Joker/run \
-H "Content-Type: text/plain" \
-d "Tell me a short joke about cloud computing."
```

The agent responds with a JSON payload that includes the generated joke.

## Expected Output

When you send a POST request with plain-text input, the Functions host responds with an HTTP 202 and queues the request for the durable agent entity. A typical response body looks like the following:
Expected HTTP 202 payload:

```json
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

from agent_framework.azure import AzureOpenAIChatClient
from agent_framework.azurefunctions import AgentFunctionApp

from azure.identity import AzureCliCredential
# 1. Instantiate the agent with the chosen deployment and instructions.
def _create_agent() -> Any:
"""Create the Joker agent."""

return AzureOpenAIChatClient().create_agent(
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
name="Joker",
instructions="You are good at telling jokes.",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
agent-framework-azurefunctions
azure-identity
packaging
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,22 @@ This sample demonstrates how to use the Durable Extension for Agent Framework to
- Conversation management (via session IDs) for isolated interactions per agent.
- Two different methods for registering agents: list-based initialization and incremental addition.

## Environment Setup
## Prerequisites

### 1. Create and activate a virtual environment

**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

- [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) – install so you can run `func start` locally.
- [Azurite storage emulator](https://learn.microsoft.com/azure/storage/common/storage-use-azurite?tabs=visual-studio) – install and start Azurite before launching the app; the sample expects `AzureWebJobsStorage=UseDevelopmentStorage=true`.
- Python dependencies – from this folder, run `pip install -r requirements.txt` (or use the equivalent command in your active virtual environment).

### 3. Configure local settings

- Copy `local.settings.json.template` to `local.settings.json`, then set the Azure OpenAI values (`AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME`, and `AZURE_OPENAI_API_KEY`) so the SDK can authenticate, and keep `TASKHUB_NAME` set to `default` unless you intend to change the durable task hub name.
Complete the common environment preparation steps described in `../README.md`, including installing Azure Functions Core Tools, starting Azurite, configuring Azure OpenAI settings, and installing this sample's requirements.

## Running the Sample

With the environment setup and function app running, you can test the sample by sending HTTP requests to the different agent endpoints.

You can use the `demo.http` file to send messages to the agents, or a command line tool like `curl` as shown below:

### Test the Weather Agent

Bash (Linux/macOS/WSL):
Weather agent request:

```bash
curl -X POST http://localhost:7071/api/agents/WeatherAgent/run \
-H "Content-Type: application/json" \
-d '{"message": "What is the weather in Seattle?"}'
```

PowerShell:
Expected HTTP 202 payload:

```powershell
Invoke-RestMethod -Method Post `
-Uri http://localhost:7071/api/agents/WeatherAgent/run `
-ContentType application/json `
-Body '{"message": "What is the weather in Seattle?"}'
```

Expected response:
```json
{
"status": "accepted",
Expand All @@ -71,26 +35,16 @@ Expected response:
}
```

### Test the Math Agent

Bash (Linux/macOS/WSL):
Math agent request:

```bash
curl -X POST http://localhost:7071/api/agents/MathAgent/run \
-H "Content-Type: application/json" \
-d '{"message": "Calculate a 20% tip on a $50 bill"}'
```

PowerShell:

```powershell
Invoke-RestMethod -Method Post `
-Uri http://localhost:7071/api/agents/MathAgent/run `
-ContentType application/json `
-Body '{"message": "Calculate a 20% tip on a $50 bill"}'
```
Expected HTTP 202 payload:

Expected response:
```json
{
"status": "accepted",
Expand All @@ -101,21 +55,14 @@ Expected response:
}
```

### Check Health

Bash (Linux/macOS/WSL):
Health check (optional):

```bash
curl http://localhost:7071/api/health
```

PowerShell:

```powershell
Invoke-RestMethod -Uri http://localhost:7071/api/health
```

Expected response:

```json
{
"status": "healthy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from agent_framework.azure import AzureOpenAIChatClient
from agent_framework.azurefunctions import AgentFunctionApp

from azure.identity import AzureCliCredential

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -51,7 +51,7 @@ def calculate_tip(bill_amount: float, tip_percentage: float = 15.0) -> dict[str,


# 1. Create multiple agents, each with its own instruction set and tools.
chat_client = AzureOpenAIChatClient()
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())

weather_agent = chat_client.create_agent(
name="WeatherAgent",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
agent-framework-azurefunctions
packaging
azure-identity
Original file line number Diff line number Diff line change
Expand Up @@ -17,62 +17,33 @@ 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:
```bash
curl -X POST http://localhost:7071/api/agents/CallbackAgent/run \
-H "Content-Type: application/json" \
-d '{"message": "Tell me a short joke"}'
```

```powershell
func start
```
Poll callback telemetry (replace `<conversationId>` with the value from the POST response):

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}`
```bash
curl http://localhost:7071/api/agents/CallbackAgent/callbacks/<conversationId>
```

Example workflow after the host starts:
Reset stored events:

```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 DELETE http://localhost:7071/api/agents/CallbackAgent/callbacks/<conversationId>
```

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.

## Expected Output

When you call `GET /api/agents/CallbackAgent/callbacks/{conversationId}` after sending a request to the agent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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

Expand Down Expand Up @@ -105,7 +106,7 @@ def _build_base_event(context: AgentCallbackContext) -> dict[str, Any]:


# 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. "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
agent-framework-azurefunctions
azure-identity
packaging
azure-identity
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,21 @@ preserving the conversation state between runs.
- HTTP endpoints for starting the orchestration and polling for status/output

## 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`
- Environment variables configured:
- `AZURE_OPENAI_ENDPOINT`
- `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME`
- `AZURE_OPENAI_API_KEY` (required for key-based auth; ensure Azure CLI is logged in if you prefer token-based auth)
- Keep `TASKHUB_NAME` set to `default` unless you intend to change the durable task hub name.
- Copy `local.settings.json.template` to `local.settings.json` and populate those keys—including `AZURE_OPENAI_API_KEY`—along with any storage settings before running the Functions host.
- Install dependencies with `pip install -r requirements.txt`

Start with the shared setup instructions in `../README.md` to create a virtual environment, install dependencies, and configure Azure OpenAI and storage settings.

## Running the Sample
1. Start the Functions host: `func start`.
2. Kick off the orchestration:
```bash
curl -X POST http://localhost:7071/api/singleagent/run
```
3. Copy the `statusQueryGetUri` from the response and poll until the orchestration completes:
```bash
curl http://localhost:7071/api/singleagent/status/<instanceId>
```
Start the orchestration:

```bash
curl -X POST http://localhost:7071/api/singleagent/run
```

Poll the returned `statusQueryGetUri` until completion:

```bash
curl http://localhost:7071/api/singleagent/status/<instanceId>
```

The orchestration first requests an inspirational sentence from the agent, then refines the initial response while
keeping it under 25 words—mirroring the behaviour of the corresponding .NET sample.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import azure.functions as func
from agent_framework.azure import AzureOpenAIChatClient
from azure.durable_functions import DurableOrchestrationContext
from azure.identity import AzureCliCredential
from agent_framework.azurefunctions import AgentFunctionApp, get_agent

logger = logging.getLogger(__name__)
Expand All @@ -33,7 +34,7 @@ def _create_writer_agent() -> Any:
"when given an improved sentence you polish it further."
)

return AzureOpenAIChatClient().create_agent(
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
name=WRITER_AGENT_NAME,
instructions=instructions,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
agent-framework-azurefunctions
azure-identity
packaging
azure-identity
Loading