update the sample to have more relevant background responses prompts and reference official documentation. (#1654)

This commit is contained in:
SergeyMenshykh
2025-10-23 18:47:54 +01:00
committed by GitHub
Unverified
parent 72c391bc08
commit c408a2d8c3
2 changed files with 5 additions and 3 deletions
@@ -14,7 +14,7 @@ AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential())
.GetOpenAIResponseClient(deploymentName)
.CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker");
.CreateAIAgent();
// Enable background responses (only supported by OpenAI Responses at this time).
AgentRunOptions options = new() { AllowBackgroundResponses = true };
@@ -22,7 +22,7 @@ AgentRunOptions options = new() { AllowBackgroundResponses = true };
AgentThread thread = agent.GetNewThread();
// Start the initial run.
AgentRunResponse response = await agent.RunAsync("Tell me a joke about a pirate.", thread, options);
AgentRunResponse response = await agent.RunAsync("Write a very long novel about otters in space.", thread, options);
// Poll until the response is complete.
while (response.ContinuationToken is { } token)
@@ -45,7 +45,7 @@ thread = agent.GetNewThread();
AgentRunResponseUpdate? lastReceivedUpdate = null;
// Start streaming.
await foreach (AgentRunResponseUpdate update in agent.RunStreamingAsync("Tell me a joke about a pirate.", thread, options))
await foreach (AgentRunResponseUpdate update in agent.RunStreamingAsync("Write a very long novel about otters in space.", thread, options))
{
// Output each update.
Console.Write(update.Text);
@@ -7,6 +7,8 @@ This sample demonstrates how to use background responses with ChatCompletionAgen
> **Note:** Background responses are currently only supported by OpenAI Responses.
For more information, see the [official documentation](https://learn.microsoft.com/en-us/agent-framework/user-guide/agents/agent-background-responses?pivots=programming-language-csharp).
# Prerequisites
Before you begin, ensure you have the following prerequisites: