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.
2
3This example demonstrates:
4- Multiple agents with different roles
5- Each agent gets a schedule with different cron, timezone, payload
6- Retry configuration for reliability
7- Rich table showing all schedules
8- Filtered views (enabled only, disabled only)
9"""
10
11from kern.db.sqlite import SqliteDb
12from kern.scheduler import ScheduleManager
13from kern.scheduler.cli import SchedulerConsole
14
15# --- Setup ---
16
17db = SqliteDb(id="multi-agent-demo", db_file="tmp/multi_agent_demo.db")
18mgr = ScheduleManager(db)
19console = SchedulerConsole(mgr)
20
21# =============================================================================
22# Create schedules with different configurations
23# =============================================================================
24
25print("Creating schedules for 3 agents...\n")
26
27# Research agent: daily at 7 AM EST with custom payload
28s_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)
39
40# Writer agent: weekdays at 10 AM UTC
41s_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)
50
51# Monitor agent: every 15 minutes with retry configuration
52s_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)
64
65print("All schedules created.")
66
67# =============================================================================
68# Display all schedules
69# =============================================================================
70
71print("\n--- All Schedules ---")
72console.show_schedules()
73
74# =============================================================================
75# Show individual schedule details
76# =============================================================================
77
78print("\n--- Monitor Schedule Details ---")
79console.show_schedule(s_monitor.id)
80
81# =============================================================================
82# Disable one schedule and show filtered views
83# =============================================================================
84
85mgr.disable(s_writer.id)
86print("\nDisabled 'weekday-report' schedule.")
87
88print("\n--- Enabled Schedules Only ---")
89enabled = console.show_schedules(enabled=True)
90print(f"({len(enabled)} enabled)")
91
92print("\n--- Disabled Schedules Only ---")
93disabled = console.show_schedules(enabled=False)
94print(f"({len(disabled)} disabled)")
95
96# =============================================================================
97# Re-enable and verify
98# =============================================================================
99
100mgr.enable(s_writer.id)
101print("\nRe-enabled 'weekday-report' schedule.")
102
103all_schedules = mgr.list()
104print(f"Total schedules: {len(all_schedules)}")
105
106# =============================================================================
107# Cleanup
108# =============================================================================
109
110# 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 repo
2git clone https://github.com/kern-ai/kern.git
3cd kern/cookbook/05_agent_os/scheduler
4
5# Create and activate virtual environment
6./scripts/demo_setup.sh
7source .venvs/demo/bin/activate
8
9python multi_agent_schedules.py