Skip to main content
The Scheduler CLI enables 24/7 autonomous agent operations by running agents at regular intervals.

Quick Start

# Schedule an agent using agents.yaml
praisonai schedule agents.yaml

Installation

pip install praisonai praisonaiagents
export OPENAI_API_KEY=your_key_here

Basic Usage

Schedule with agents.yaml

The scheduler uses your existing agents.yaml file with an optional schedule section:
framework: praisonai

agents:
  - name: "AI News Monitor"
    role: "Technology News Analyst"
    goal: "Monitor and summarize AI news"
    instructions: "Search for latest AI developments"
    tools:
      - search_tool
    verbose: true

task: "Search for latest AI news and provide top 3 stories"

schedule:
  interval: "hourly"
  max_retries: 3
  run_immediately: true

Run the Scheduler

# Use agents.yaml in current directory
praisonai schedule

# Or specify path
praisonai schedule path/to/agents.yaml

# Override interval from CLI
praisonai schedule --interval "*/30m"

# Override max retries
praisonai schedule --max-retries 5

Command Options

OptionTypeDescriptionExample
yaml_filepathPath to agents.yamlagents.yaml (default)
--intervalstringOverride schedule intervalhourly, */30m
--max-retriesintOverride max retry attempts3
--verbose, -vflagEnable verbose logging-

Schedule Intervals

FormatIntervalDescription
hourly3600sEvery hour
daily86400sEvery 24 hours
*/30m1800sEvery 30 minutes
*/6h21600sEvery 6 hours
*/5s5sEvery 5 seconds (testing)
36003600sCustom seconds

Examples

Example 1: News Monitoring (Hourly)

agents.yaml:
framework: praisonai

agents:
  - name: "AI News Monitor"
    role: "Technology News Analyst"
    instructions: "Search and summarize latest AI news"
    tools:
      - search_tool

task: "Search for latest AI news and provide top 3 stories"

schedule:
  interval: "hourly"
  max_retries: 3
  run_immediately: true
Run:
praisonai schedule agents.yaml

Example 2: Data Collection (Every 30 Minutes)

agents.yaml:
framework: praisonai

agents:
  - name: "Data Collector"
    role: "Data Analyst"
    instructions: "Collect and analyze market data"
    tools:
      - search_tool

task: "Collect latest market data and identify trends"

schedule:
  interval: "*/30m"
  max_retries: 5
  run_immediately: false
Run with override:
# Override to run every 15 minutes instead
praisonai schedule agents.yaml --interval "*/15m"

Example 3: Testing with Short Interval

# Test with 10-second interval
praisonai schedule agents.yaml --interval "*/10s" --verbose

Python API

For programmatic control, use the Python API:

Option 1: Load from agents.yaml

from praisonai.scheduler import AgentScheduler

# Load from YAML
scheduler = AgentScheduler.from_yaml("agents.yaml")

# Start with YAML config
scheduler.start_from_yaml_config()

# Or override settings
scheduler = AgentScheduler.from_yaml(
    "agents.yaml",
    interval_override="*/15m",
    max_retries_override=5
)
scheduler.start_from_yaml_config()

# Keep running
try:
    while scheduler.is_running:
        import time
        time.sleep(1)
except KeyboardInterrupt:
    scheduler.stop()
    print(scheduler.get_stats())

Option 2: Create Programmatically

from praisonaiagents import Agent
from praisonai.scheduler import AgentScheduler

# Create agent
agent = Agent(
    name="NewsChecker",
    instructions="Check latest AI news",
    tools=[search_tool]
)

# Create scheduler
scheduler = AgentScheduler(
    agent=agent,
    task="Search for latest AI news"
)

# Start (runs every hour)
scheduler.start("hourly", max_retries=3, run_immediately=True)

# Keep running
try:
    while scheduler.is_running:
        import time
        time.sleep(1)
except KeyboardInterrupt:
    scheduler.stop()
    print(scheduler.get_stats())

Features

  • Multiple Schedule Formats - hourly, daily, custom intervals
  • Automatic Retry - Exponential backoff on failures
  • Statistics Tracking - Monitor success rates
  • Graceful Shutdown - Clean stop with Ctrl+C
  • Callbacks - Success/failure notifications
  • Thread-Safe - Daemon threads for background execution

Output

🤖 Starting 24/7 AI News Checker Agent
============================================================
Agent: AI News Monitor
Task: Search for latest AI news
Schedule: Every 1 hour
============================================================

 Starting scheduler... (Press Ctrl+C to stop)

[2025-12-20 19:00:00] Starting scheduled agent execution
[2025-12-20 19:00:05] Agent execution successful
[2025-12-20 19:00:05] Next execution in 3600 seconds (1.0 hours)

# On stop (Ctrl+C)
🛑 Stopping scheduler...

📊 Final Statistics:
  Total Executions: 5
  Successful: 5
  Failed: 0
  Success Rate: 100.0%

 Agent stopped successfully

Error Handling

The scheduler automatically retries failed executions with exponential backoff:
  • Attempt 1: Execute immediately
  • Attempt 2: Wait 30s, retry
  • Attempt 3: Wait 60s, retry
  • Attempt 4: Wait 90s, retry
  • Attempt 5: Wait 120s, retry

Stopping the Scheduler

Press Ctrl+C to stop gracefully. The scheduler will:
  1. Set stop event
  2. Wait for current execution (max 10s)
  3. Log final statistics
  4. Exit cleanly

See Also