androidengineers.Book a session

Bounded conversational memory

Practice: PocketChat context policy

exerciseSelf-paced

Assignment: implement a real context improvement

Prerequisites: understand buildContext, JUnit assertions, and the difference between a completed turn and an attempt. Work on your learning branch, never change the shared published baseline.

Create ContextPolicyLessonTest.kt in app/src/test/java/com/androidengineers/pocketchat/. The codelab's context-policy step provides the exact test file and implementation.

The required cases are:

  • Two completed pairs with a limit of one retain only the newest pair and report omission.
  • Limits zero and negative one throw IllegalArgumentException before generation.
  • A stopped partial answer is excluded, and a six-character budget still retains only the pair that fits plus the latest question.

Run only your new class while iterating:

./gradlew :app:testDebugUnitTest --tests '*ContextPolicyLessonTest'

Add the new signature parameter with no behavior first. Two assertions should fail; the character-budget case should already pass. Then add parameter validation and the count guard inside the reverse traversal. Run the full unit suite afterward to detect regressions.

Submit the red and green summaries, the function diff, and a hand-worked example showing how pair count and character budget interact. Explain why omitted compares with all eligible completed turns rather than with every stored attempt. Do not call six pairs “six tokens” or “six messages”: a pair contains two API parts.

Study guide · Hands-on codelab · Pinned Android source

YOUR LEARNING JOURNEY

0 of 23 available lessons completed

Progress saved in this browser. No account needed.
Practice: PocketChat context policy | Gemini Chat for Android with PocketChat | Android Engineers