Files
agent-framework/dotnet/samples/GettingStarted/Agents/Agent_Step17_BackgroundResponses
T

What This Sample Shows

This sample demonstrates how to use background responses with ChatCompletionAgent and OpenAI Responses for long-running operations. Background responses support:

  • Polling for completion - Non-streaming APIs can start a background operation and return a continuation token. Poll with the token until the response completes.
  • Resuming after interruption - Streaming APIs can be interrupted and resumed from the last update using the continuation token.

Note: Background responses are currently only supported by OpenAI Responses.

For more information, see the official documentation.

Prerequisites

Before you begin, ensure you have the following prerequisites:

  • .NET 8.0 SDK or later
  • OpenAI api key

Set the following environment variables:

$env:AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/" # Replace with your Azure OpenAI resource endpoint
$env:AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o-mini"  # Optional, defaults to gpt-4o-mini