Scheduling teams and workflows (not just agents).

This example demonstrates.

This example demonstrates: - Creating schedules that target team endpoints (/teams//runs) - Creating schedules that target workflow endpoints (/workflows//runs) - Different payload configurations for teams vs workflows - Using the ScheduleManager directly for setup

1"""Scheduling teams and workflows (not just agents).
2
3This example demonstrates:
4- Creating schedules that target team endpoints (/teams/*/runs)
5- Creating schedules that target workflow endpoints (/workflows/*/runs)
6- Different payload configurations for teams vs workflows
7- Using the ScheduleManager directly for setup
8"""
9
10from kern.db.sqlite import SqliteDb
11from kern.scheduler import ScheduleManager
12from kern.scheduler.cli import SchedulerConsole
13
14# --- Setup ---
15
16db = SqliteDb(id="team-wf-demo", db_file="tmp/team_wf_demo.db")
17mgr = ScheduleManager(db)
18console = SchedulerConsole(mgr)
19
20# =============================================================================
21# 1. Schedule a team run
22# =============================================================================
23
24print("=== Team Schedules ===\n")
25
26team_schedule = mgr.create(
27 name="daily-research-team",
28 cron="0 9 * * 1-5",
29 endpoint="/teams/research-team/runs",
30 description="Run the research team every weekday at 9 AM",
31 payload={
32 "message": "Research the latest developments in AI safety",
33 "stream": False,
34 },
35 timeout_seconds=1800,
36 max_retries=2,
37 retry_delay_seconds=60,
38)
39print(f"Created team schedule: {team_schedule.name}")
40console.show_schedule(team_schedule.id)
41
42# =============================================================================
43# 2. Schedule a workflow run
44# =============================================================================
45
46print("\n=== Workflow Schedules ===\n")
47
48wf_schedule = mgr.create(
49 name="nightly-data-pipeline",
50 cron="0 2 * * *",
51 endpoint="/workflows/data-pipeline/runs",
52 description="Run the data pipeline workflow every night at 2 AM",
53 payload={
54 "message": "Process and aggregate daily data",
55 },
56 timeout_seconds=3600,
57)
58print(f"Created workflow schedule: {wf_schedule.name}")
59console.show_schedule(wf_schedule.id)
60
61# =============================================================================
62# 3. Mix of agent, team, and workflow schedules
63# =============================================================================
64
65print("\n=== Mixed Schedules ===\n")
66
67agent_sched = mgr.create(
68 name="hourly-monitor",
69 cron="0 * * * *",
70 endpoint="/agents/monitor-agent/runs",
71 description="Run monitor agent every hour",
72 payload={"message": "Check system health"},
73)
74
75# Show all schedules together
76console.show_schedules()
77
78# =============================================================================
79# 4. Different HTTP methods for non-run endpoints
80# =============================================================================
81
82print("\n=== Non-run endpoint schedules ===\n")
83
84# Schedule a GET request (e.g., health check)
85health_sched = mgr.create(
86 name="health-ping",
87 cron="*/10 * * * *",
88 endpoint="/health",
89 method="GET",
90 description="Ping health endpoint every 10 minutes",
91)
92print(
93 f"Created GET schedule: {health_sched.name} -> {health_sched.method} {health_sched.endpoint}"
94)
95
96# =============================================================================
97# Cleanup
98# =============================================================================
99
100print("\n=== Cleanup ===\n")
101for s in mgr.list():
102 mgr.delete(s.id)
103print("All 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 team_workflow_schedules.py