Repository navigation
feat(flow): support conversational flow context compaction - #8627
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Strix Security ReviewWarning This pull request has 33 commits after the last Strix review ( ✅ No open security findings. PR summary: This PR adds context-window compaction to conversational Flows: the built-in `converse`, `answer_from_history` and router LLM calls now go through CrewAI's shared summarizer (compacting proactively near the model limit and retrying once after a provider context-limit error), controlled by a new `respect_context_window` setting that defaults to enabled across the Python config, the declarative definition and the DSL round-trip, with documentation in four locales. Review summaryReviewed all ten changed files in full, including every hunk of the new Ruled out (2)
Review 1 on this PR · Reviewed by Strix |
fed80b6 to
ab9a69c
Compare
Vidit-Ostwal
left a comment
There was a problem hiding this comment.
One naming suggestion for clarity.
Related issue
None.
Summary
Long conversational histories currently fail at the model context limit without using CrewAI's shared compaction. Reuse the BaseLLM summarizer for built-in converse, history-only, and router calls, with proactive compaction and one recovery attempt after a provider context-limit error.
Preserve the public transcript, system prompt, and latest user message. Keep internal summary text out of streamed replies. Enable handling by default through
respect_context_window, with an opt-out supported in Python and declarative flows. Document the behavior in English, Arabic, Korean, and Brazilian Portuguese.Verification
Additional context
Compaction changes the model request;
state.messagesremains intact for display and persistence, so later turns may summarize again. Call-only custom LLM objects, legacy intent pre-classification, and custom route handlers retain their existing context handling. Local probe scripts and logs are excluded from this PR.Note
Medium Risk
Changes default LLM request shaping for built-in chat/router paths and adds one-shot recovery on context errors; transcript persistence is preserved but model inputs differ from before when histories are long.
Overview
Adds automatic context compaction for conversational Flows on
BaseLLMmodels, enabled by default via newConversationConfig.respect_context_window(also on declarativeconversationalblocks and DSL round-trips).Built-in
converse, deprecatedanswer_from_history, and router calls now go through_call_conversation_llm, which proactively summarizes when the window is near the limit and retries once after provider context-overflow errors. Compaction only changes the per-turn model request:state.messagesstays intact, system prompts are kept, the latest user turn is re-appended after summarization, and summary LLM calls run with streaming disabled so internal text does not leak into replies. Customcall()-only LLMs, legacy intent pre-classification, and custom route handlers are unchanged.agent_utilsgainsallow_single_user_compactionso router payloads that are a single user message can still be compacted.Docs for conversational flows are updated in en, ar, ko, and pt-BR.
test_flow_context_compaction.pycovers proactive compaction, streaming, bounded retry, opt-out, router/history paths, and declaration round-tripping.authlibis bumped to ≥1.9.1 inpyproject.toml/uv.lock.Reviewed by Cursor Bugbot for commit 0836feb. Bugbot is set up for automated code reviews on this repo. Configure here.