code: def terminate_running_agents(
      agent_tag_name: str, boto3_session: boto3.session.Session
  ) -> None:
      ec2 = boto3_session.client("ec2")
      waiter = ec2.get_waiter("instance_terminated")
  
      response = ec2.describe_instances(
          Filters=[
              {"Name": "tag:Name", "Values": [agent_tag_name]},
              {
                  "Name": "instance-state-name",
                  "Values": ["running", "pending"],
              },
          ]
      )
  
      reservations = response["Reservations"]
  
      instance_ids = []
      for reservation in reservations:
          for instance in reservation["Instances"]:
              instance_ids.append(instance["InstanceId"])
  
      if instance_ids:
          ec2.terminate_instances(InstanceIds=instance_ids)
          for n in range(NUM_WAITS):
              print("Waiting For Agents To Terminate")
              try:
                  waiter.wait(
                      InstanceIds=instance_ids,
                      WaiterConfig={"Delay": 10},
                  )
                  break
              except WaiterError as e:
                  if n == NUM_WAITS - 1:
                      raise e
  
imports: import sys
  import threading
  import time
  from typing import Any, Callable, Dict, List, Optional, Tuple
  import boto3
  import tqdm
  from botocore.exceptions import ClientError, WaiterError
  from determined.deploy.aws import constants
label_desc: Use image node_id 18 for calling a global function with example usage: terminate_running_agents(agent_tag_name, boto3_session) without return types