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 @@ -41,8 +41,8 @@ public override JsonElement SerializeSession(AgentSession session, JsonSerialize
return typedSession.Serialize(jsonSerializerOptions);
}

public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
=> new(new CustomAgentSession(serializedSession, jsonSerializerOptions));
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedState, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
=> new(new CustomAgentSession(serializedState, jsonSerializerOptions));

protected override async Task<AgentResponse> RunCoreAsync(IEnumerable<ChatMessage> messages, AgentSession? session = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default)
{
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public override JsonElement SerializeSession(AgentSession session, JsonSerialize
}

/// <inheritdoc/>
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
=> new(new A2AAgentSession(serializedSession, jsonSerializerOptions));
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedState, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
=> new(new A2AAgentSession(serializedState, jsonSerializerOptions));

/// <inheritdoc/>
protected override async Task<AgentResponse> RunCoreAsync(IEnumerable<ChatMessage> messages, AgentSession? session = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default)
Expand Down
8 changes: 4 additions & 4 deletions dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@ public abstract class AIAgent
/// <summary>
/// Deserializes an agent session from its JSON serialized representation.
/// </summary>
/// <param name="serializedSession">A <see cref="JsonElement"/> containing the serialized session state.</param>
/// <param name="serializedState">A <see cref="JsonElement"/> containing the serialized session state.</param>
/// <param name="jsonSerializerOptions">Optional settings to customize the deserialization process.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
/// <returns>A value task that represents the asynchronous operation. The task result contains a restored <see cref="AgentSession"/> instance with the state from <paramref name="serializedSession"/>.</returns>
/// <exception cref="ArgumentException">The <paramref name="serializedSession"/> is not in the expected format.</exception>
/// <returns>A value task that represents the asynchronous operation. The task result contains a restored <see cref="AgentSession"/> instance with the state from <paramref name="serializedState"/>.</returns>
/// <exception cref="ArgumentException">The <paramref name="serializedState"/> is not in the expected format.</exception>
/// <exception cref="JsonException">The serialized data is invalid or cannot be deserialized.</exception>
/// <remarks>
/// This method enables restoration of conversation sessions from previously saved state,
/// allowing conversations to resume across application restarts or be migrated between
/// different agent instances.
/// </remarks>
public abstract ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default);
public abstract ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedState, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default);

/// <summary>
/// Run the agent with no message assuming that all required instructions are already provided to the agent or on the session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public override JsonElement SerializeSession(AgentSession session, JsonSerialize
=> this.InnerAgent.SerializeSession(session, jsonSerializerOptions);

/// <inheritdoc />
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
=> this.InnerAgent.DeserializeSessionAsync(serializedSession, jsonSerializerOptions, cancellationToken);
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedState, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
=> this.InnerAgent.DeserializeSessionAsync(serializedState, jsonSerializerOptions, cancellationToken);

