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

Code before:

**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:

    ```json
    {{
        "checks": [
            {{
                "predicate_number": "1",
                "rationale": "<EXPLANATION WHY THE PREDICATE IS RELEVANT OR IRRELEVANT FOR THE CURRENT STATE OF THE INTERACTION>"

Review comment (performance):
I suggest bringing back "There are exactly {len(guidelines)} predicates". It helped fix some hallucinations in some cases, where gpt 3.5 would imagine there are more predicates than given.

Also, **very important to remember**, while working on this you switched to GPT 4 for guideline filtering. This was a big step, as it means that every conversation would cost us around $50-$100 instead $5-$10 (!!!). So, the real test should in reality have been done on GPT 3.5.

However, for our MVP, which won't run in large scales, this is fine for now.

But do not that, as in this case, it's important to be careful not to remove things which may seem a bit redundant at first, but in fact helped the performance of cheaper LLMs. :)

Code after:

**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:

    ```json
    {{
        "checks": [
            {{
                "predicate_number": "1",
                "rationale": "<EXPLANATION WHY THE PREDICATE IS