> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# LaunchAgent

<Card title="ソースコードを表示" href="https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L164-L924" icon="code" />

指定された run キューをポーリングし、wandb launch の run を起動する Launch エージェントのクラスです。

```python theme={"system"}
LaunchAgent(
    api: Api,
    config: Dict[str, Any]
)
```

| 引数 | 説明 |
| :- | :- |
| `api` | バックエンドへのリクエストに使用する API オブジェクトです。 |
| `config` | エージェントの設定の辞書です。 |

| 属性 | 説明 |
| :- | :- |
| `num_running_jobs` | スケジューラーを除くジョブの数を返します。 |
| `num_running_schedulers` | スケジューラーの数のみを返します。 |
| `thread_ids` | エージェントで実行中のスレッド ID をキーとするリストを返します。 |

<h2 id="methods">
  メソッド
</h2>

<h3 id="check_sweep_state">
  `check_sweep_state`
</h3>

[View source](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L786-L803)

```python theme={"system"}
check_sweep_state(
    launch_spec, api
)
```

sweep の run を起動する前に、sweep の状態を確認します。

<h3 id="fail_run_queue_item">
  `fail_run_queue_item`
</h3>

[View source](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L295-L304)

```python theme={"system"}
fail_run_queue_item(
    run_queue_item_id, message, phase, files=None
)
```

<h3 id="finish_thread_id">
  `finish_thread_id`
</h3>

[View source](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L416-L509)

```python theme={"system"}
finish_thread_id(
    thread_id, exception=None
)
```

ジョブをリストから一時的に削除します。

<h3 id="get_job_and_queue">
  `get_job_and_queue`
</h3>

[View source](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L908-L915)

```python theme={"system"}
get_job_and_queue()
```

<h3 id="initialized">
  `initialized`
</h3>

[View source](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L190-L193)

```python theme={"system"}
@classmethod
initialized() -> bool
```

エージェントが初期化されているかどうかを返します。

<h3 id="loop">
  `loop`
</h3>

[View source](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L572-L653)

```python theme={"system"}
loop()
```

無限ループでジョブをポーリングし、実行します。

| 送出される例外 | 説明 |
| :- | :- |
| `KeyboardInterrupt` | エージェントの停止が要求された場合。 |

<h3 id="name">
  `name`
</h3>

[View source](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L180-L188)

```python theme={"system"}
@classmethod
name() -> str
```

エージェント名を返します。

<h3 id="pop_from_queue">
  `pop_from_queue`
</h3>

[View source](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L340-L363)

```python theme={"system"}
pop_from_queue(
    queue
)
```

run キューから項目を取り出し、ジョブとして実行します。

| 引数 | 説明 |
| :- | :- |
| `queue` | 項目を取り出すキューです。 |

| 戻り値 | 説明 |
| :- | :- |
| キューから取り出された項目です。 | |

| 送出される例外 | 説明 |
| :- | :- |
| `Exception` | キューからの取り出し時にエラーが発生した場合。 |

<h3 id="print_status">
  `print_status`
</h3>

[View source](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L365-L381)

```python theme={"system"}
print_status() -> None
```

エージェントの現在のステータスを出力します。

<h3 id="run_job">
  `run_job`
</h3>

[View source](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L511-L541)

```python theme={"system"}
run_job(
    job, queue, file_saver
)
```

project を設定し、ジョブを実行します。

| 引数 | 説明 |
| :- | :- |
| `job` | 実行するジョブ。 |

<h3 id="task_run_job">
  `task_run_job`
</h3>

[View source](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L656-L688)

```python theme={"system"}
task_run_job(
    launch_spec, job, default_config, api, job_tracker
)
```

<h3 id="update_status">
  `update_status`
</h3>

[View source](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L383-L394)

```python theme={"system"}
update_status(
    status
)
```

エージェントのステータスを更新します。

| 引数 | 説明 |
| :- | :- |
| `status` | エージェントを更新するステータス。 |
