Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,27 @@

await Task.Delay(TimeSpan.FromSeconds(10));

RestoreAgentState(agent, out thread, out object? continuationToken);
RestoreAgentState(agent, out thread, out ResponseContinuationToken? continuationToken);

options.ContinuationToken = continuationToken;
response = await agent.RunAsync(thread, options);
}

Console.WriteLine(response.Text);

void PersistAgentState(AgentThread thread, object? continuationToken)
void PersistAgentState(AgentThread thread, ResponseContinuationToken? continuationToken)
{
stateStore["thread"] = thread.Serialize();
stateStore["continuationToken"] = JsonSerializer.SerializeToElement(continuationToken, AgentAbstractionsJsonUtilities.DefaultOptions.GetTypeInfo(typeof(ResponseContinuationToken)));
}

void RestoreAgentState(AIAgent agent, out AgentThread thread, out object? continuationToken)
void RestoreAgentState(AIAgent agent, out AgentThread thread, out ResponseContinuationToken? continuationToken)
{
JsonElement serializedThread = stateStore["thread"] ?? throw new InvalidOperationException("No serialized thread found in state store.");
JsonElement? serializedToken = stateStore["continuationToken"];

thread = agent.DeserializeThread(serializedThread);
continuationToken = serializedToken?.Deserialize(AgentAbstractionsJsonUtilities.DefaultOptions.GetTypeInfo(typeof(ResponseContinuationToken)));
continuationToken = (ResponseContinuationToken?)serializedToken?.Deserialize(AgentAbstractionsJsonUtilities.DefaultOptions.GetTypeInfo(typeof(ResponseContinuationToken)));
}

[Description("Researches relevant space facts and scientific information for writing a science fiction novel")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public AgentRunOptions(AgentRunOptions options)
/// can be polled for completion by obtaining the token from the <see cref="AgentRunResponse.ContinuationToken"/> property
/// and passing it via this property on subsequent calls to <see cref="AIAgent.RunAsync(AgentThread?, AgentRunOptions?, System.Threading.CancellationToken)"/>.
/// </remarks>
public object? ContinuationToken { get; set; }
public ResponseContinuationToken? ContinuationToken { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the background responses are allowed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public IList<ChatMessage> Messages
/// to poll for completion.
/// </para>
/// </remarks>
public object? ContinuationToken { get; set; }
public ResponseContinuationToken? ContinuationToken { get; set; }

/// <summary>
/// Gets or sets the timestamp indicating when this response was created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ response.RawRepresentation as ChatResponse ??
RawRepresentation = response,
ResponseId = response.ResponseId,
Usage = response.Usage,
ContinuationToken = response.ContinuationToken as ResponseContinuationToken,
ContinuationToken = response.ContinuationToken,
};
}

Expand Down Expand Up @@ -75,7 +75,7 @@ responseUpdate.RawRepresentation as ChatResponseUpdate ??
RawRepresentation = responseUpdate,
ResponseId = responseUpdate.ResponseId,
Role = responseUpdate.Role,
ContinuationToken = responseUpdate.ContinuationToken as ResponseContinuationToken,
ContinuationToken = responseUpdate.ContinuationToken,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public IList<AIContent> Contents
/// to resume streaming from the point of interruption.
/// </para>
/// </remarks>
public object? ContinuationToken { get; set; }
public ResponseContinuationToken? ContinuationToken { get; set; }

/// <inheritdoc/>
public override string ToString() => this.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ await thread.AIContextProvider.InvokedAsync(new(inputMessages, aiContextProvider
{
chatOptions ??= new ChatOptions();
chatOptions.AllowBackgroundResponses = agentRunOptions.AllowBackgroundResponses;
chatOptions.ContinuationToken = agentRunOptions.ContinuationToken as ResponseContinuationToken;
chatOptions.ContinuationToken = agentRunOptions.ContinuationToken;
}

return chatOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void CloningConstructorCopiesProperties()
// Arrange
var options = new AgentRunOptions
{
ContinuationToken = new object(),
ContinuationToken = ResponseContinuationToken.FromBytes(new byte[] { 1, 2, 3 }),
AllowBackgroundResponses = true,
AdditionalProperties = new AdditionalPropertiesDictionary
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static async ValueTask RunAsync(TextWriter writer, IWorkflowExecutionEnvi
foreach (string input in inputs)
{
AgentRunResponse response;
object? continuationToken = null;
ResponseContinuationToken? continuationToken = null;
do
{
response = await hostAgent.RunAsync(input, thread, new AgentRunOptions { ContinuationToken = continuationToken });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static async ValueTask RunAsync(TextWriter writer, IWorkflowExecutionEnvi
foreach (string input in inputs)
{
AgentRunResponse response;
object? continuationToken = null;
ResponseContinuationToken? continuationToken = null;
do
{
response = await hostAgent.RunAsync(input, thread, new AgentRunOptions { ContinuationToken = continuationToken });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static async ValueTask RunAsync(TextWriter writer, IWorkflowExecutionEnvi
foreach (string input in inputs)
{
AgentRunResponse response;
object? continuationToken = null;
ResponseContinuationToken? continuationToken = null;
do
{
response = await hostAgent.RunAsync(input, thread, new AgentRunOptions { ContinuationToken = continuationToken });
Expand Down
Loading