Skip to content

Conversation

@copybara-service
Copy link

@copybara-service copybara-service bot commented Jan 22, 2026

feat: new ContextFilterPlugin

Introduces a new ContextFilterPlugin in Java, which is designed to reduce the size of the LLM context by filtering out older turns.

Here's a breakdown:

  • ContextFilterPlugin.java: This new plugin extends BasePlugin and implements logic in its beforeModelCallback method. It trims the LlmRequest contents to retain only a specified number of the most recent "model" turns and their preceding "user" turns. A key aspect is the adjustSplitIndexToAvoidOrphanedFunctionResponses method, which ensures that any FunctionResponse included in the filtered context has its corresponding FunctionCall also present, preventing invalid inputs to the LLM.
  • ContextFilterPluginTest.java: This file contains unit tests for ContextFilterPlugin, verifying its behavior for both scenarios where context filtering is not needed and where it successfully reduces the LlmRequest contents based on the configured number of invocations to keep.

@copybara-service copybara-service bot force-pushed the test_859380380 branch 7 times, most recently from 45f4378 to f053993 Compare January 22, 2026 14:56
Introduces a new `ContextFilterPlugin` in Java, which is designed to reduce the size of the LLM context by filtering out older turns.

Here's a breakdown:

*   **`ContextFilterPlugin.java`**: This new plugin extends `BasePlugin` and implements logic in its `beforeModelCallback` method. It trims the `LlmRequest` contents to retain only a specified number of the most recent "model" turns and their preceding "user" turns. A key aspect is the `adjustSplitIndexToAvoidOrphanedFunctionResponses` method, which ensures that any `FunctionResponse` included in the filtered context has its corresponding `FunctionCall` also present, preventing invalid inputs to the LLM.
*   **`ContextFilterPluginTest.java`**: This file contains unit tests for `ContextFilterPlugin`, verifying its behavior for both scenarios where context filtering is not needed and where it successfully reduces the `LlmRequest` contents based on the configured number of invocations to keep.

PiperOrigin-RevId: 859380380
@copybara-service copybara-service bot changed the title feat: new Plugins feat: new ContextFilterPlugin Jan 22, 2026
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