Table of Contents

Class TypePrefixSubscription

Namespace
Microsoft.AutoGen.Contracts
Assembly
Microsoft.AutoGen.Core.dll

This subscription matches on topics based on a prefix of the type and maps to agents using the source of the topic as the agent key. This subscription causes each source to have its own agent instance.

public class TypePrefixSubscription : ISubscriptionDefinition
Inheritance
TypePrefixSubscription
Implements
Inherited Members

Remarks

Example:

var subscription = new TypePrefixSubscription("t1", "a1");

In this case:

  • A TopicId with type "t1" and source "s1" will be handled by an agent of type "a1" with key "s1".
  • A TopicId with type "t1" and source "s2" will be handled by an agent of type "a1" with key "s2".
  • A TopicId with type "t1SUFFIX" and source "s2" will be handled by an agent of type "a1" with key "s2".

Constructors

TypePrefixSubscription(string, AgentType, string?)

Initializes a new instance of the TypePrefixSubscription class.

public TypePrefixSubscription(string topicTypePrefix, AgentType agentType, string? id = null)

Parameters

topicTypePrefix string

Topic type prefix to match against.

agentType AgentType

Agent type to handle this subscription.

id string

Unique identifier for the subscription. If not provided, a new UUID will be generated.

Properties

AgentType

Gets the agent type that handles this subscription.

public AgentType AgentType { get; }

Property Value

AgentType

Id

Gets the unique identifier of the subscription.

public string Id { get; }

Property Value

string

TopicTypePrefix

Gets the topic type prefix used for matching.

public string TopicTypePrefix { get; }

Property Value

string

Methods

Equals(object?)

Determines whether the specified object is equal to the current subscription.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

GetHashCode()

Returns a hash code for this instance.

public override int GetHashCode()

Returns

int

A hash code for this instance, suitable for use in hashing algorithms and data structures.

MapToAgent(TopicId)

Maps a TopicId to an AgentId. Should only be called if Matches(TopicId) returns true.

public AgentId MapToAgent(TopicId topic)

Parameters

topic TopicId

The topic to map.

Returns

AgentId

An AgentId representing the agent that should handle the topic.

Exceptions

InvalidOperationException

Thrown if the topic does not match the subscription.

Matches(TopicId)

Checks if a given TopicId matches the subscription based on its type prefix.

public bool Matches(TopicId topic)

Parameters

topic TopicId

The topic to check.

Returns

bool

true if the topic's type starts with the subscription's prefix, false otherwise.