Repository: emcie-co/parlant
File: server/tests/engines/alpha/test_supervision.py (Python)

Code before:


@given(
    parsers.parse(
        "that the {guideline_name} guideline is proposed with a priority of {score} because {rationale}"  # noqa
    )
)
def given_a_guideline_proposition(
    context: _TestContext,
    guideline_name: str,
    score: int,
    rationale: str,
) -> None:
    guideline = context.guidelines[guideline_name]
    context.guideline_proposition[guideline_name] = GuidelineProposition(
        guideline=guideline,
        score=score,
        rationale=rationale,
    )


@when("messages are produced", target_fixture="produced_events")
def when_processing_is_triggered(
    context: _TestContext,
) -> list[ProducedEvent]:
    agents = [
        Agent(
            id=AgentId("123"),
            creation_utc=datetime.now(timezone.utc),
            name="Test Agent",
            description="You are an agent that work for Emcie",
        )
    ]

    message_event_producer = MessageEventProducer()

    message_events = context.sync_await(
        message_event_producer.produce_events(
            agents=agents,
            context_variables=[],
            interaction_history=context.intercations_history,
            ordinary_guideline_propositions=list(context.guideline_proposition.values()),
            tool_enabled_guideline_propositions={},
            staged_events=[],
        )
    )

    return list(message_events)


@then(parsers.parse("the message should contain {something}"))

Review comment (bug):
We need to add a test case that tests this new feature.
Specify a BDD test scenario that takes agent identity into consideration.

Process:
1. Create a test scenario that is supposed to lean on agent description to verify its outcome (e.g., specify in the identity that it's an agent that sells pizza, then specify a guideline that says "do your job when a user says hello", and then `nlp_test` that it's trying to sell pizza.
2. Don't yet add the correct agent description to the test code. First, let's ensure that the test fails after it was first written.
3. Add the proper agent description in the test code.
4. Make sure that the test passes.

Code after:


@given(
    parsers.parse(
        "that the {guideline_name} guideline is proposed with a priority of {score} because {rationale}"  # noqa
    )
)
def given_a_guideline_proposition(
    context: _TestContext,
    guideline_name: str,
    score: int,
    rationale: str,
) -> None:
    guideline = context.guidelines[guideline_name]
    context.guideline_proposition[guideline_name] = GuidelineProposition(
        guideline=guideline,
        score=score,
        rationale=rationale,
    )


@when("messages are produced", target_fixture="produced_events")
def when_processing_is_triggered(
    context: _TestContext,
) -> list[ProducedEvent]:
    agents = [
        Agent(
            id=AgentId("123"),
            creation_utc=datetime.now(timezone.utc),
            name="Test Agent",
            description="You are an agent that works for Emcie",
        )
    ]

    message_event_producer = MessageEventProducer()

    message_events = context.sync_await(
        message_event_producer.produce_events(
            agents=agents,
            context_variables=[],
            interaction_history=context.intercations_history,
            ordinary_guideline_propositions=list(context.guideline_proposition.values()),
            tool_enabled_guideline_propositions={},
            staged_events=[],
        )
    )

    return list(message_events)


@then(parsers.parse("the message should contain {something}"))