def parse_t5_response(response: str) -> Tuple[bool, bool, Sequence[Term]]:
  """Parse the response of the T5 agent model.

  Args:
    response: The T5 response given as a string.

  Returns:
    A triple: (success, stop, terms).
    success indicates that the response was correctly parsed.
    stop indicates the stop action
    terms is a list of length 3 containing the newly added/subtracted/or-terms.
  """
  stop = response == "Stop."

  def parse_by_regexp(regexp_string: str, response: str) -> Term:
    field = ""
    term = ""
    for match in re.findall(regexp_string, response):
      if isinstance(match, tuple):
        field, term = match
      else:
        term = match
      break
    return Term(field.lower(), term, term_type="")

  # pylint: disable=g-complex-comprehension
  terms = [
      parse_by_regexp(regexp_string, response) for regexp_string in [
          r"(Contents|Title) must contain: '(.+?)'.",
          r"(Contents|Title) cannot contain: '(.+?)'.",
          r"Should contain: '(.+?)'."
      ]
  ]
  # pylint: enable=g-complex-comprehension

  success = stop
  for term in terms:
    success = success or bool(term.term)
  return success, stop, terms
Parse the response of the T5 agent model.

  Args:
    response: The T5 response given as a string.

  Returns:
    A triple: (success, stop, terms).
    success indicates that the response was correctly parsed.
    stop indicates the stop action
    terms is a list of length 3 containing the newly added/subtracted/or-terms.
  
language/search_agents/t5/t5_agent_lib.py