def convert_session_to_eval_invocations(session: Session) -> list[Invocation]:
  """Converts a session data into a list of Invocation.

  Args:
      session: The session that should be converted.

  Returns:
      list: A list of invocation.
  """
  invocations: list[Invocation] = []
  events = session.events if session and session.events else []

  for event in events:
    if event.author == 'user':
      if not event.content or not event.content.parts:
        continue

      # The content present in this event is the user content.
      user_content = event.content
      invocation_id = event.invocation_id
      invocaton_timestamp = event.timestamp

      # Find the corresponding tool usage or response for the query
      tool_uses: list[genai_types.FunctionCall] = []
      intermediate_responses: list[Tuple[str, list[genai_types.Part]]] = []

      # Check subsequent events to extract tool uses or responses for this turn.
      for subsequent_event in events[events.index(event) + 1 :]:
        event_author = subsequent_event.author or 'agent'
        if event_author == 'user':
          # We found an event where the author was the user. This means that a
          # new turn has started. So close this turn here.
          break

        if not subsequent_event.content or not subsequent_event.content.parts:
          continue

        intermediate_response_parts = []
        for subsequent_part in subsequent_event.content.parts:
          # Some events have both function call and reference
          if subsequent_part.function_call:
            tool_uses.append(subsequent_part.function_call)
          elif subsequent_part.text:
            # Also keep track of all the natural language responses that
            # agent (or sub agents) generated.
            intermediate_response_parts.append(subsequent_part)

        if intermediate_response_parts:
          # Only add an entry if there any intermediate entries.
          intermediate_responses.append(
              (event_author, intermediate_response_parts)
          )

      # If we are here then either we are done reading all the events or we
      # encountered an event that had content authored by the end-user.
      # This, basically means an end of turn.
      # We assume that the last natural language intermediate response is the
      # final response from the agent/model. We treat that as a reference.
      invocations.append(
          Invocation(
              user_content=user_content,
              invocation_id=invocation_id,
              creation_timestamp=invocaton_timestamp,
              intermediate_data=IntermediateData(
                  tool_uses=tool_uses,
                  intermediate_responses=intermediate_responses[:-1],
              ),
              final_response=genai_types.Content(
                  parts=intermediate_responses[-1][1]
              ),
          )
      )

  return invocations
Converts a session data into a list of Invocation.

  Args:
      session: The session that should be converted.

  Returns:
      list: A list of invocation.
  
src/google/adk/cli/utils/evals.py