Table of Contents

Class TypeSubscription

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

This subscription matches on topics based on the exact 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 TypeSubscription : ISubscriptionDefinition
Inheritance
TypeSubscription
Implements
Inherited Members

Remarks

Example:

var subscription = new TypeSubscription("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".

Constructors

TypeSubscription(string, AgentType, string?)

Initializes a new instance of the TypeSubscription class.

public TypeSubscription(string topicType, AgentType agentType, string? id = null)

Parameters

topicType string

The exact topic type 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

TopicType

Gets the exact topic type used for matching.

public string TopicType { 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 an exact type match.

public bool Matches(TopicId topic)

Parameters

topic TopicId

The topic to check.

Returns

bool

true if the topic's type matches exactly, false otherwise.