Skip to content
Changelog

Load long session histories one page of runs at a time

November 12, 20261 min read

Agno AgentOS now pages GET /sessions/{session_id}/runs when you pass limit, so a chat UI can open a long session by loading only its newest runs. Before, the UI had to pull every run before it could show the last message. The before_run_index and after_run_index cursors step back or forward from there.

GET /sessions/chat/runs?user_id=u1&limit=2
GET /sessions/chat/runs?user_id=u1&limit=2&before_run_index=4

On a session seeded with six runs, the first request returned the two newest and the second the two before them:

data: run-4, run-5  meta: {"limit": 2, "total_count": 6, "has_more": true, "oldest_run_index": 4, "newest_run_index": 5}
data: run-2, run-3  meta: {"limit": 2, "total_count": 6, "has_more": true, "oldest_run_index": 2, "newest_run_index": 3}

Every run carries a run_index, its 0-based position in the whole session, and it stays the same on the list, page, preview and single-run endpoints. Take the next cursor from meta, since a cursor taken from data[0] can skip a run stored between a member and its parent.

A team session keeps each turn whole. With limit=1, the newest page held the member run m2 and its team run t2, and total_count read 3 for three team turns.

This output comes from FastAPI's TestClient over the session router, with runs written to a local SQLite file.

See the cookbook, and learn more about sessions in the documentation.

Frequently asked questions

Call GET /sessions/{session_id}/runs?limit=N for the newest N runs. For the page before it, pass the response's meta.oldest_run_index as before_run_index; for the page after, pass meta.newest_run_index as after_run_index. Runs inside a page stay in chronological order. From Python, AgentOSClient.get_session_runs(..., limit=N) returns a RunsPage with data and meta.

No. Without limit the endpoint returns a bare list of every run, as before, and each run now also carries its run_index. A cursor without limit, or both cursors at once, answers 422. Earlier releases ignored these query parameters and returned the full list.

A page counts top-level runs only. Member and step runs ride along with their parent at any depth and do not use up the limit, so a team turn never splits across two pages. total_count and has_more count top-level runs too.

Shipped around the same time