Skip to content

Commit 9d8446f

Browse files
update code snippets to use thread
1 parent a740525 commit 9d8446f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ AgentRunOptions options = new()
5757
AllowBackgroundResponses = true
5858
};
5959

60+
AgentThread thread = agent.GetNewThread();
61+
6062
// Get initial response - may return with or without a continuation token
61-
AgentRunResponse response = await agent.RunAsync("What is the weather like in Amsterdam?", options: options);
63+
AgentRunResponse response = await agent.RunAsync("What is the weather like in Amsterdam?", thread, options);
6264

6365
// Continue to poll until the final response is received
6466
while (response.ContinuationToken is not null)
@@ -67,7 +69,7 @@ while (response.ContinuationToken is not null)
6769
await Task.Delay(TimeSpan.FromSeconds(2));
6870

6971
options.ContinuationToken = response.ContinuationToken;
70-
response = await agent.RunAsync(options: options);
72+
response = await agent.RunAsync(thread, options);
7173
}
7274

7375
Console.WriteLine(response.Text);
@@ -91,9 +93,11 @@ AgentRunOptions options = new()
9193
AllowBackgroundResponses = true
9294
};
9395

96+
AgentThread thread = agent.GetNewThread();
97+
9498
AgentRunResponseUpdate? latestReceivedUpdate = null;
9599

96-
await foreach (var update in agent.RunStreamingAsync("Tell me a joke about a pirate.", options: options))
100+
await foreach (var update in agent.RunStreamingAsync("Tell me a joke about a pirate.", thread, options))
97101
{
98102
Console.Write(update.Text);
99103

@@ -105,7 +109,7 @@ await foreach (var update in agent.RunStreamingAsync("Tell me a joke about a pir
105109

106110
// Resume from interruption point captured by the continuation token
107111
options.ContinuationToken = latestReceivedUpdate?.ContinuationToken;
108-
await foreach (var update in agent.RunStreamingAsync(options: options))
112+
await foreach (var update in agent.RunStreamingAsync(thread, options))
109113
{
110114
Console.Write(update.Text);
111115
}

0 commit comments

Comments
 (0)