trim_messages
Compress chat message history by trimming oldest non-system messages when token count exceeds threshold, preserving system messages and recent context.
Instructions
Compress chat message history using token-based trimming strategy. Removes oldest non-system messages when token count exceeds threshold while preserving system messages and recent context.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| messages | Yes | Array of chat messages to compress | |
| maxModelTokens | No | Model's maximum token context window | |
| thresholdPercent | No | Percentage threshold to trigger compression (0-1) | |
| minRecentMessages | No | Minimum recent messages to always preserve |