autogen_core._default_topic 源代码
from ._message_handler_context import MessageHandlerContext
from ._topic import TopicId
[文档]
class DefaultTopicId(TopicId):
"""DefaultTopicId 为 TopicId 的 topic_id 和 source 字段提供了一个合理的默认值。
如果在消息处理器的上下文中创建,source 将被设置为消息处理器的 agent_id,否则将被设置为 "default"。
Args:
type (str, optional): 要发布消息的主题类型。默认为 "default"。
source (str | None, optional): 要发布消息的主题来源。如果为 None,在消息处理器上下文中 source 将被设置为消息处理器的 agent_id,否则将被设置为 "default"。默认为 None。
"""
def __init__(self, type: str = "default", source: str | None = None) -> None:
if source is None:
try:
source = MessageHandlerContext.agent_id().key
# If we aren't in the context of a message handler, we use the default source
except RuntimeError:
source = "default"
super().__init__(type, source)