Skip to content

Commit

Permalink
fix: Typos and other PR comments
Browse files Browse the repository at this point in the history
* Creates a named type for the Participants dictionary in GroupChatOptions
  • Loading branch information
lokitoth committed Feb 7, 2025
1 parent c12138d commit ad643f1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Microsoft.AutoGen.AgentChat.Abstractions;

/// <summary>
/// A stateful condition that deterines when a conversation should be terminated.
/// A stateful condition that determines when a conversation should be terminated.
///
/// A termination condition takes a sequences of <see cref="AgentMessage"/> objects since the last time the
/// condition was checked, and returns a <see cref="StopMessage"/> if the conversation should be terminated,
Expand All @@ -17,7 +17,7 @@ namespace Microsoft.AutoGen.AgentChat.Abstractions;
public interface ITerminationCondition
{
/// <summary>
/// Checkes if the termination condition has been reached
/// Checks if the termination condition has been reached
/// </summary>
bool IsTerminated { get; }

Expand Down Expand Up @@ -86,27 +86,27 @@ internal sealed class CombinerCondition : ITerminationCondition
/// <summary>
/// Create a new <see cref="CombinerCondition"/> with the given conjunction and clauses.
/// </summary>
/// <param name="conjuction">The conjunction to use when combining the clauses.</param>
/// <param name="conjunction">The conjunction to use when combining the clauses.</param>
/// <param name="clauses">The termination conditions to combine.</param>
public CombinerCondition(bool conjuction, params IEnumerable<ITerminationCondition> clauses)
public CombinerCondition(bool conjunction, params IEnumerable<ITerminationCondition> clauses)
{
// Flatten the list of clauses by unwrapping included CombinerConditions if their
// conjuctions match (since combiners with associative conjuctions can be hoisted).
// conjunctions match (since combiners with associative conjunctions can be hoisted).
IEnumerable<ITerminationCondition> flattened =
clauses.SelectMany(c =>
(c is CombinerCondition combiner && combiner.conjunction == conjuction)
(c is CombinerCondition combiner && combiner.conjunction == conjunction)
? (IEnumerable<ITerminationCondition>)combiner.clauses
: new[] { c });

this.conjunction = conjuction;
this.conjunction = conjunction;

this.clauses = flattened.ToList();
}

/// <inheritdoc cref="ITerminationCondition.IsTerminated" />
public bool IsTerminated { get; private set; }

/// <inheritdoc cref="ITerminationCondition.Reset" />"/>
/// <inheritdoc cref="ITerminationCondition.Reset" />
public void Reset()
{
this.stopMessages.Clear();
Expand Down Expand Up @@ -149,7 +149,7 @@ public void Reset()
}
else if (this.conjunction)
{
// If any clause does not terminate, the conjuction does not terminate
// If any clause does not terminate, the conjunction does not terminate
raiseTermination = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected GroupChatBase(List<IChatAgent> participants, ITerminationCondition? te
{
AgentChatConfig config = new AgentChatConfig(participant, GroupTopicType, OutputTopicType);
this.Participants[participant.Name] = config;
this.GroupChatOptions.Participants[participant.Name] = (config.ParticipantTopicType, participant.Description);
this.GroupChatOptions.Participants[participant.Name] = new GroupParticipant(config.ParticipantTopicType, participant.Description);
}

this.messageThread = new List<AgentMessage>(); // TODO: Allow injecting this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public GroupChatManagerBase(GroupChatOptions options) : base()
protected string GroupChatTopicType => this.options.GroupChatTopicType;
protected string OutputTopicType => this.options.OutputTopicType;

protected Dictionary<string, (string TopicType, string Description)> Participants => this.options.Participants;
protected Dictionary<string, GroupParticipant> Participants => this.options.Participants;

protected ITerminationCondition? TerminationCondition => this.options.TerminationCondition;
protected int? MaxTurns => this.options.MaxTurns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@

namespace Microsoft.AutoGen.AgentChat.GroupChat;

public struct GroupParticipant(string topicType, string description)
{
public string TopicType { get; } = topicType;
public string Description { get; } = description;

// Destructuring from a tuple
public GroupParticipant((string topicType, string description) tuple) : this(tuple.topicType, tuple.description)
{
}

// Destructuring to a tuple
public void Deconstruct(out string topicType, out string description)
{
topicType = this.TopicType;
description = this.Description;
}

public static implicit operator GroupParticipant((string topicType, string description) tuple) => new GroupParticipant(tuple);
public static implicit operator (string topicType, string description)(GroupParticipant participant) => (participant.TopicType, participant.Description);
}

public class GroupChatOptions(string groupTopicType, string outputTopicType)
{
public string GroupChatTopicType { get; } = groupTopicType;
Expand All @@ -13,5 +34,5 @@ public class GroupChatOptions(string groupTopicType, string outputTopicType)
public ITerminationCondition? TerminationCondition { get; set; }
public int? MaxTurns { get; set; }

public Dictionary<string, (string TopicType, string Description)> Participants { get; } = new Dictionary<string, (string, string)>();
public Dictionary<string, GroupParticipant> Participants { get; } = new Dictionary<string, GroupParticipant>();
}

0 comments on commit ad643f1

Please sign in to comment.