Basic scheduled agent run.
Starts an AgentOS with the scheduler enabled.
Starts an AgentOS with the scheduler enabled. After the server is running, use the REST API to create a schedule that triggers an agent every 5 minutes.
1"""Basic scheduled agent run.23Starts an AgentOS with the scheduler enabled. After the server is running,4use the REST API to create a schedule that triggers an agent every 5 minutes.56Prerequisites:7 pip install kern-ai[scheduler]8 # Start postgres: ./cookbook/scripts/run_pgvector.sh910Usage:11 python cookbook/05_agent_os/scheduler/basic_schedule.py1213Then, in another terminal, create a schedule:14 curl -X POST http://localhost:7777/schedules \15 -H "Content-Type: application/json" \16 -d '{17 "name": "greeting-every-5m",18 "cron_expr": "*/5 * * * *",19 "endpoint": "/agents/greeter/runs",20 "payload": {"message": "Say hello!"}21 }'22"""2324from kern.agent import Agent25from kern.db.postgres import PostgresDb26from kern.models.openai import OpenAIChat27from kern.os import AgentOS2829# ---------------------------------------------------------------------------30# Create Example31# ---------------------------------------------------------------------------3233db = PostgresDb(34 id="scheduler-demo-db",35 db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",36)3738greeter = Agent(39 id="greeter",40 name="Greeter Agent",41 model=OpenAIChat(id="gpt-4o-mini"),42 instructions=[43 "You are a friendly greeter. Say hello and include the current time."44 ],45 db=db,46 markdown=True,47)4849app = AgentOS(50 agents=[greeter],51 db=db,52 scheduler=True,53 scheduler_poll_interval=15,54).get_app()5556# ---------------------------------------------------------------------------57# Run Example58# ---------------------------------------------------------------------------5960if __name__ == "__main__":61 import uvicorn6263 uvicorn.run(app, host="0.0.0.0", port=7777)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/activate89# Optiona: Run PgVector (needs docker)10./cookbook/scripts/run_pgvector.sh1112python basic_schedule.py