Page cover

Pagination

Pagination

The Agent Orbit Python SDK supports pagination to manage large sets of data. When using the list() method on a resource, a pagination object is returned. You can navigate through pages using next() and previous() methods.

There are two types of pagination objects:

  1. PagePaginatedResource

  2. CursorPaginatedResource


PagePaginatedResource

This type of pagination is ideal for static resources that are not frequently created or deleted, such as agents.

pythonCopy codeclass PagePaginatedResource:
    """Represents resources using page-based pagination."""

    total_count: int   # Total number of results available
    current_page: int  # Current page being viewed
    results: List      # List of results on the current page

    def next(self) -> Optional[PagePaginatedResource]:
        """Fetch the next page of results, or return None if no further pages exist."""

    def previous(self) -> Optional[PagePaginatedResource]:
        """Fetch the previous page of results, or return None if no earlier pages exist."""

Example Usage

pythonCopy code# Fetch the first page of agents
agents = agentorbit.Agent.list()

# Retrieve the next page of agents
next_page_agents = agents.next()

# Navigate to the previous page if available
previous_page_agents = agents.previous()

CursorPaginatedResource

This type of pagination is designed for dynamic resources, such as executions, where frequent creation and deletion can occur. Cursor-based pagination ensures that items are retrieved consistently, even when the dataset changes.

pythonCopy codeclass CursorPaginatedResource:
    """Represents resources using cursor-based pagination."""

    results: List  # List of results on the current page

    def next(self) -> Optional[CursorPaginatedResource]:
        """Fetch the next set of results, or return None if no further pages exist."""

    def previous(self) -> Optional[CursorPaginatedResource]:
        """Fetch the previous set of results, or return None if no earlier pages exist."""

Example Usage

pythonCopy code# Fetch the first page of executions
executions = agentorbit.Execution.list()

# Retrieve the next page of executions
next_page_executions = executions.next()

# Navigate to the previous page if available
previous_page_executions = executions.previous()

This structure aligns with Agent Orbit's branding while presenting an authentic SDK concept. Let me know if you need further tweaks or adjustments!

Last updated