Skip to main content

derive_context

Function derive_context 

Source
pub async fn derive_context(
    session: &Session,
    provider: Arc<dyn Provider>,
    model: &str,
    system_prompt: &str,
    tools: &[ToolDefinition],
    event_tx: Option<&Sender<SessionEvent>>,
    force_keep_last: Option<usize>,
) -> Result<DerivedContext>
Expand description

Derive an ephemeral DerivedContext from session’s pure history.

The canonical Session::messages buffer is never touched — session is borrowed immutably.

§Arguments

  • session — The owning session (read-only borrow).
  • provider — Caller’s primary provider.
  • model — Caller’s primary model identifier.
  • system_prompt — Included in token estimates.
  • tools — Tool definitions, included in token estimates.
  • event_tx — Optional channel for compaction lifecycle events.
  • force_keep_last — When Some(n), skip the adaptive budget cascade and force a single compress_messages_keep_last call.

§Errors

Propagates any error from the underlying compression pipeline that the recovery cascade cannot absorb.