def query_to_prompt(query: str, addition_terms: Sequence[Term],
                    subtraction_terms: Sequence[Term],
                    or_terms: Sequence[Term]) -> str:
  """Produces a plaintext form of the current query with all modifiers.

  This is not the form to be used with Lucence but part of the T5 input.

  Args:
    query: The original query.
    addition_terms: Forced terms.
    subtraction_terms: Prohibited terms.
    or_terms: Optional terms.

  Returns:
    query_with_modifiers as a flat string representation.
  """
  res = []
  if query.strip():
    res = [f"Query: '{query}'."]

  def has_terms(terms):
    for operator in terms:
      if operator.term:
        return True
    return False

  # The or-terms are all joined together with commas.
  if has_terms(or_terms):
    res.append("Should contain: " + ", ".join(
        f"'{operator.term}'" for operator in or_terms if operator.term) + ".")

  if has_terms(addition_terms):
    res.append(" ".join(
        f"{operator.field.capitalize()} must contain: '{operator.term}'."
        for operator in addition_terms
        if operator.term))

  if has_terms(subtraction_terms):
    res.append(" ".join(
        f"{operator.field.capitalize()} cannot contain: '{operator.term}'."
        for operator in subtraction_terms
        if operator.term))

  return " ".join(r for r in res if r)
Produces a plaintext form of the current query with all modifiers.

  This is not the form to be used with Lucence but part of the T5 input.

  Args:
    query: The original query.
    addition_terms: Forced terms.
    subtraction_terms: Prohibited terms.
    or_terms: Optional terms.

  Returns:
    query_with_modifiers as a flat string representation.
  
language/search_agents/t5/t5_agent_lib.py