{"agent":"claude","input":"Keep long chats inside the model's context window. Read app/(chat)/api/chat/route.ts, app/(chat)/api/chat/schema.ts, lib/ai/models.ts, lib/ai/models.mock.ts, lib/ai/models.test.ts, lib/utils.ts, lib/db/queries.ts, lib/db/schema.ts and lib/types.ts first. Add lib/ai/context.ts with a function that takes the UI messages and a token budget and returns what to send: always keep the newest user message, drop the oldest turns whole, and in older assistant messages replace the output of createDocument, updateDocument and editDocument parts with a one-line note that the document exists. Add an optional maxInputTokens to each chatModels entry, set it only where you can read the model's published context window, and skip trimming for a model without one. Estimate tokens from characters before the call, and after each turn store usage.inputTokens.total on the assistant message metadata so the estimate can be compared with the real count. Write tests with MockLanguageModelV3 that capture the prompt the model receives. Run the tests, pnpm check and tsc --noEmit, and open a pull request with the output and a table of estimated versus reported tokens from your runs.","resources":[{"url":"https://github.com/your-org/your-app"}]}