code: def agent(
      sweep_id, function=None, entity=None, project=None, count=None
  ):
      """Run a function or program with configuration parameters specified by server.
  
      Generic agent entrypoint, used for CLI or jupyter.
  
      Arguments:
          sweep_id: (dict) Sweep ID generated by CLI or sweep API
          function: (func, optional) A function to call instead of the "program"
              specifed in the config.
          entity: (str, optional) W&B Entity
          project: (str, optional) W&B Project
          count: (int, optional) the number of trials to run.
  
      Examples:
          Run a sample sweep over a function:
          <!--yeadoc-test:one-parameter-sweep-agent-->
          ```python
          import wandb
  
          sweep_configuration = {
              "name": "my-awesome-sweep",
              "metric": {"name": "accuracy", "goal": "maximize"},
              "method": "grid",
              "parameters": {"a": {"values": [1, 2, 3, 4]}},
          }
  
  
          def my_train_func():
              # read the current value of parameter "a" from wandb.config
              wandb.init()
              a = wandb.config.a
  
              wandb.log({"a": a, "accuracy": a + 1})
  
  
          sweep_id = wandb.sweep(sweep_configuration)
  
          # run the sweep
          wandb.agent(sweep_id, function=my_train_func)
          ```
      """
      global _INSTANCES
      _INSTANCES += 1
      try:
          # make sure we are logged in
          wandb_sdk.wandb_login._login(_silent=True)
          if function:
              return pyagent(sweep_id, function, entity, project, count)
          in_jupyter = (
              wandb.wandb_sdk.lib.ipython._get_python_type() != "python"
          )
          return run_agent(
              sweep_id,
              function=function,
              in_jupyter=in_jupyter,
              entity=entity,
              project=project,
              count=count,
          )
      finally:
          _INSTANCES -= 1
  
imports: import logging
  import multiprocessing
  import os
  import platform
  import queue
  import re
  import signal
  import socket
  import subprocess
  import sys
  import time
  import traceback
  from typing import Any, Dict, List
  import yaml
  import wandb
  from wandb import util, wandb_lib, wandb_sdk
  from wandb.agents.pyagent import pyagent
  from wandb.apis import InternalApi
  from wandb.sdk.launch.sweeps import utils
label_desc: Use image node_id 2 for calling a global function with example usage: agent(sweep_id, function, entity, project, count) and returns: run_agent, pyagent