def fetch_history(client, conversation_id):
The round: a 45-minute phone screen, reported four times from June to November 2026, for agent engineering and new-grad roles. One new-grad report says AI tools were not allowed. You are handed a small API with several classes and asked to work with a conversation's history. Three reports say the code is not hard and reading the API is the hard part: one candidate spent a long time just understanding the prompt, another advises working out how the classes relate in the first few minutes. In one report the screen opened with a project discussion that left about 30 minutes for code. The round has three parts; the first two are known and are the two graded parts here. No report gives the third part's task or rules (see the note at the end).
Given — what the tests call
Four classes, in the editor above your code. Read them first.
class Usage: # usage.token_count: int
class Message: # message_id, role, text, usage (a Usage)
class Page: # messages: list[Message], NEWEST first; next_cursor: str | None
class ConversationClient:
def __init__(self, conversations: dict, page_size: int = 50): ...
def list_messages(self, conversation_id: str, cursor: str | None = None) -> Page: ...
list_messages(conversation_id) with no cursor returns the first page: the newest messages. Pass page.next_cursor back to get the next, older page. The last page has next_cursor None.None again starts over from the newest page. Cursors are opaque strings.ConversationClient(conversations, page_size=2), where conversations maps an id to its messages, oldest first. Your code only calls list_messages.client.calls counts calls to list_messages. The tests check it.Part 1 — page through a conversation
def fetch_history(client, conversation_id: str) -> list[Message]: ...
list_messages with each page's next_cursor until there is no next page.Message, oldest first.Not reported: the third part. No report gives its task or rules. Two replies say it is close to Part 2 and uses the same idea. Nobody in these reports says they finished it: two ran out of time after Part 2, one was asked to explain the approach with 10 minutes left, and another explained it along with how to optimize the second and third parts together.
Notes: the class names, fields and method signature above are ours, written to match what the reports describe: pages linked by next_cursor, and a token_count on each message. So are newest-first pages, "None starts over", the oldest-first result, the strict "under 10,000" (exactly 10,000 drops one more) and the ValueError rules. The 20,000 and 10,000 thresholds and dropping the oldest messages first are reported. The given API in your round will differ, so read it before you code.
Reported four times from June to November 2026, for agent engineering and new-grad roles, as the 45-minute technical screen. One reply mentions a shared coding pad, and one report says AI tools were not allowed. Three candidates say the code is easy and the given API takes the time: one spent long on understanding the prompt, another advises mapping how the classes relate in the first few minutes. One interviewer gave rough directions and helped debug. One candidate compared Part 2 to a well-known sliding-window problem. The third part is a time risk: nobody in these reports says they finished it. Two candidates ran out of time after Part 2; one was asked only to explain its approach, and another explained it along with optimizing the second and third parts together. Results vary: two posters say they failed, one did not know yet and expected to fail, and one went on to ask about the onsite, which suggests they advanced.
What the reports say: three reports say the code is easy and the given API is the hard part. Spend the first minutes mapping how the classes relate, then code. Part 2 uses two thresholds: compact above 20,000 tokens, down to under 10,000, dropping the oldest messages first. Nobody reported finishing the third part in 45 minutes, so move fast through the first two.
Common mistakes (ours, not reported): Stopping on an empty page instead of on the next cursor; one extra call after the last page; returning messages in page order when the pages are newest first; compacting whenever the total is above 10,000; re-summing the tokens after every dropped message.
Edge cases to test (ours): An empty conversation; a history that fills its last page exactly; a total between 10,000 and 20,000; a total that lands exactly on 10,000 while dropping; one message bigger than the target.
The round: a 45-minute phone screen, reported four times from June to November 2026, for agent engineering and new-grad roles. One new-grad report says AI tools were not allowed. You are handed a small API with several classes and asked to work with a conversation's history. Three reports say the code is not hard and reading the API is the hard part: one candidate spent a long time just understanding the prompt, another advises working out how the classes relate in the first few minutes. In one report the screen opened with a project discussion that left about 30 minutes for code. The round has three parts; the first two are known and are the two graded parts here. No report gives the third part's task or rules (see the note at the end).
Given — what the tests call
Four classes, in the editor above your code. Read them first.
class Usage: # usage.token_count: int
class Message: # message_id, role, text, usage (a Usage)
class Page: # messages: list[Message], NEWEST first; next_cursor: str | None
class ConversationClient:
def __init__(self, conversations: dict, page_size: int = 50): ...
def list_messages(self, conversation_id: str, cursor: str | None = None) -> Page: ...
list_messages(conversation_id) with no cursor returns the first page: the newest messages. Pass page.next_cursor back to get the next, older page. The last page has next_cursor None.None again starts over from the newest page. Cursors are opaque strings.ConversationClient(conversations, page_size=2), where conversations maps an id to its messages, oldest first. Your code only calls list_messages.client.calls counts calls to list_messages. The tests check it.Part 1 — page through a conversation
def fetch_history(client, conversation_id: str) -> list[Message]: ...
list_messages with each page's next_cursor until there is no next page.Message, oldest first.Part 2 — compact the history by token count
def compact(messages: list[Message], trigger: int = 20000, target: int = 10000) -> list[Message]: ...
message.usage.token_count.trigger (20,000), drop the oldest messages until the total is under target (10,000). Return the messages left, oldest first.target above trigger raises ValueError.Not reported: the third part. No report gives its task or rules. Two replies say it is close to Part 2 and uses the same idea. Nobody in these reports says they finished it: two ran out of time after Part 2, one was asked to explain the approach with 10 minutes left, and another explained it along with how to optimize the second and third parts together.
Notes: the class names, fields and method signature above are ours, written to match what the reports describe: pages linked by next_cursor, and a token_count on each message. So are newest-first pages, "None starts over", the oldest-first result, the strict "under 10,000" (exactly 10,000 drops one more) and the ValueError rules. The 20,000 and 10,000 thresholds and dropping the oldest messages first are reported. The given API in your round will differ, so read it before you code.
Explain how you would do the third part, and how the second and third parts could be optimized together.
What the reports say: three reports say the code is easy and the given API is the hard part. Spend the first minutes mapping how the classes relate, then code. Part 2 uses two thresholds: compact above 20,000 tokens, down to under 10,000, dropping the oldest messages first. Nobody reported finishing the third part in 45 minutes, so move fast through the first two.
Common mistakes (ours, not reported): Stopping on an empty page instead of on the next cursor; one extra call after the last page; returning messages in page order when the pages are newest first; compacting whenever the total is above 10,000; re-summing the tokens after every dropped message.
Edge cases to test (ours): An empty conversation; a history that fills its last page exactly; a total between 10,000 and 20,000; a total that lands exactly on 10,000 while dropping; one message bigger than the target.
If you have had this round, tell us how close this page was. It is how we keep the pages accurate.