atiaomar1978-hub opened a new pull request, #24901: URL: https://github.com/apache/camel/pull/24901
## CAMEL-23394 — Conversation history size limits **Issue:** https://issues.apache.org/jira/browse/CAMEL-23394 **Branch:** `CAMEL-23394-conversation-history-size` **Commit:** `f8e2ab40b40` ### Problem With `conversationMemory=true`, history in `CamelOpenAIConversationHistory` grew without bound. Long or agentic exchanges could exceed the model context window and cause API errors. ### Solution Two new options on `camel-openai`: | Option | Default | Behavior | |--------|---------|----------| | `maxHistoryMessages` | `0` | Keep only the N most recent history messages (`0` = unlimited) | | `maxHistoryTokens` | `0` | Drop oldest messages until estimated tokens (chars ÷ 4) fit the limit (`0` = unlimited) | System/developer messages are not stored in history (they’re prepended in `buildMessages()`), so they’re outside these limits. ### Implementation - **`OpenAIConversationHistoryTrimmer`** — sliding-window trim + DEBUG log when messages are dropped - Applied when **reading** history (`addConversationHistory`) and **writing** it (`OpenAIProducer`, `OpenAIToolExecutionProducer`) - Regenerated `openai.json` + endpoint configurer/uri factory ### Tests (100/100) - **`OpenAIConversationHistoryTrimmerTest`** — 5 unit tests (message cap, token cap, both, tool-call args in token estimate, no-op when unset) - **`OpenAIConversationHistorySizeTest`** — mock multi-turn route; `maxHistoryMessages=2` drops old turns from requests and exchange property -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
