Trim messages to Google context window before send#2567
Merged
hiroshinishio merged 1 commit intomainfrom Apr 21, 2026
Merged
Conversation
Extends Claude's trim_messages pattern to Google so gemma-4-31b-it (262144 token cap) stops throwing 400 INVALID_ARGUMENT on bursty test_failure payloads (AGENT-3JR/3JS/3JT/3JV, 2026-04-20 gitautoai/website PR 810, conversation jumped 11855 -> 262144+ tokens in 9s at new chat_with_agent invocation). trim_messages_to_token_limit now takes a count_tokens_fn callback; Claude and Google each supply their own count_tokens_* function via functools.partial. Shared trim + message_to_dict moved to services/messages/ so they aren't Claude-specific. Added CONTEXT_WINDOW and MAX_OUTPUT_TOKENS to constants/google_ai.py matching constants/claude.py. Also enables pytest --import-mode=importlib both in our own pytest.ini and in run_pytest_test.py so duplicate test filenames (e.g. test_count_tokens.py in both claude/ and google_ai/) coexist without the 'import file mismatch' collection error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.