Repository: emcie-co/parlant
File: src/parlant/core/guidelines.py (Python)

Code before:
            creation_utc = creation_utc or datetime.now(timezone.utc)

            guideline = Guideline(
                id=GuidelineId(generate_id()),
                creation_utc=creation_utc,
                content=GuidelineContent(
                    condition=condition,
                    action=action,
                ),
                enabled=enabled,
            )

            await self._collection.insert_one(
                document=self._serialize(
                    guideline=guideline,
                    guideline_set=guideline_set,
                )
            )

        return guideline

    @override
    async def list_guidelines(
        self,
        guideline_set: str,
        show_disabled: bool = False,
    ) -> Sequence[Guideline]:
        async with self._lock.reader_lock:
            filters = {
                "guideline_set": {"$eq": guideline_set},
                **({"enabled": {"$eq": True}} if not show_disabled else {}),
            }

            return [
                self._deserialize(d)
                for d in await self._collection.find(filters=cast(Where, filters))
            ]

    @override
    async def read_guideline(
        self,
        guideline_set: str,
        guideline_id: GuidelineId,
    ) -> Guideline:
        async with self._lock.reader_lock:
            guideline_document = await self._collection.find_one(
                filters={
                    "guideline_set": {"$eq": guideline_set},
                    "id": {"$eq": guideline_id},
                }
            )

Review comment (suggestion):
This isn't the place to do it.
It's not like with events where they're *deleted* so we stop listing them.
Here the guideline is disabled but it should still be listed everywhere like API, CLI, and it shouldn't take extra effort or flags to do so.

It's only the engine itself which must filter out disabled guidelines.

Code after:
            creation_utc = creation_utc or datetime.now(timezone.utc)

            guideline = Guideline(
                id=GuidelineId(generate_id()),
                creation_utc=creation_utc,
                content=GuidelineContent(
                    condition=condition,
                    action=action,
                ),
                enabled=enabled,
            )

            await self._collection.insert_one(
                document=self._serialize(
                    guideline=guideline,
                    guideline_set=guideline_set,
                )
            )

        return guideline

    @override
    async def list_guidelines(
        self,
        guideline_set: str,
    ) -> Sequence[Guideline]:
        async with self._lock.reader_lock:
            return [
                self._deserialize(d)
                for d in await self._collection.find(
                    filters={
                        "guideline_set": {"$eq": guideline_set},
                    }
                )
            ]

    @override
    async def read_guideline(
        self,
        guideline_set: str,
        guideline_id: GuidelineId,
    ) -> Guideline:
        async with self._lock.reader_lock:
            guideline_document = await self._collection.find_one(
                filters={
                    "guideline_set": {"$eq": guideline_set},
                    "id": {"$eq": guideline_id},
                }
            )

        if not guideline_document: