Skip to content

fix(apps): explicitly preserve language and tools during event compac…#6273#6329

Open
eajajhossain wants to merge 1 commit into
google:mainfrom
eajajhossain:fix/compaction-language-anchor
Open

fix(apps): explicitly preserve language and tools during event compac…#6273#6329
eajajhossain wants to merge 1 commit into
google:mainfrom
eajajhossain:fix/compaction-language-anchor

Conversation

@eajajhossain

@eajajhossain eajajhossain commented Jul 7, 2026

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

N/A

Problem:
During long-lived sessions with multiple compaction cycles, massive tool payloads (200K+ chars) cause "Attention Dilution." The model loses its language anchor (e.g., switching to Russian) and hallucinates tools (e.g., calling run_command which isn't registered) because the default LlmEventSummarizer strips the exact language and tool context during compaction.

Solution:
Updated the _DEFAULT_PROMPT_TEMPLATE in LlmEventSummarizer to include explicit CRITICAL INSTRUCTIONS. The summarizer is now forced to explicitly identify and state the primary conversation language and accurately list the exact tool names used. This ensures these structural anchors survive inside the EventCompaction object, preserving grounding when the main agent resumes.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Passed pytest results:

----- 8 passed, 4 warnings in 25.33s -----

Manual End-to-End (E2E) Tests:

Setup:

  • Configured an agent with DatabaseSessionService and EventsCompactionConfig(compaction_interval=10).
  • Conducted a multi-turn conversation that uses tools and exceeds the compaction interval.

Logs/Evidence:
When running the agent and inspecting the generated EventCompaction event in the session storage (or verbose terminal logs), the summary now clearly injects the explicit anchors requested:

{
  "role": "model",
  "parts": [
    {
      "text": "Conversation Language: English\nTools Used: fetch_documents, retrieve_by_bank\n..."
    }
  ]
}

This proves the language and tool grounding is successfully retained and passed back to the main agent.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

None

@rohityan rohityan added the core [Component] This issue is related to the core interface and implementation label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLM event compaction loses conversation language context - model switches to other languages (or hallucinates tools) after summarization

3 participants