Learn R Programming

aisdk (version 1.1.0)

MissionOrchestrator: MissionOrchestrator Class

Description

R6 class that manages a queue of Missions and executes them within a concurrency limit. Provides full observability via status summaries and stall detection through reconcile().

Arguments

Public fields

pending_queue

List of Mission objects waiting to run.

running

List of Mission objects currently executing.

completed

List of Mission objects that have finished.

max_concurrent

Maximum simultaneous missions. Default 3.

global_session

Optional SharedSession shared across all missions.

global_model

Default model ID for missions that don't specify one.

async_handles

list of callr::r_bg handles (for run_async).

Methods


Method new()

Initialize a new MissionOrchestrator.

Usage

MissionOrchestrator$new(max_concurrent = 3, model = NULL, session = NULL)

Arguments

max_concurrent

Maximum simultaneous missions. Default 3.

model

Optional default model for all missions.

session

Optional shared SharedSession.


Method submit()

Submit a Mission to the orchestrator queue.

Usage

MissionOrchestrator$submit(mission)

Arguments

mission

A Mission object.

Returns

Invisible self for chaining.


Method run_all()

Run all submitted missions respecting the concurrency limit.

Usage

MissionOrchestrator$run_all(model = NULL)

Arguments

model

Optional model override for all missions in this run.

Details

Missions are executed in batches of max_concurrent. Within each batch, missions run in parallel (via parallel::mclapply on Unix, sequentially on Windows). Completed missions are moved to $completed.

Returns

Invisibly returns the list of completed Mission objects.


Method run_async()

Run a single Mission asynchronously in a background process.

Usage

MissionOrchestrator$run_async(mission, model = NULL)

Arguments

mission

A Mission object.

model

Optional model override.

Details

Uses callr::r_bg to launch the mission in a separate R process. The mission state is serialized to a temp file, executed, and the result is written back. Call $poll_async() to check completion.

Returns

A list with $handle (callr process), $mission_id, $checkpoint_path.


Method poll_async()

Poll all async handles and collect completed missions.

Usage

MissionOrchestrator$poll_async()

Returns

Named list with completed (list of Mission objects) and still_running (integer count).


Method reconcile()

Stall detection: check for missions that appear stuck.

Usage

MissionOrchestrator$reconcile(stall_threshold_secs = 600)

Arguments

stall_threshold_secs

Missions running longer than this are flagged. Default 600 (10 minutes).

Returns

list of stalled mission IDs.


Method status()

Get a status summary of all missions.

Usage

MissionOrchestrator$status()

Returns

A data.frame with id, goal, status, n_steps columns.


Method print()

Print method.

Usage

MissionOrchestrator$print()


Method clone()

The objects of this class are cloneable with this method.

Usage

MissionOrchestrator$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.