mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
update the sample to have more relevant background responses prompts and reference official documentation. (#1654)
This commit is contained in:
@@ -14,7 +14,7 @@ AIAgent agent = new AzureOpenAIClient(
|
|||||||
new Uri(endpoint),
|
new Uri(endpoint),
|
||||||
new AzureCliCredential())
|
new AzureCliCredential())
|
||||||
.GetOpenAIResponseClient(deploymentName)
|
.GetOpenAIResponseClient(deploymentName)
|
||||||
.CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker");
|
.CreateAIAgent();
|
||||||
|
|
||||||
// Enable background responses (only supported by OpenAI Responses at this time).
|
// Enable background responses (only supported by OpenAI Responses at this time).
|
||||||
AgentRunOptions options = new() { AllowBackgroundResponses = true };
|
AgentRunOptions options = new() { AllowBackgroundResponses = true };
|
||||||
@@ -22,7 +22,7 @@ AgentRunOptions options = new() { AllowBackgroundResponses = true };
|
|||||||
AgentThread thread = agent.GetNewThread();
|
AgentThread thread = agent.GetNewThread();
|
||||||
|
|
||||||
// Start the initial run.
|
// 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.
|
// Poll until the response is complete.
|
||||||
while (response.ContinuationToken is { } token)
|
while (response.ContinuationToken is { } token)
|
||||||
@@ -45,7 +45,7 @@ thread = agent.GetNewThread();
|
|||||||
|
|
||||||
AgentRunResponseUpdate? lastReceivedUpdate = null;
|
AgentRunResponseUpdate? lastReceivedUpdate = null;
|
||||||
// Start streaming.
|
// 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.
|
// Output each update.
|
||||||
Console.Write(update.Text);
|
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.
|
> **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
|
# Prerequisites
|
||||||
|
|
||||||
Before you begin, ensure you have the following prerequisites:
|
Before you begin, ensure you have the following prerequisites:
|
||||||
|
|||||||
Reference in New Issue
Block a user