> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Basic scheduled agent run

> Runs an AgentOS on port 7777 with cron scheduling and Postgres, then creates a 5-minute greeter schedule via POST /schedules.

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.

```python basic_schedule.py theme={null}
"""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)
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U "agno[os]" "psycopg[binary]" openai
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export OPENAI_API_KEY="your_openai_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Snippet file="run-pgvector-step.mdx" />

  <Step title="Run the example">
    Save the code above as `basic_schedule.py`, then run:

    ```bash theme={null}
    python basic_schedule.py
    ```
  </Step>
</Steps>

Full source: [cookbook/05\_agent\_os/scheduler/basic\_schedule.py](https://github.com/agno-agi/agno/blob/main/cookbook/05_agent_os/scheduler/basic_schedule.py)
