Background Agents: Durable Agent Tasks
Background Agents run OmniCoreAgent work outside the foreground request path. They are durable tracked tasks with schedules, retries, cancellation, leases, workspace output, and inspectable lifecycle events. Use the default in-memory store for local development, orsql, redis, or mongodb when runs must
survive restarts.
Key Concepts
- BackgroundAgentManager: Registers agents, tasks, runs, and lifecycle operations.
- Task store: Operational state for agents, tasks, schedule state, runs, attempts, leases, retries, and cancellation flags. It defaults to in-memory and is separate from conversation memory.
- Run: One concrete execution of a task. Runs have stable IDs, statuses, attempts, workspace paths, and event history.
- Worker lifecycle: A worker claims queued runs with leases, heartbeats while work is active, and recovers expired leases.
- Workspace output: Every background run gets a workspace namespace for lifecycle files and agent output.
BackgroundAgentManager() for the default zero-config in-memory task store. Use
task_store="sql", task_store="redis", or task_store="mongodb" when task
state must survive process restarts. The task store is not conversation memory;
it is the control plane for background work.
Redis and MongoDB task stores use optional backend drivers:
Quick Start
Durable Task Stores
The default task store is in-memory. It needs no database and is right for local development, tests, and single-process experiments:Scheduled Runs
Manual tasks run only when you callrun_now. Scheduled tasks are dispatched by
the manager worker after start() is called:
start() creates the manager worker and returns immediately. Keep the process
alive while scheduled work should continue, and use shutdown() when the
process exits so worker loops and active background resources close cleanly:
once task, starts the background worker, waits for the run to
complete, then prints task status, manager status, lifecycle events, and the
workspace files created for the run. By default it writes the demo workspace
under your system temp directory. Set OMNICOREAGENT_COOKBOOK_WORKSPACE_DIR to
choose a different location:
Real Application Background Task
The real application example runs the support operations app shape through the background manager. It uses the same support domain tools ascookbook/real_applications/support_operations_agent.py, registers a manual
task, waits for the run to finish, then prints the run id, status, attempts,
lifecycle events, and workspace files.
It is deterministic and does not require LLM_API_KEY, so it is safe to run in
CI or locally when you only want to inspect the background execution boundary:
omnicoreagent_real_app_background_workspace. The script prints both
workspace_root and the run-local workspace path. Pass workspace_dir when
calling run_real_application_background_example(...) from Python if you want a
specific local root.
The run workspace contains:
output.mdwith the durable support notetickets/tck-1042.mdwith the ticket-specific recordrun.jsonwith the latest run snapshotevents.jsonlwith ordered lifecycle events
Runtime Controls
get_run_events(run_id) returns ordered lifecycle events for that run. These
events use run-local names such as background_task_scheduled,
background_run_queued, background_run_claimed, background_run_started,
background_run_heartbeat, background_run_retrying,
background_run_recovered, background_run_completed,
background_run_failed, background_run_timeout,
background_run_cancelled, and background_run_skipped.
When workspace event mirroring is enabled, lifecycle events are also written to
the run workspace events.jsonl file for durable replay and debugging.
OmniServe Endpoints
OmniServe exposes the same background run lifecycle over HTTP:Task Configuration
| Field | Purpose |
|---|---|
task_id | Stable task identifier. |
agent_id | Registered agent that executes the task. |
query | Instruction passed to the agent for each run. |
schedule | manual, interval, cron, or once. |
timeout_seconds | Optional per-run timeout. |
retry_policy | Retry count, delay, backoff, and retryable error types. |
overlap_policy | skip_if_running, queue_next, cancel_previous, or allow_parallel. |
session_policy | task, run, or fixed memory-session behavior. |