# Buggy code
def __init__(
    self,
    name: str = None,
    labels: Iterable[str] = None,
    env_vars: dict = None,
    max_polls: int = None,
    agent_address: str = None,
    no_cloud_logs: bool = False,
) -> None:
    self.name = name or config.cloud.agent.get("name", "agent")
    self.labels = list(
        labels or ast.literal_eval(config.cloud.agent.get("labels", "[]"))
    )
    self.env_vars = env_vars or config.cloud.agent.get("env_vars", dict())
    self.max_polls = max_polls
    self.log_to_cloud = False if no_cloud_logs else True

    self.agent_address = agent_address or config.cloud.agent.get("agent_address", "")
    self._api_server = None  # type: ignore
    self._api_server_loop = None  # type: Optional[IOLoop]
    self._api_server_thread = None  # type: Optional[threading.Thread]

    logger = logging.getLogger(self.name)
    logger.setLevel(config.cloud.agent.get("level"))
    if not any([isinstance(h, logging.StreamHandler) for h in logger.handlers]):
        ch = logging.StreamHandler(sys.stdout)
        formatter = logging.Formatter(context.config.logging.format)
        formatter.converter = time.gmtime  # type: ignore
        ch.setFormatter(formatter)
        logger.addHandler(ch)

    self.logger = logger
    self.submitting_flow_runs = set()  # type: Set[str]

    self.logger.debug("Verbose logs enabled")
    self.logger.debug(f"Environment variables: {[*self.env_vars]}")
    self.logger.debug(f"Max polls: {self.max_polls}")
    self.logger.debug(f"Agent address: {self.agent_address}")
    self.logger.debug(f"Log to Cloud: {self.log_to_cloud}")

    token = config.cloud.agent.get("auth_token")

    self.logger.debug(f"Prefect backend: {config.backend}")

    self.client = Client(api_token=token)
    if config.backend == "cloud":
        self._verify_token(token)
        self.client.attach_headers({"X-PREFECT-AGENT-ID": self._register_agent()})


# Traceback (ValueError)
(dw_kube) dylanhughes@Dylans-MacBook-Pro-Prefect ~> kubectl get po                                                                                                                                                                                                            1
NAME                             READY   STATUS             RESTARTS   AGE
prefect-agent-74d7947c44-dsxxw   1/2     CrashLoopBackOff   5          5m14s
(dw_kube) dylanhughes@Dylans-MacBook-Pro-Prefect ~> kubectl logs prefect-agent-74d7947c44-dsxxw agent                                                                                                                                                                         1
Traceback (most recent call last):
File "/usr/local/bin/prefect", line 8, in <module>
sys.exit(cli())
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/prefect/cli/agent.py", line 278, in start
agent_address=agent_address,
File "/usr/local/lib/python3.6/site-packages/prefect/agent/kubernetes/agent.py", line 67, in __init__
no_cloud_logs=no_cloud_logs,
File "/usr/local/lib/python3.6/site-packages/prefect/agent/agent.py", line 102, in __init__
labels or ast.literal_eval(config.cloud.agent.get("labels", "[]"))
File "/usr/local/lib/python3.6/ast.py", line 85, in literal_eval
return _convert(node_or_string)
File "/usr/local/lib/python3.6/ast.py", line 84, in _convert
raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: <BoxList: ['prefect-data-warehouse']>
(dw_kube) dylanhughes@Dylans-MacBook-Pro-Prefect ~> prefect version
0.11.0

# Fixed code
def __init__(
    self,
    name: str = None,
    labels: Iterable[str] = None,
    env_vars: dict = None,
    max_polls: int = None,
    agent_address: str = None,
    no_cloud_logs: bool = False,
) -> None:
    self.name = name or config.cloud.agent.get("name", "agent")

    self.labels = labels or config.cloud.agent.get("labels", [])
    # quick hack in case config has not been evaluated to a list yet
    if isinstance(self.labels, str):
        self.labels = ast.literal_eval(self.labels)
    self.env_vars = env_vars or config.cloud.agent.get("env_vars", dict())
    self.max_polls = max_polls
    self.log_to_cloud = False if no_cloud_logs else True

    self.agent_address = agent_address or config.cloud.agent.get("agent_address", "")
    self._api_server = None  # type: ignore
    self._api_server_loop = None  # type: Optional[IOLoop]
    self._api_server_thread = None  # type: Optional[threading.Thread]

    logger = logging.getLogger(self.name)
    logger.setLevel(config.cloud.agent.get("level"))
    if not any([isinstance(h, logging.StreamHandler) for h in logger.handlers]):
        ch = logging.StreamHandler(sys.stdout)
        formatter = logging.Formatter(context.config.logging.format)
        formatter.converter = time.gmtime  # type: ignore
        ch.setFormatter(formatter)
        logger.addHandler(ch)

    self.logger = logger
    self.submitting_flow_runs = set()  # type: Set[str]

    self.logger.debug("Verbose logs enabled")
    self.logger.debug(f"Environment variables: {[*self.env_vars]}")
    self.logger.debug(f"Max polls: {self.max_polls}")
    self.logger.debug(f"Agent address: {self.agent_address}")
    self.logger.debug(f"Log to Cloud: {self.log_to_cloud}")

    token = config.cloud.agent.get("auth_token")

    self.logger.debug(f"Prefect backend: {config.backend}")

    self.client = Client(api_token=token)
    if config.backend == "cloud":
        self._verify_token(token)
        self.client.attach_headers({"X-PREFECT-AGENT-ID": self._register_agent()})