Part 1: Cursor-Based Message Retrieval
Implement a function that retrieves all messages from a paginated client API.
- Request messages from the client using a pagination cursor.
- Iterate through each page until no additional cursor is returned.
- Aggregate all messages into a single list.
Concepts tested: API pagination, iteration, and data aggregation.
Part 2: Token-Budgeted Context Management
Extend message retrieval to manage a fixed token budget using a FIFO cache.
- Track the token count of incoming messages.
- Maintain a running total of tokens in the cache.
- Evict the oldest messages when the token budget is exceeded.
- Return the remaining messages within the context limit.
Concepts tested: FIFO queues, sliding windows, token budgeting, and memory management.
Part 3: Unique Property-Based Message Retrieval
Extend the previous functionality to account for uniqueness based on a specific message property.
- Track previously encountered property values.
- Handle duplicate messages according to the uniqueness constraint.
- Maintain the appropriate message collection.
Concepts tested: Hash sets, deduplication, and state management.
Discussion
Loading comments…