Repository: phidatahq/phidata
File: libs/agno/agno/agent/agent.py (Python)

Code before:
            self.culture_manager.create_cultural_knowledge(message=run_messages.user_message.get_content_string())

    async def _acreate_cultural_knowledge(
        self,
        run_messages: RunMessages,
    ):
        if (
            run_messages.user_message is not None
            and self.culture_manager is not None
            and self.update_cultural_knowledge
        ):
            log_debug("Creating cultural knowledge.")
            await self.culture_manager.acreate_cultural_knowledge(
                message=run_messages.user_message.get_content_string()
            )

    def _make_memories(
        self,
        run_messages: RunMessages,
        user_id: Optional[str] = None,
    ):
        user_message_str = (
            run_messages.user_message.get_content_string() if run_messages.user_message is not None else None
        )
        if user_message_str is not None and user_message_str.strip() != "" and self.memory_manager is not None:
            log_debug("Creating, updating or deleting user memories.")
            self.memory_manager.create_user_memories(  # type: ignore
                message=user_message_str,
                user_id=user_id,
                agent_id=self.id,
            )

        if run_messages.extra_messages is not None and len(run_messages.extra_messages) > 0:
            parsed_messages = []
            for _im in run_messages.extra_messages:
                if isinstance(_im, Message):
                    parsed_messages.append(_im)
                elif isinstance(_im, dict):
                    try:
                        parsed_messages.append(Message(**_im))
                    except Exception as e:
                        log_warning(f"Failed to validate message during memory update: {e}")
                else:
                    log_warning(f"Unsupported message type: {type(_im)}")
                    continue

            # Filter out messages with empty content before passing to memory manager
            non_empty_messages = [
                msg
                for msg in parsed_messages
                if msg.content and (not isinstance(msg.content, str) or msg.content.strip() != "")

Review comment (suggestion):
It might not execute any of these actions, right? We should say something like:

`Managing user memories`

Code after:
            self.culture_manager.create_cultural_knowledge(message=run_messages.user_message.get_content_string())

    async def _acreate_cultural_knowledge(
        self,
        run_messages: RunMessages,
    ):
        if (
            run_messages.user_message is not None
            and self.culture_manager is not None
            and self.update_cultural_knowledge
        ):
            log_debug("Creating cultural knowledge.")
            await self.culture_manager.acreate_cultural_knowledge(
                message=run_messages.user_message.get_content_string()
            )

    def _make_memories(
        self,
        run_messages: RunMessages,
        user_id: Optional[str] = None,
    ):
        user_message_str = (
            run_messages.user_message.get_content_string() if run_messages.user_message is not None else None
        )
        if user_message_str is not None and user_message_str.strip() != "" and self.memory_manager is not None:
            log_debug("Managing user memories")
            self.memory_manager.create_user_memories(  # type: ignore
                message=user_message_str,
                user_id=user_id,
                agent_id=self.id,
            )

        if run_messages.extra_messages is not None and len(run_messages.extra_messages) > 0:
            parsed_messages = []
            for _im in run_messages.extra_messages:
                if isinstance(_im, Message):
                    parsed_messages.append(_im)
                elif isinstance(_im, dict):
                    try:
                        parsed_messages.append(Message(**_im))
                    except Exception as e:
                        log_warning(f"Failed to validate message during memory update: {e}")
                else:
                    log_warning(f"Unsupported message type: {type(_im)}")
                    continue

            # Filter out messages with empty content before passing to memory manager
            non_empty_messages = [
                msg
                for msg in parsed_messages
                if msg.content and (not isinstance(msg.content, str) or msg.content.strip() != "")