Convenience function to run the full LLM-based compaction for a session.
(
session_id: &str,
parent_id: &str,
messages: Vec<Message>,
model: LlmModelRef,
provider: Arc<dyn Provider>,
abort: tokio_util::sync::CancellationToken,
auto: bool,
co
| 902 | |
| 903 | /// Convenience function to run the full LLM-based compaction for a session. |
| 904 | pub async fn run_compaction<S: SessionOps>( |
| 905 | session_id: &str, |
| 906 | parent_id: &str, |
| 907 | messages: Vec<Message>, |
| 908 | model: LlmModelRef, |
| 909 | provider: Arc<dyn Provider>, |
| 910 | abort: tokio_util::sync::CancellationToken, |
| 911 | auto: bool, |
| 912 | config: Option<CompactionConfig>, |
| 913 | session_ops: Option<&S>, |
| 914 | ) -> anyhow::Result<CompactionResult> { |
| 915 | let engine = CompactionEngine::new(config.unwrap_or_default()); |
| 916 | |
| 917 | let input = CompactionInput { |
| 918 | parent_id: parent_id.to_string(), |
| 919 | session_id: session_id.to_string(), |
| 920 | messages, |
| 921 | messages_with_parts: vec![], |
| 922 | abort, |
| 923 | auto, |
| 924 | model, |
| 925 | custom_prompt: None, |
| 926 | plugin_context: None, |
| 927 | cwd: None, |
| 928 | root: None, |
| 929 | variant: None, |
| 930 | original_agent: None, |
| 931 | }; |
| 932 | |
| 933 | engine.process(input, provider, session_ops).await |
| 934 | } |
| 935 | |
| 936 | /// Convert `MessageWithParts` to the `MessageForPrune` format used by the |
| 937 | /// prune algorithm. |