Skip to content

Commit 0febe44

Browse files
address pr review comments
1 parent 9363e9c commit 0febe44

1 file changed

Lines changed: 10 additions & 26 deletions

File tree

agent-framework/user-guide/agents/agent-background-responses.md

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ Background responses use a **continuation token** mechanism to handle long-runni
2727
1. **Immediate completion**: The agent completes the task quickly and returns the final response without a continuation token
2828
2. **Background processing**: The agent starts processing in the background and returns a continuation token instead of the final result
2929

30-
The continuation token contains all necessary information to either poll for completion using the non-streaming `RunAsync` method or resume an interrupted stream with `RunStreamingAsync`. When the continuation token is `null`, the operation is complete - this happens when a background response has completed, failed, or cannot proceed further (for example, when user input is required).
31-
32-
## Enabling Background Responses
30+
The continuation token contains all necessary information to either poll for completion using the non-streaming agent API or resume an interrupted stream with streaming agent API. When the continuation token is `null`, the operation is complete - this happens when a background response has completed, failed, or cannot proceed further (for example, when user input is required).
3331

3432
::: zone pivot="programming-language-csharp"
3533

34+
## Enabling Background Responses
35+
3636
To enable background responses, set the `AllowBackgroundResponses` property to `true` in the `AgentRunOptions`:
3737

3838
```csharp
@@ -42,22 +42,13 @@ AgentRunOptions options = new()
4242
};
4343
```
4444

45-
::: zone-end
46-
::: zone pivot="programming-language-python"
47-
48-
Background responses support in Python is coming soon. This feature is currently available in the .NET implementation of Agent Framework.
49-
50-
::: zone-end
51-
5245
> [!NOTE]
5346
> Currently, only agents that use the OpenAI Responses API support background responses: [OpenAI Responses Agent](agent-types/openai-responses-agent.md) and [Azure OpenAI Responses Agent](agent-types/azure-openai-responses-agent.md).
5447
55-
Some agents may not allow explicit control over background responses. These agents can decide autonomously whether to initiate a background response based on the complexity of the operation, regardless of the `AllowBackgroundResponses` setting. An example is the A2A agent.
48+
Some agents may not allow explicit control over background responses. These agents can decide autonomously whether to initiate a background response based on the complexity of the operation, regardless of the `AllowBackgroundResponses` setting.
5649

5750
## Non-Streaming Background Responses
5851

59-
::: zone pivot="programming-language-csharp"
60-
6152
For non-streaming scenarios, when you initially run an agent, it may or may not return a continuation token. If no continuation token is returned, it means the operation has completed. If a continuation token is returned, it indicates that the agent has initiated a background response that is still processing and will require polling to retrieve the final result:
6253

6354
```csharp
@@ -72,8 +63,11 @@ AgentRunResponse response = await agent.RunAsync("What is the weather like in Am
7263
// Continue to poll until the final response is received
7364
while (response.ContinuationToken is not null)
7465
{
66+
// Wait before polling again.
67+
await Task.Delay(TimeSpan.FromSeconds(2));
68+
7569
options.ContinuationToken = response.ContinuationToken;
76-
response = await agent.RunAsync([], options: options);
70+
response = await agent.RunAsync(options: options);
7771
}
7872

7973
Console.WriteLine(response.Text);
@@ -85,20 +79,10 @@ Console.WriteLine(response.Text);
8579
- If no continuation token is returned, the operation is complete and the response contains the final result
8680
- If a continuation token is returned, the agent has started a background process that requires polling
8781
- Use the continuation token from the previous response in subsequent polling calls
88-
- Pass an empty message array (`[]`) when polling with a continuation token
8982
- When `ContinuationToken` is `null`, the operation is complete
9083

91-
::: zone-end
92-
::: zone pivot="programming-language-python"
93-
94-
Background responses support in Python is coming soon. This feature is currently available in the .NET implementation of Agent Framework.
95-
96-
::: zone-end
97-
9884
## Streaming Background Responses
9985

100-
::: zone pivot="programming-language-csharp"
101-
10286
In streaming scenarios, background responses work much like regular streaming responses - the agent streams all updates back to consumers in real-time. However, the key difference is that if the original stream gets interrupted, agents support stream resumption through continuation tokens. Each update includes a continuation token that captures the current state, allowing the stream to be resumed from exactly where it left off by passing this token to subsequent streaming API calls:
10387

10488
```csharp
@@ -121,7 +105,7 @@ await foreach (var update in agent.RunStreamingAsync("Tell me a joke about a pir
121105

122106
// Resume from interruption point captured by the continuation token
123107
options.ContinuationToken = latestReceivedUpdate?.ContinuationToken;
124-
await foreach (var update in agent.RunStreamingAsync([], options: options))
108+
await foreach (var update in agent.RunStreamingAsync(options: options))
125109
{
126110
Console.Write(update.Text);
127111
}
@@ -132,9 +116,9 @@ await foreach (var update in agent.RunStreamingAsync([], options: options))
132116
- Each `AgentRunResponseUpdate` contains a continuation token that can be used for resumption
133117
- Store the continuation token from the last received update before interruption
134118
- Use the stored continuation token to resume the stream from the interruption point
135-
- Pass an empty message array (`[]`) when resuming with a continuation token
136119

137120
::: zone-end
121+
138122
::: zone pivot="programming-language-python"
139123

140124
Background responses support in Python is coming soon. This feature is currently available in the .NET implementation of Agent Framework.

0 commit comments

Comments
 (0)