Skip to content

Trim messages to Google context window before send#2567

Merged
hiroshinishio merged 1 commit intomainfrom
wes
Apr 21, 2026
Merged

Trim messages to Google context window before send#2567
hiroshinishio merged 1 commit intomainfrom
wes

Conversation

@hiroshinishio
Copy link
Copy Markdown
Collaborator

No description provided.

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.
@hiroshinishio hiroshinishio self-assigned this Apr 21, 2026
@hiroshinishio hiroshinishio merged commit 131fa6f into main Apr 21, 2026
1 check passed
@hiroshinishio hiroshinishio deleted the wes branch April 21, 2026 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant