Skip to content

Commit

Permalink
.Net - Agents IReadonlyList instead of IEnumerable (Step #ANY) (micro…
Browse files Browse the repository at this point in the history
…soft#5832)

### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

`IEnumerable` can be cumbersome if not required. Identified a usage that
is improved by `IReadOnlyList` (as the usage of `IEnumerable` was
extraneous.)

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

Been on the look-out for tuning these signatures...this one slipped
through.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
  • Loading branch information
crickman authored Apr 11, 2024
1 parent ed1770c commit cbbaa59
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dotnet/src/Agents/Abstractions/AgentChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class AgentChannel
/// </summary>
/// <param name="history">The chat history at the point the channel is created.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
protected internal abstract Task ReceiveAsync(IEnumerable<ChatMessageContent> history, CancellationToken cancellationToken = default);
protected internal abstract Task ReceiveAsync(IReadOnlyList<ChatMessageContent> history, CancellationToken cancellationToken = default);

/// <summary>
/// Perform a discrete incremental interaction between a single <see cref="Agent"/> and <see cref="AgentChat"/>.
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/Agents/Abstractions/ChatHistoryChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected internal sealed override async IAsyncEnumerable<ChatMessageContent> In
}

/// <inheritdoc/>
protected internal sealed override Task ReceiveAsync(IEnumerable<ChatMessageContent> history, CancellationToken cancellationToken)
protected internal sealed override Task ReceiveAsync(IReadOnlyList<ChatMessageContent> history, CancellationToken cancellationToken)
{
this._history.AddRange(history);

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/Agents/Abstractions/Internal/BroadcastQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.SemanticKernel.Agents.Internal;
/// <summary>
/// Utility class used by <see cref="AgentChat"/> to manage the broadcast of
/// conversation messages via the <see cref="AgentChannel"/>.
/// (<see cref="AgentChannel.ReceiveAsync(IEnumerable{ChatMessageContent}, System.Threading.CancellationToken)"/>.)
/// (<see cref="AgentChannel.ReceiveAsync"/>.)
/// </summary>
/// <remarks>
/// Maintains a set of channel specific queues, each with individual locks, in addition to a global state lock.
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/Agents/UnitTests/AgentChannelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected internal override IAsyncEnumerable<ChatMessageContent> GetHistoryAsync
throw new NotImplementedException();
}

protected internal override Task ReceiveAsync(IEnumerable<ChatMessageContent> history, CancellationToken cancellationToken = default)
protected internal override Task ReceiveAsync(IReadOnlyList<ChatMessageContent> history, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/Agents/UnitTests/Internal/BroadcastQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected internal override IAsyncEnumerable<ChatMessageContent> InvokeAsync(Age
throw new NotImplementedException();
}

protected internal override async Task ReceiveAsync(IEnumerable<ChatMessageContent> history, CancellationToken cancellationToken = default)
protected internal override async Task ReceiveAsync(IReadOnlyList<ChatMessageContent> history, CancellationToken cancellationToken = default)
{
this.ReceivedMessages.AddRange(history);
this.ReceiveCount += 1;
Expand All @@ -164,7 +164,7 @@ protected internal override IAsyncEnumerable<ChatMessageContent> InvokeAsync(Age
throw new NotImplementedException();
}

protected internal override async Task ReceiveAsync(IEnumerable<ChatMessageContent> history, CancellationToken cancellationToken = default)
protected internal override async Task ReceiveAsync(IReadOnlyList<ChatMessageContent> history, CancellationToken cancellationToken = default)
{
await Task.Delay(this.ReceiveDuration, cancellationToken);

Expand Down

0 comments on commit cbbaa59

Please sign in to comment.