davsclaus opened a new pull request, #30018: URL: https://github.com/apache/camel/pull/30018
JIRA: [CAMEL-26932](https://issues.apache.org/jira/browse/CAMEL-26932), item 7. ## The bug `camel ask` without a question opens a chat that keeps one history for all its questions. Every tool call and every tool result went into it in full: `cli_exec` alone returns up to 32 KB of stdout plus 32 KB of stderr. The whole history was sent with every question, and nothing trimmed it. Once it was larger than the context window of the model, every later question failed. A question that failed also stayed in the history, so the next request sent the failed turn again. ## The fix The chat bounds its history as the AI panel of the TUI already does: - a tool result is cut at 18,000 characters (`CatalogDocs.MAX_ANSWER_LENGTH`, so no catalog answer is cut) before it enters the history; - once a question is answered, the tool results of the questions before the previous one are shrunk to 400 characters, and the chat keeps the last 20 questions. Whole turns are removed, so a tool call never loses its result; - a question that fails (the model is not reachable, or there is no answer within `--max-iterations`) is removed from the history. The note on the mistakes of the answer before (CAMEL-26960) is kept for the next question. The history code moved from `AiPanel` (TUI) to camel-jbang-core as `ChatHistory`, which `camel ask` and the AI panel now share. `AiPanel`'s methods call it, so its tests are unchanged. Its size limit in `SourceSizeTest` goes down to 3093 lines. ## Tests - `AskLoopTest.aQuestionOfAChatThatFailsLeavesNoTraceInTheHistory`: a 500 from the model leaves the history empty, and the next request has only the system prompt and the new question. - `AskLoopTest.theToolResultsOfAChatStayBounded`: three questions with a 36,000-character tool result each. All results are cut, the result of the first question is shrunk, and the previous question's result is kept. - Both fail on main. The core suite and the TUI suite (2617 tests) are green. `DependencyUpdateTest` failed once and passed on rerun; it fails once per run on every branch. Docs: `camel-jbang-ai.adoc` says how the chat keeps its history bounded. _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
