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
+17-2Lines changed: 17 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,9 @@ ms.service: agent-framework
13
13
14
14
The Microsoft Agent Framework supports background responses for handling long-running operations that may take time to complete. This feature enables agents to start processing a request and return a continuation token that can be used to poll for results or resume interrupted streams.
15
15
16
+
> [!TIP]
17
+
> For a complete working example, see the [Background Responses sample](https://github.com/microsoft/agent-framework/blob/main/dotnet/samples/GettingStarted/Agents/Agent_Step17_BackgroundResponses/Program.cs).
18
+
16
19
## When to Use Background Responses
17
20
18
21
Background responses are particularly useful for:
@@ -52,6 +55,12 @@ Some agents may not allow explicit control over background responses. These agen
52
55
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:
53
56
54
57
```csharp
58
+
AIAgentagent=newAzureOpenAIClient(
59
+
newUri("https://<myresource>.openai.azure.com"),
60
+
newAzureCliCredential())
61
+
.GetOpenAIResponseClient("<deployment-name>")
62
+
.CreateAIAgent();
63
+
55
64
AgentRunOptionsoptions=new()
56
65
{
57
66
AllowBackgroundResponses=true
@@ -60,7 +69,7 @@ AgentRunOptions options = new()
60
69
AgentThreadthread=agent.GetNewThread();
61
70
62
71
// Get initial response - may return with or without a continuation token
63
-
AgentRunResponseresponse=awaitagent.RunAsync("What is the weather like in Amsterdam?", thread, options);
72
+
AgentRunResponseresponse=awaitagent.RunAsync("Write a very long novel about otters in space.", thread, options);
64
73
65
74
// Continue to poll until the final response is received
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:
0 commit comments