# Sort CompanyOS Routines by next run, schedule or enabled state

> Agno's `GET /company/routines` accepts `next_run_at`, `schedule_type` and `enabled` as `sort_by` values. Agno OS uses them to sort its routines table by Next run at, Schedule and Active.

- Published: 2026-10-29
- Author: Ayush Jha
- Categories: Changelog
- Canonical: https://www.agno.com/blog/sort-companyos-routines-by-next-run-schedule-or-enabled-state
- Markdown: https://www.agno.com/blog/sort-companyos-routines-by-next-run-schedule-or-enabled-state.md

A long Routine list ordered by creation date hides which one fires next. In [CompanyOS](https://www.agno.com/blog/introducing-companyos), Agno's list endpoint now orders Routines by their upcoming run, so the soonest one comes first.

```text
GET /company/routines?sort_by=next_run_at&sort_order=asc
```

We created five Routines through AgentOS with FastAPI's `TestClient` on SQLite, with no model, paused one, and sent this request on both releases. Real output:

```text
Before: 422 Input should be 'created_at' or 'updated_at'
Now:    200 ['minutely', 'daily', 'yearly', 'paused-soon', 'on-demand']
```

`paused-soon` still stores a timestamp earlier than the one on `daily`, and AgentOS ignores it because a paused Routine has no upcoming run. Under this sort, paused and on-demand Routines stay at the bottom in either direction.

The other two sorts treat them like any other value, so ascending order puts `on_demand` ahead of `scheduled` and `false` ahead of `true`. Ties follow creation time in the same direction as the sort. Sorting happens before paging, and `limit=2` returned `minutely` and `daily`.

Learn more about [CompanyOS Routines](https://docs.agno.com/agent-platform/company-os) in the documentation.
