Multi-agent scheduling with different cron patterns and payloads.
This example demonstrates.
This example demonstrates: - Multiple agents with different roles - Each agent gets a schedule with different cron, timezone, payload - Retry configuration for reliability - Rich table showing all schedules - Filtered views (enabled only, disabled only)
1"""Multi-agent scheduling with different cron patterns and payloads.23This example demonstrates:4- Multiple agents with different roles5- Each agent gets a schedule with different cron, timezone, payload6- Retry configuration for reliability7- Rich table showing all schedules8- Filtered views (enabled only, disabled only)9"""1011from kern.db.sqlite import SqliteDb12from kern.scheduler import ScheduleManager13from kern.scheduler.cli import SchedulerConsole1415# --- Setup ---1617db = SqliteDb(id="multi-agent-demo", db_file="tmp/multi_agent_demo.db")18mgr = ScheduleManager(db)19console = SchedulerConsole(mgr)2021# =============================================================================22# Create schedules with different configurations23# =============================================================================2425print("Creating schedules for 3 agents...\n")2627# Research agent: daily at 7 AM EST with custom payload28s_research = mgr.create(29 name="daily-research",30 cron="0 7 * * *",31 endpoint="/agents/research-agent/runs",32 description="Gather daily research insights",33 timezone="America/New_York",34 payload={35 "message": "Research the latest AI developments",36 "stream": False,37 },38)3940# Writer agent: weekdays at 10 AM UTC41s_writer = mgr.create(42 name="weekday-report",43 cron="0 10 * * 1-5",44 endpoint="/agents/writer-agent/runs",45 description="Generate weekday summary report",46 payload={47 "message": "Write a summary of yesterday's research",48 },49)5051# Monitor agent: every 15 minutes with retry configuration52s_monitor = mgr.create(53 name="health-monitor",54 cron="*/15 * * * *",55 endpoint="/agents/monitor-agent/runs",56 description="System health check every 15 minutes",57 payload={58 "message": "Check system health and report anomalies",59 },60 max_retries=3,61 retry_delay_seconds=30,62 timeout_seconds=120,63)6465print("All schedules created.")6667# =============================================================================68# Display all schedules69# =============================================================================7071print("\n--- All Schedules ---")72console.show_schedules()7374# =============================================================================75# Show individual schedule details76# =============================================================================7778print("\n--- Monitor Schedule Details ---")79console.show_schedule(s_monitor.id)8081# =============================================================================82# Disable one schedule and show filtered views83# =============================================================================8485mgr.disable(s_writer.id)86print("\nDisabled 'weekday-report' schedule.")8788print("\n--- Enabled Schedules Only ---")89enabled = console.show_schedules(enabled=True)90print(f"({len(enabled)} enabled)")9192print("\n--- Disabled Schedules Only ---")93disabled = console.show_schedules(enabled=False)94print(f"({len(disabled)} disabled)")9596# =============================================================================97# Re-enable and verify98# =============================================================================99100mgr.enable(s_writer.id)101print("\nRe-enabled 'weekday-report' schedule.")102103all_schedules = mgr.list()104print(f"Total schedules: {len(all_schedules)}")105106# =============================================================================107# Cleanup108# =============================================================================109110# Uncomment to clean up schedules from the DB:111# for s in [s_research, s_writer, s_monitor]:112# mgr.delete(s.id)113# print("\nAll schedules cleaned up.")Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/05_agent_os/scheduler45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python multi_agent_schedules.py