๐Ÿš€ Everything is free โ€” help us improve! Submit feedback and shape the platform.
๐ŸงชTDD Challengeยทadvancedยทโฑ๏ธ 35โ€“50mยทโญ 225 XP

M-013Build a Context Window Manager

Description

Nebula Corp's chatbot keeps crashing when conversations get too long โ€” it exceeds the model's context window. Build a context window manager that tracks token usage, implements smart truncation strategies (keep system prompt + recent messages + important messages), and warns when approaching the limit. The manager should support multiple truncation strategies: 'sliding-window', 'summarize-old', and 'priority-based'.

Test Cases (3)

Tracks token count
Should count tokens across messages
Input:testTokenCount()
Expected:CONTAINS:7
Sliding window keeps recent
Should keep system + recent messages after truncation
Input:testSlidingWindow()
Expected:CONTAINS:2
Detects near limit
Should detect when approaching token limit
Input:testNearLimit()
Expected:CONTAINS:true

Related Lessons

Click Run / Check to validate your solution