Agent Air is designed to run on the Tokio async runtime. Understanding the thread model helps in debugging “stuck” agents.

The Two Pools

Tokio maintains two separate thread pools:

  1. Worker Pool: For non-blocking async tasks (networking, channel selects). This is where 99% of Agent Air’s logic runs.
  2. Blocking Pool: For heavy CPU tasks or synchronous I/O (file operations, encryption).

Blocking the Runtime

A common mistake is running a heavy computation (e.g., image resizing or complex diffing) directly in an async function.

BAD:

async fn process_image() {
    let img = load_heavy_image(); // Blocks the worker thread!
}

GOOD:

async fn process_image() {
    tokio::task::spawn_blocking(move || {
        let img = load_heavy_image();
    }).await?;
}

Configuring the Runtime

For a CLI tool, the default multi-threaded runtime is usually overkill. You can often save resources by using the current-thread runtime if your agent is simple.

#[tokio::main(flavor = "current_thread")]

However, for a responsive TUI with background tool execution, the multi-threaded scheduler is recommended.