Skip to content

Commit

Permalink
Revise utterance BDD tests and steps
Browse files Browse the repository at this point in the history
  • Loading branch information
kichanyurd committed Dec 27, 2024
1 parent 35ec947 commit 0ee7db6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 45 deletions.
24 changes: 22 additions & 2 deletions tests/core/common/engines/alpha/steps/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

import asyncio
from typing import cast
from pytest_bdd import given, when
from pytest_bdd import given, when, parsers
from unittest.mock import AsyncMock

from parlant.core.agents import Agent, AgentId, AgentStore
from parlant.core.customers import CustomerStore
from parlant.core.engines.alpha.engine import AlphaEngine
from parlant.core.engines.alpha.message_event_generator import MessageEventGenerator
from parlant.core.emissions import EmittedEvent
from parlant.core.engines.types import Context
from parlant.core.engines.types import Context, UtteranceReason, UtteranceRequest
from parlant.core.emission.event_buffer import EventBuffer
from parlant.core.sessions import SessionId, SessionStore

Expand All @@ -45,6 +45,26 @@ def given_a_faulty_message_production_mechanism(
generator.generate_events = AsyncMock(side_effect=Exception()) # type: ignore


@step(
given,
parsers.parse('an utterance request "{action}", to {do_something}'),
)
def given_a_follow_up_utterance_request(
context: ContextOfTest, action: str, do_something: str
) -> UtteranceRequest:
utterance_request = UtteranceRequest(
action=action,
reason={
"follow up with the customer": UtteranceReason.FOLLOW_UP,
"buy time": UtteranceReason.BUY_TIME,
}[do_something],
)

context.actions.append(utterance_request)

return utterance_request


@step(when, "processing is triggered", target_fixture="emitted_events")
def when_processing_is_triggered(
context: ContextOfTest,
Expand Down
31 changes: 0 additions & 31 deletions tests/core/common/engines/alpha/steps/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from parlant.core.customers import CustomerStore
from parlant.core.engines.alpha.utils import emitted_tool_event_to_dict
from parlant.core.emissions import EmittedEvent
from parlant.core.engines.types import UtteranceReason, UtteranceRequest
from parlant.core.nlp.moderation import ModerationTag
from parlant.core.sessions import (
MessageEventData,
Expand Down Expand Up @@ -195,36 +194,6 @@ def given_a_flagged_customer_message(
return session.id


@step(
given,
parsers.parse('an utterance with action of "{action}", to follow up with the customer'),
)
def given_a_follow_up_utterance_request(
context: ContextOfTest,
action: str,
) -> UtteranceRequest:
utterance_request = UtteranceRequest(action=action, reason=UtteranceReason.FOLLOW_UP)

context.actions.append(utterance_request)

return utterance_request


@step(
given,
parsers.parse('an utterance with action of "{action}", to buy time'),
)
def given_a_buy_time_utterance_request(
context: ContextOfTest,
action: str,
) -> UtteranceRequest:
utterance_request = UtteranceRequest(action=action, reason=UtteranceReason.BUY_TIME)

context.actions.append(utterance_request)

return utterance_request


@step(
when,
parsers.parse("the last {num_messages:d} messages are deleted"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@ Feature: Utterances
And an agent
And an empty session

Scenario: A buy-time message is determined by the actions sent from utter engine operation
Given an utterance with action of "inform the user that more information is coming", to buy time
Scenario: The agent utters a message aligned with an action to buy time
Given an utterance request "inform the customer that more information is coming", to buy time
When uttering is triggered
Then a single message event is emitted
And the message contains that more information is coming
And the message mentions that more information is coming

Scenario: A buy-time message of thinking as an utter action
Given an utterance with action of "tell the user 'Thinking...'", to buy time
Scenario: The agent utters a message aligned with an action to follow up with the customer
Given an utterance request "suggest proceeding to checkout", to follow up with the customer
When uttering is triggered
Then a single message event is emitted
And the message contains thinking

Scenario: A follow-up message is determined by the actions sent from utter engine operation
Given an utterance with action of "ask the user if he need assistant with the blue-yellow feature", to follow up with the customer
When uttering is triggered
Then a single message event is emitted
And the message contains asking the user if he need help with the blue-yellow feature
And the message mentions proceeding to checkout

0 comments on commit 0ee7db6

Please sign in to comment.