code: def render_tasks(
      args: Namespace, tasks: Dict[str, v1AllocationSummary]
  ) -> None:
      """Render tasks for JSON, tabulate or csv output.
  
      The tasks parameter requires a map from allocation IDs to v1AllocationSummary
      describing individual tasks.
      """
  
      def agent_info(t: v1AllocationSummary) -> Union[str, List[str]]:
          if t.resources is None:
              return "unassigned"
          agents = [
              a for r in t.resources for a in (r.agentDevices or {})
          ]
          if len(agents) == 1:
              agent = agents[0]  # type: str
              return agent
          return agents
  
      if args.json:
          render.print_json(
              {a: t.to_json() for (a, t) in tasks.items()}
          )
          return
  
      headers = [
          "Task ID",
          "Allocation ID",
          "Name",
          "Slots Needed",
          "Registered Time",
          "Agent",
          "Priority",
          "Resource Pool",
          "Ports",
      ]
      values = [
          [
              task.taskId,
              task.allocationId,
              task.name,
              task.slotsNeeded,
              render.format_time(task.registeredTime),
              agent_info(task),
              task.priority
              if task.schedulerType == "priority"
              else "N/A",
              task.resourcePool,
              ",".join(
                  map(
                      str,
                      sorted(
                          [
                              pp.port
                              for pp in (task.proxyPorts or [])
                              if pp.port is not None
                          ]
                      ),
                  )
              ),
          ]
          for task_id, task in sorted(
              tasks.items(),
              key=lambda tup: (
                  render.format_time(tup[1].registeredTime),
              ),
          )
      ]
  
      render.tabulate_or_csv(headers, values, args.csv)
  
file_path: determined/harness/determined/cli/task.py
imports: from argparse import Namespace
  from functools import partial
  from typing import Any, Dict, List, Union, cast
  from termcolor import colored
  from determined import cli
  from determined.cli import ntsc, render
  from determined.common import api
  from determined.common.api import authentication, bindings
  from determined.common.api.bindings import v1AllocationSummary
  from determined.common.declarative_argparse import Arg, Cmd, Group
label_desc: Use image node_id 1 for calling a global function with example usage: render_tasks(args, tasks) and returns: agents, str, agent