Skip to content

conversation

Conversation

Captures the interaction between a user and an agent.

Attributes:

Name Type Description
messages list

A list of tuples of the form (role, message).

turns int

The number of turns in the conversation.

Source code in src/agenteval/conversation.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Conversation:
    """Captures the interaction between a user and an agent.

    Attributes:
        messages (list): A list of tuples of the form (role, message).
        turns (int): The number of turns in the conversation.
    """

    def __init__(self):
        self.messages = []
        self.turns = _START_TURN_COUNT

    def __iter__(self):
        """Allow iteration over conversation messages."""
        return iter(self.messages)

    def add_turn(self, user_message: str, agent_response: str):
        """Record a turn in the conversation.

        Args:
            user_message (str): The users's message
            agent_response (str): The agent's response to the user's message

        Increments the `turn` counter by `1`.
        """
        self.messages.extend([(_USER, user_message), (_AGENT, agent_response)])
        self.turns += 1

__iter__()

Allow iteration over conversation messages.

Source code in src/agenteval/conversation.py
21
22
23
def __iter__(self):
    """Allow iteration over conversation messages."""
    return iter(self.messages)

add_turn(user_message, agent_response)

Record a turn in the conversation.

Parameters:

Name Type Description Default
user_message str

The users's message

required
agent_response str

The agent's response to the user's message

required

Increments the turn counter by 1.

Source code in src/agenteval/conversation.py
25
26
27
28
29
30
31
32
33
34
35
def add_turn(self, user_message: str, agent_response: str):
    """Record a turn in the conversation.

    Args:
        user_message (str): The users's message
        agent_response (str): The agent's response to the user's message

    Increments the `turn` counter by `1`.
    """
    self.messages.extend([(_USER, user_message), (_AGENT, agent_response)])
    self.turns += 1