code: def test_sweep_scheduler_sweeps_stop_agent_hearbeat(
      user, sweep_config, num_workers, monkeypatch
  ):
      _patch_wandb_run(monkeypatch)
      monkeypatch.setattr(
          "wandb.sdk.launch.sweeps.scheduler.Scheduler._try_load_executable",
          lambda _: True,
      )
  
      api = internal.Api()
  
      def mock_agent_heartbeat(*args, **kwargs):
          return [{"type": "stop"}]
  
      api.agent_heartbeat = mock_agent_heartbeat
  
      def mock_get_run_state(*args, **kwargs):
          if args[2] == "sweep-scheduler":
              return "running"
          return "finished"
  
      api.get_run_state = mock_get_run_state
  
      _project = "test-project"
      _job = "test-job:latest"
      sweep_id = wandb.sweep(
          sweep_config, entity=user, project=_project
      )
      scheduler = SweepScheduler(
          api,
          sweep_id=sweep_id,
          entity=user,
          project=_project,
          num_workers=num_workers,
          polling_sleep=0,
          job=_job,
      )
      scheduler.start()
      assert scheduler.state == SchedulerState.STOPPED
  
imports: import asyncio
  from typing import Dict
  from unittest.mock import Mock, patch
  import pytest
  import wandb
  from wandb.apis import internal, public
  from wandb.errors import CommError
  from wandb.sdk.launch.sweeps import SchedulerError, load_scheduler
  from wandb.sdk.launch.sweeps.scheduler import RunState, Scheduler, SchedulerState, SweepRun
  from wandb.sdk.launch.sweeps.scheduler_sweep import SweepScheduler
  from wandb.sdk.launch.sweeps.utils import construct_scheduler_args
  from .test_wandb_sweep import VALID_SWEEP_CONFIGS_MINIMAL
label_desc: Use image node_id 11 for calling a global function with example usage: test_sweep_scheduler_sweeps_stop_agent_hearbeat(user, sweep_config, num_workers, monkeypatch) and returns: list, str, str