Skip to main content

Background Module

The background module provides the ability to run agents in the background, allowing long-running tasks without blocking the main thread.

Installation

Features

  • Long-running tasks without blocking
  • Task queuing and management
  • Progress monitoring and notifications
  • Graceful cancellation

Quick Start

Classes

BackgroundRunner

Main class for managing background tasks.

Constructor

Methods

BackgroundTask

Represents a background task.

Attributes

Methods

TaskStatus

Enumeration of task statuses.

BackgroundConfig

Configuration for background runner.

Usage Examples

Basic Background Task

With Callback

Multiple Tasks

Task Cancellation

Progress Monitoring

Best Practices

  1. Set appropriate timeouts - Prevent tasks from running indefinitely
  2. Handle failures - Always provide error callbacks
  3. Limit concurrency - Don’t overwhelm resources with too many workers
  4. Clean up - Call shutdown() when done with the runner
  5. Monitor progress - Track long-running tasks
  • Agent - Agent configuration
  • Task - Task definition