/// <inheritdoc />
protected override Task<AgentResponse> RunCoreAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,29 @@ protected InMemoryAgentSession(IEnumerable<ChatMessage> messages)
/// <summary>
/// Initializes a new instance of the <see cref="InMemoryAgentSession"/> class from previously serialized state.
/// </summary>
/// <param name="serializedSessionState">A <see cref="JsonElement"/> representing the serialized state of the session.</param>
/// <param name="serializedState">A <see cref="JsonElement"/> representing the serialized state of the session.</param>
/// <param name="jsonSerializerOptions">Optional settings for customizing the JSON deserialization process.</param>
/// <param name="chatHistoryProviderFactory">
/// Optional factory function to create the <see cref="InMemoryChatHistoryProvider"/> from its serialized state.
/// If not provided, a default factory will be used that creates a basic <see cref="InMemoryChatHistoryProvider"/>.
/// </param>
/// <exception cref="ArgumentException">The <paramref name="serializedSessionState"/> is not a JSON object.</exception>
/// <exception cref="JsonException">The <paramref name="serializedSessionState"/> is invalid or cannot be deserialized to the expected type.</exception>
/// <exception cref="ArgumentException">The <paramref name="serializedState"/> is not a JSON object.</exception>
/// <exception cref="JsonException">The <paramref name="serializedState"/> is invalid or cannot be deserialized to the expected type.</exception>
/// <remarks>
/// This constructor enables restoration of in-memory threads from previously saved state, allowing
/// conversations to be resumed across application restarts or migrated between different instances.
/// </remarks>
protected InMemoryAgentSession(
JsonElement serializedSessionState,
JsonElement serializedState,
JsonSerializerOptions? jsonSerializerOptions = null,
Func<JsonElement, JsonSerializerOptions?, InMemoryChatHistoryProvider>? chatHistoryProviderFactory = null)
{
if (serializedSessionState.ValueKind != JsonValueKind.Object)
if (serializedState.ValueKind != JsonValueKind.Object)
{
throw new ArgumentException("The serialized session state must be a JSON object.", nameof(serializedSessionState));
throw new ArgumentException("The serialized session state must be a JSON object.", nameof(serializedState));
}

var state = serializedSessionState.Deserialize(
var state = serializedState.Deserialize(
AgentAbstractionsJsonUtilities.DefaultOptions.GetTypeInfo(typeof(InMemoryAgentSessionState))) as InMemoryAgentSessionState;

this.ChatHistoryProvider =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ protected ServiceIdAgentSession(string serviceSessionId)
/// <summary>
/// Initializes a new instance of the <see cref="ServiceIdAgentSession"/> class from previously serialized state.
/// </summary>
/// <param name="serializedSessionState">A <see cref="JsonElement"/> representing the serialized state of the session.</param>
/// <param name="serializedState">A <see cref="JsonElement"/> representing the serialized state of the session.</param>
/// <param name="jsonSerializerOptions">Optional settings for customizing the JSON deserialization process.</param>
/// <exception cref="ArgumentException">The <paramref name="serializedSessionState"/> is not a JSON object.</exception>
/// <exception cref="JsonException">The <paramref name="serializedSessionState"/> is invalid or cannot be deserialized to the expected type.</exception>
/// <exception cref="ArgumentException">The <paramref name="serializedState"/> is not a JSON object.</exception>
/// <exception cref="JsonException">The <paramref name="serializedState"/> is invalid or cannot be deserialized to the expected type.</exception>
/// <remarks>
/// This constructor enables restoration of a service-backed session from serialized state, typically used
/// when deserializing session information that was previously saved or transmitted across application boundaries.
/// </remarks>
protected ServiceIdAgentSession(
JsonElement serializedSessionState,
JsonElement serializedState,
JsonSerializerOptions? jsonSerializerOptions = null)
{
if (serializedSessionState.ValueKind != JsonValueKind.Object)
if (serializedState.ValueKind != JsonValueKind.Object)
{
throw new ArgumentException("The serialized session state must be a JSON object.", nameof(serializedSessionState));
throw new ArgumentException("The serialized session state must be a JSON object.", nameof(serializedState));
}

var state = serializedSessionState.Deserialize(
var state = serializedState.Deserialize(
AgentAbstractionsJsonUtilities.DefaultOptions.GetTypeInfo(typeof(ServiceIdAgentSessionState))) as ServiceIdAgentSessionState;

if (state?.ServiceSessionId is string serviceSessionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public override JsonElement SerializeSession(AgentSession session, JsonSerialize
}

/// <inheritdoc/>
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
=> new(new CopilotStudioAgentSession(serializedSession, jsonSerializerOptions));
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedState, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
=> new(new CopilotStudioAgentSession(serializedState, jsonSerializerOptions));

/// <inheritdoc/>
protected override async Task<AgentResponse> RunCoreAsync(
Expand Down
1 change: 1 addition & 0 deletions dotnet/src/Microsoft.Agents.AI.DurableTask/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Removed AgentThreadMetadata and used AgentSessionId directly instead ([#3067](https://github.com/microsoft/agent-framework/pull/3067));
- Renamed AgentThread to AgentSession ([#3430](https://github.com/microsoft/agent-framework/pull/3430))
- Moved AgentSession.Serialize to AIAgent.SerializeSession ([#3650](https://github.com/microsoft/agent-framework/pull/3650))
- Renamed serializedSession parameter to serializedState on DeserializeSessionAsync for consistency ([#3681](https://github.com/microsoft/agent-framework/pull/3681))

## v1.0.0-preview.251204.1

Expand Down
6 changes: 3 additions & 3 deletions dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public override JsonElement SerializeSession(AgentSession session, JsonSerialize
/// <summary>
/// Deserializes an agent session from JSON.
/// </summary>
/// <param name="serializedSession">The serialized session data.</param>
/// <param name="serializedState">The serialized session data.</param>
/// <param name="jsonSerializerOptions">Optional JSON serializer options.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A value task that represents the asynchronous operation. The task result contains the deserialized agent session.</returns>
public override ValueTask<AgentSession> DeserializeSessionAsync(
JsonElement serializedSession,
JsonElement serializedState,
JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
{
return ValueTask.FromResult<AgentSession>(DurableAgentSession.Deserialize(serializedSession, jsonSerializerOptions));
return ValueTask.FromResult<AgentSession>(DurableAgentSession.Deserialize(serializedState, jsonSerializerOptions));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public override JsonElement SerializeSession(AgentSession session, JsonSerialize
}

public override ValueTask<AgentSession> DeserializeSessionAsync(
JsonElement serializedSession,
JsonElement serializedState,
JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
{
return ValueTask.FromResult<AgentSession>(DurableAgentSession.Deserialize(serializedSession, jsonSerializerOptions));
return ValueTask.FromResult<AgentSession>(DurableAgentSession.Deserialize(serializedState, jsonSerializerOptions));
}

public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ public override JsonElement SerializeSession(AgentSession session, JsonSerialize

/// <inheritdoc/>
public override ValueTask<AgentSession> DeserializeSessionAsync(
JsonElement serializedSession,
JsonElement serializedState,
JsonSerializerOptions? jsonSerializerOptions = null,
CancellationToken cancellationToken = default)
=> new(new GitHubCopilotAgentSession(serializedSession, jsonSerializerOptions));
=> new(new GitHubCopilotAgentSession(serializedState, jsonSerializerOptions));

/// <inheritdoc/>
protected override Task<AgentResponse> RunCoreAsync(
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/Microsoft.Agents.AI.Purview/PurviewAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public override JsonElement SerializeSession(AgentSession session, JsonSerialize
}

/// <inheritdoc/>
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedState, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
{
return this._innerAgent.DeserializeSessionAsync(serializedSession, jsonSerializerOptions, cancellationToken);
return this._innerAgent.DeserializeSessionAsync(serializedState, jsonSerializerOptions, cancellationToken);
}

/// <inheritdoc/>
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public override JsonElement SerializeSession(AgentSession session, JsonSerialize
return workflowSession.Serialize(jsonSerializerOptions);
}

public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
=> new(new WorkflowSession(this._workflow, serializedSession, this._executionEnvironment, this._checkpointManager, this._includeExceptionDetails, this._includeWorkflowOutputsInResponse, jsonSerializerOptions));
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedState, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
=> new(new WorkflowSession(this._workflow, serializedState, this._executionEnvironment, this._checkpointManager, this._includeExceptionDetails, this._includeWorkflowOutputsInResponse, jsonSerializerOptions));

private async ValueTask<WorkflowSession> UpdateSessionAsync(IEnumerable<ChatMessage> messages, AgentSession? session = null, CancellationToken cancellationToken = default)
{
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public override JsonElement SerializeSession(AgentSession session, JsonSerialize
}

/// <inheritdoc/>
public override async ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
public override async ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedState, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
{
Func<JsonElement, JsonSerializerOptions?, CancellationToken, ValueTask<ChatHistoryProvider>>? chatHistoryProviderFactory = this._agentOptions?.ChatHistoryProviderFactory is null ?
null :
Expand All @@ -410,7 +410,7 @@ public override async ValueTask<AgentSession> DeserializeSessionAsync(JsonElemen
(jse, jso, ct) => this._agentOptions.AIContextProviderFactory.Invoke(new() { SerializedState = jse, JsonSerializerOptions = jso }, ct);

return await ChatClientAgentSession.DeserializeAsync(
serializedSession,
serializedState,
jsonSerializerOptions,
chatHistoryProviderFactory,
aiContextProviderFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ internal set
/// <summary>
/// Creates a new instance of the <see cref="ChatClientAgentSession"/> class from previously serialized state.
/// </summary>
/// <param name="serializedSessionState">A <see cref="JsonElement"/> representing the serialized state of the session.</param>
/// <param name="serializedState">A <see cref="JsonElement"/> representing the serialized state of the session.</param>
/// <param name="jsonSerializerOptions">Optional settings for customizing the JSON deserialization process.</param>
/// <param name="chatHistoryProviderFactory">
/// An optional factory function to create a custom <see cref="AI.ChatHistoryProvider"/> from its serialized state.
Expand All @@ -128,18 +128,18 @@ internal set
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests.</param>
/// <returns>A task representing the asynchronous operation. The task result contains the deserialized <see cref="ChatClientAgentSession"/>.</returns>
internal static async Task<ChatClientAgentSession> DeserializeAsync(
JsonElement serializedSessionState,
JsonElement serializedState,
JsonSerializerOptions? jsonSerializerOptions = null,
Func<JsonElement, JsonSerializerOptions?, CancellationToken, ValueTask<ChatHistoryProvider>>? chatHistoryProviderFactory = null,
Func<JsonElement, JsonSerializerOptions?, CancellationToken, ValueTask<AIContextProvider>>? aiContextProviderFactory = null,
CancellationToken cancellationToken = default)
{
if (serializedSessionState.ValueKind != JsonValueKind.Object)
if (serializedState.ValueKind != JsonValueKind.Object)
{
throw new ArgumentException("The serialized session state must be a JSON object.", nameof(serializedSessionState));
throw new ArgumentException("The serialized session state must be a JSON object.", nameof(serializedState));
}

var state = serializedSessionState.Deserialize(
var state = serializedState.Deserialize(
AgentJsonUtilities.DefaultOptions.GetTypeInfo(typeof(SessionState))) as SessionState;

var session = new ChatClientAgentSession();
Expand Down
Loading
Loading