You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: agent-framework/user-guide/agents/agent-background-responses.md
+10-26Lines changed: 10 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,12 +27,12 @@ Background responses use a **continuation token** mechanism to handle long-runni
27
27
1.**Immediate completion**: The agent completes the task quickly and returns the final response without a continuation token
28
28
2.**Background processing**: The agent starts processing in the background and returns a continuation token instead of the final result
29
29
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).
33
31
34
32
::: zone pivot="programming-language-csharp"
35
33
34
+
## Enabling Background Responses
35
+
36
36
To enable background responses, set the `AllowBackgroundResponses` property to `true` in the `AgentRunOptions`:
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
-
52
45
> [!NOTE]
53
46
> 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).
54
47
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.
56
49
57
50
## Non-Streaming Background Responses
58
51
59
-
::: zone pivot="programming-language-csharp"
60
-
61
52
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:
62
53
63
54
```csharp
@@ -72,8 +63,11 @@ AgentRunResponse response = await agent.RunAsync("What is the weather like in Am
72
63
// Continue to poll until the final response is received
- If no continuation token is returned, the operation is complete and the response contains the final result
86
80
- If a continuation token is returned, the agent has started a background process that requires polling
87
81
- Use the continuation token from the previous response in subsequent polling calls
88
-
- Pass an empty message array (`[]`) when polling with a continuation token
89
82
- When `ContinuationToken` is `null`, the operation is complete
90
83
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
-
98
84
## Streaming Background Responses
99
85
100
-
::: zone pivot="programming-language-csharp"
101
-
102
86
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:
103
87
104
88
```csharp
@@ -121,7 +105,7 @@ await foreach (var update in agent.RunStreamingAsync("Tell me a joke about a pir
121
105
122
106
// Resume from interruption point captured by the continuation token
0 commit comments