def create_ag2_event(type: Optional[str] = None, **kwargs: Any) -> "BaseEvent":
type = type or "text"
if type not in EVENT_CLASSES:
raise ValueError(f"Unknown event type: {type}")
# Get the ag2 event class
cls = EVENT_CLASSES[type]
content = kwargs.pop("content", {})
kwargs.update(content)
return cls(**kwargs)