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

Code before:
        context_values = context_variables_to_json(context_variables)
        predicates = "\n".join(f"{i}) {g.predicate}" for i, g in enumerate(guidelines, start=1))
        prompt = """
### Definition of Predicate Relevance Evaluation:
This process involves assessing the relevance of predefined predicates 
to the last known state of an interaction between an AI assistant and a user.

**Objective**: Determine the applicability of each predicate to the concluding 
state of the interaction based on a given set of interactions.

**Task Description**:
1. **Input**:
"""

        if interaction_history:
            prompt += f"""\
    - Interaction Events: ###
    {json_events}
    ###
    """
        else:
            prompt += """\
    - Interaction Context: ###
    You, an AI assistant, 
    are currently engaged in the initial phase of an online session with a user.
    The interaction has just commenced, and no substantial exchange has occurred yet.
    ###
    """

        if context_variables:
            prompt += f"""
    The following is additional information available 
    about the user and the context of the interaction: ###
    {context_values}
    ###
    """

        prompt += f"""
    - Predicate List: ###
    {predicates}
    ###

2. **Process**:
   a. Examine the provided interaction events to discern 
   the latest state of interaction between the user and the assistant.
   b. Determine the applicability of each predicate based on the most recent interaction state.
   c. Assign a relevance score to each predicate, from 1 to 10, where 10 denotes high relevance.

3. **Output**:
   - Create a JSON object summarizing relevance for each predicate, formatted as follows:


Review comment (suggestion):
I think it's also important to say that "the user has not *chosen* to engage with you", to help it understand that the user doesn't *have to* engage, and the assistant doesn't *have to* engage either.

Code after:
        context_values = context_variables_to_json(context_variables)
        predicates = "\n".join(f"{i}) {g.predicate}" for i, g in enumerate(guidelines, start=1))
        prompt = """
### Definition of Predicate Relevance Evaluation:
This process involves assessing the relevance of predefined predicates 
to the last known state of an interaction between an AI assistant and a user.

**Objective**: Determine the applicability of each predicate to the latest 
state based on a stream of events.

**Task Description**:
1. **Input**:
"""

        if interaction_history:
            prompt += f"""\
    The following is a list of events describing a back-and-forth
    interaction between you, an AI assistant, and a user: ###
    {json_events}
    ###
    """
        else:
            prompt += """\
    You, an AI assistant, are now present in an online interaction session with a user.
    The session has just started, 
    and the user hasn't said anything yet nor chosen to engage with you.
    """

        if context_variables:
            prompt += f"""
    The following is additional information available 
    about the user and the context of the interaction: ###
    {context_values}
    ###
    """

        prompt += f"""
    - Predicate List: ###
    {predicates}
    ###

2. **Process**:
   a. Examine the provided interaction events to discern 
   the latest state of interaction between the user and the assistant.
   b. Determine the applicability of each predicate based on the most recent interaction state.
     Note: There are exactly {len(guidelines)} predicates.
   c. Assign a relevance score to each predicate, from 1 to 10, where 10 denotes high relevance.

3. **Output**:
   - Create a JSON object summarizing relevance for each predicate, formatted as follows: