Repository: emcie-co/parlant
File: src/parlant/core/engines/alpha/engine.py (Python)

Code before:
                [
                    f"When {p.guideline.content.condition}, then {p.guideline.content.action}"
                    for p in propositions
                ]
            )

        if staged_events:
            context += str([e.data for e in staged_events])

        if context:
            return await self._glossary_store.find_relevant_terms(
                term_set=agent.id,
                query=context,
            )
        return []

    async def _utter_requests_to_guideline_propositions(
        self,
        actions: Sequence[UtteranceRequest],
    ) -> Sequence[GuidelineProposition]:
        def utterance_to_proposition(utterance: UtteranceRequest) -> GuidelineProposition:
            ratioanles = {
                UtteranceReason.BUY_TIME: "An external module has determined that this response is necessary, and you must adhere to it.",
                UtteranceReason.FOLLOW_UP: "An external module has determined that this response is necessary, and you must adhere to it.",
            }

            conditions = {
                UtteranceReason.BUY_TIME: "always",
                UtteranceReason.FOLLOW_UP: "always",
            }

            return GuidelineProposition(
                guideline=Guideline(
                    id=GuidelineId(""),
                    creation_utc=datetime.now(timezone.utc),
                    content=GuidelineContent(
                        condition=conditions[utterance.reason],
                        action=utterance.action,
                    ),
                ),
                rationale=ratioanles[utterance.reason],
                score=10,
            )

        return [utterance_to_proposition(action) for action in actions]


async def fresh_value(
    context_variable_store: ContextVariableStore,
    service_registery: ServiceRegistry,
    agent_id: AgentId,

Review comment (bug):
Maybe include at least some indicator here so that it doesn't look like a bug: `GuidelineId("<utterance-request-{i}>")` where `i` is received by enumerating `actions` (which BTW should be named `requests`)

Code after:

        if context:
            return await self._glossary_store.find_relevant_terms(
                term_set=agent.id,
                query=context,
            )
        return []

    async def _utter_requests_to_guideline_propositions(
        self,
        requests: Sequence[UtteranceRequest],
    ) -> Sequence[GuidelineProposition]:
        def utterance_to_proposition(i: int, utterance: UtteranceRequest) -> GuidelineProposition:
            rationales = {
                UtteranceReason.BUY_TIME: "An external module has determined that this response is necessary, and you must adhere to it.",
                UtteranceReason.FOLLOW_UP: "An external module has determined that this response is necessary, and you must adhere to it.",
            }

            conditions = {
                UtteranceReason.BUY_TIME: "always",
                UtteranceReason.FOLLOW_UP: "always",
            }

            return GuidelineProposition(
                guideline=Guideline(
                    id=GuidelineId(f"<utterance-request-{i}>"),
                    creation_utc=datetime.now(timezone.utc),
                    content=GuidelineContent(
                        condition=conditions[utterance.reason],
                        action=utterance.action,
                    ),
                ),
                rationale=rationales[utterance.reason],
                score=10,
            )

        return [utterance_to_proposition(i, request) for i, request in enumerate(requests, start=1)]


async def fresh_value(
    context_variable_store: ContextVariableStore,
    service_registery: ServiceRegistry,
    agent_id: AgentId,
    session: Session,
    variable_id: ContextVariableId,
    key: str,
    current_time: datetime,
) -> Optional[ContextVariableValue]:
    variable = await context_variable_store.read_variable(
        variable_set=agent_id,
        id=variable_id,