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).23This 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 workflows7- Using the ScheduleManager directly for setup8"""910from kern.db.sqlite import SqliteDb11from kern.scheduler import ScheduleManager12from kern.scheduler.cli import SchedulerConsole1314# --- Setup ---1516db = SqliteDb(id="team-wf-demo", db_file="tmp/team_wf_demo.db")17mgr = ScheduleManager(db)18console = SchedulerConsole(mgr)1920# =============================================================================21# 1. Schedule a team run22# =============================================================================2324print("=== Team Schedules ===\n")2526team_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)4142# =============================================================================43# 2. Schedule a workflow run44# =============================================================================4546print("\n=== Workflow Schedules ===\n")4748wf_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)6061# =============================================================================62# 3. Mix of agent, team, and workflow schedules63# =============================================================================6465print("\n=== Mixed Schedules ===\n")6667agent_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)7475# Show all schedules together76console.show_schedules()7778# =============================================================================79# 4. Different HTTP methods for non-run endpoints80# =============================================================================8182print("\n=== Non-run endpoint schedules ===\n")8384# 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)9596# =============================================================================97# Cleanup98# =============================================================================99100print("\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 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 team_workflow_schedules.py