Skip to content

Conversation

@xiaoju111a
Copy link
Contributor

@xiaoju111a xiaoju111a commented Jan 30, 2026

Related Issue

Resolve #788
Resolve #796
Resolve #778

Description

This PR fixes a critical bug where the compaction process would include media parts (video_url, image_url, audio_url) in the compaction message, causing a 400 API error when context usage approaches 100%.

Problem

When conversation context reaches ~100% capacity, the system triggers automatic compaction to summarize old messages. However, the compaction logic was including all content parts (including media files) in the compaction request. The Kimi API does not accept media parts in compaction messages, resulting in:

Error code: 400 - {'error': {'message': "the message at position 1 with role 'user' contains an invalid part type: video_url", 'type': 'invalid_request_error'}}

Solution

Modified src/kimi_cli/soul/compaction.py to filter out media parts (ImageURLPart, AudioURLPart, VideoURLPart) during the compaction preparation phase. Only text content and tool-related parts are now included in compaction messages.

Changes

  • src/kimi_cli/soul/compaction.py: Added media part filtering in the prepare() method
  • tests/core/test_simple_compaction.py: Added test case to verify media parts are correctly filtered

Impact

  • ✅ Prevents 400 API errors during compaction at high context usage
  • ✅ Allows conversations with media files to continue smoothly
  • ✅ Text content from messages with media is still preserved in compaction
  • ✅ Recent messages (preserved messages) still contain their original media parts

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open with Devin

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional flags.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant