Skip to main content

BackgroundAgentManager

The guide is Background agents.

Run statuses

A run is queued, then claimed by a worker, running, and retrying between attempts. It ends in a terminal status, or pauses in a waiting one until resume_run; run_now(wait=True) and wait_for_run return at either.

Overlap policies

What a task does when it is due while one of its runs is still active (overlap_policy; the default is skip_if_running):

Methods

cancel_run

Cancel a queued, running or waiting run.

delete_task

Delete a task; delete_runs deletes its runs too.

get_agent

The registered agent’s spec, or None.

get_manager_status

Agents, tasks, active runs and run counts by status, for this manager’s store.

get_run

The run: its status, attempts count, timings, result preview and error.

get_run_events

The run’s lifecycle events (queued, claimed, started, completed, …), in order.

get_run_workspace

Return the durable workspace location and visible files for a run.

get_task

The task, or None.

get_task_status

A task with its schedule state, active runs and a count of its runs by status.

initialize

Prepare the task store. start and the first use call it for you.

list_agents

Every registered agent’s spec.

list_attempts

Every attempt of a run, with how each ended.

list_runs

Runs, optionally one task’s, optionally in one status.

list_tasks

Every task, or one agent’s.

pause_task

Stop scheduling a task; runs already queued or running continue.

recover_expired_runs

Take back runs whose worker stopped renewing its lease (a process that died), so they retry or fail.

register_agent

Register an agent under agent_id so tasks can run it; replace swaps an existing one.

register_agent_spec

Register an agent from a spec (its model, tools and settings) that the store keeps, so a new process can rebuild it.

register_task

Create a task: which agent runs which query, on what schedule (manual, once, interval or cron), with its timeout, retries, overlap, session and workspace policies. replace overwrites an existing one.

resume_run

Queue a run that was waiting for approval, once the approvals are decided (agent.resolve_approval). Its next attempt continues the same durable run instead of starting over.

resume_task

Schedule a paused task again.

run_now

Queue one run of a task now, optionally with another query. With wait, return when it ends (or at timeout_seconds). Under the task’s overlap policy, a run can come back skipped (another run holds the task) instead of queued.

run_until_terminal

Execute a queued run in this process and return it when it ends, or at timeout_seconds.

shutdown

Stop the worker loop and cancel the runs it is executing; their attempts are recorded.

start

Start the worker loop: it runs due schedules and queued runs until shutdown.

unregister_agent

Remove an agent. Refused while it has active runs, unless force.

update_task

Change a task: patch holds the fields to change (query, schedule, enabled, timeout_seconds, retry_policy, overlap_policy, …).

wait_for_run

Wait for one specific run to become terminal without executing work.