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

Code before:
        guidelines: list[Guideline],
    ) -> str:
        json_events = events_to_json(interaction_history)
        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.


Review comment (suggestion):
I don't think you need the ### delimiters here, right? This is a simple general description of the context in which the agent is operating.

Also, the sentence "no substantial exchange has occurred yet" is problematic, as guidelines like, "The user hasn't engaged yet" may not apply when nothing was said yet—and it should. So, please set it back to "the user hasn't said anything yet nor chosen to engage with you."

Code after:
        guidelines: list[Guideline],
    ) -> str:
        json_events = events_to_json(interaction_history)
        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.