basic_schedule.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Export your OpenAI API key
4
Run PgVector
5
Run the example
Save the code above as
basic_schedule.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Runs an AgentOS on port 7777 with cron scheduling and Postgres, then creates a 5-minute greeter schedule via POST /schedules.
"""Basic scheduled agent run.
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.
Prerequisites:
pip install agno[scheduler]
# Start postgres: ./cookbook/scripts/run_pgvector.sh
Usage:
python cookbook/05_agent_os/scheduler/basic_schedule.py
Then, in another terminal, create a schedule:
curl -X POST http://localhost:7777/schedules \
-H "Content-Type: application/json" \
-d '{
"name": "greeting-every-5m",
"cron_expr": "*/5 * * * *",
"endpoint": "/agents/greeter/runs",
"payload": {"message": "Say hello!"}
}'
"""
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.openai import OpenAIChat
from agno.os import AgentOS
# ---------------------------------------------------------------------------
# Create Example
# ---------------------------------------------------------------------------
db = PostgresDb(
id="scheduler-demo-db",
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
)
greeter = Agent(
id="greeter",
name="Greeter Agent",
model=OpenAIChat(id="gpt-4o-mini"),
instructions=[
"You are a friendly greeter. Say hello and include the current time."
],
db=db,
markdown=True,
)
app = AgentOS(
agents=[greeter],
db=db,
scheduler=True,
scheduler_poll_interval=15,
).get_app()
# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7777)
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U "agno[os]" "psycopg[binary]" openai
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
Run PgVector
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql \
-v pgvolume:/var/lib/postgresql \
-p 5532:5432 \
--name pgvector \
agnohq/pgvector:18
docker run -d `
-e POSTGRES_DB=ai `
-e POSTGRES_USER=ai `
-e POSTGRES_PASSWORD=ai `
-e PGDATA=/var/lib/postgresql `
-v pgvolume:/var/lib/postgresql `
-p 5532:5432 `
--name pgvector `
agnohq/pgvector:18
Run the example
basic_schedule.py, then run:python basic_schedule.py
Was this page helpful?