# wandb.agent

[![](https://www.tensorflow.org/images/GitHub-Mark-32px.png)View source on GitHub](https://www.github.com/wandb/client/tree/v0.10.31.dev1/wandb/wandb_agent.py#L526-L572)

Generic agent entrypoint, used for CLI or jupyter.

```python
agent(
    sweep_id, function=None, entity=None, project=None, count=None
)
```

Will run a function or program with configuration parameters specified by server.

| 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:

```
def train():
    with wandb.init() as run:
        print("config:", dict(run.config))
        for epoch in range(35):
            print("running", epoch)
            wandb.log({"metric": run.config.param1, "epoch": epoch})
            time.sleep(1)

wandb.agent(sweep_id, function=train)
```
