← Back to PRs

#10214: feat(compaction): Add Anthropic server-side compaction API support

by GodsBoy open 2026-02-06 07:09 View on GitHub →
docs extensions: memory-lancedb agents stale
## Summary Adds opt-in support for Anthropic's server-side compaction API, which offloads context summarization to Anthropic's API for better performance and summarization quality. Closes #10213 ## Changes - **Config**: Add `serverSide` option under `agents.defaults.compaction` - `enabled`: Boolean to enable server-side compaction (default: false) - `strategy`: Compaction strategy version (default: "compact_20260112") - **API Integration**: - Add `context_management.edits` parameter with compaction strategy - Add `anthropic-beta: context-management-2025-06-27` header - **Backward Compatibility**: Client-side compaction remains the default - **Tests**: Add comprehensive test suite (8 tests covering all scenarios) - **Documentation**: Update compaction docs with usage examples ## Configuration Example ```json5 { agents: { defaults: { compaction: { serverSide: { enabled: true, strategy: "compact_20260112", // optional, this is the default }, }, }, }, } ``` ## Technical Details When enabled, the implementation: 1. Adds the `context-management-2025-06-27` beta header to Anthropic API requests 2. Includes `context_management.edits` in the request body with the specified strategy 3. Preserves existing beta headers and extraBody properties 4. Works alongside other extra params (temperature, maxTokens, etc.) ## Testing - [x] All 8 new tests pass - [x] Schema validation passes for new config options - [x] No breaking changes to existing functionality ## References - [Anthropic Compaction Docs](https://docs.anthropic.com/en/docs/build-with-claude/compaction) - [Cookbook: Automatic Context Compaction](https://platform.claude.com/cookbook/tool-use-automatic-context-compaction) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds opt-in Anthropic server-side compaction support by introducing `agents.defaults.compaction.serverSide` config, validating it in the agent-defaults zod schema, and wrapping the embedded runner stream function to inject the `anthropic-beta: context-management-2025-06-27` header plus a `context_management.edits` request body entry (defaulting to strategy `compact_20260112`). It also adds a dedicated vitest suite covering enable/disable behavior, header appending, and `extraBody` preservation, and documents how to configure the feature. <h3>Confidence Score: 4/5</h3> - Generally safe to merge, but has a couple of edge-case request-shaping regressions that should be fixed first. - Core integration is small and well-tested, but the wrapper currently (1) concatenates an untyped existing header value into a string and (2) overwrites any existing `extraBody.context_management`, which can break users who already set these fields. - src/agents/pi-embedded-runner/extra-params.ts <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs