vibe.assistant.history_pruner

History pruning utilities for conversation context management.

HistoryPruner

Prunes conversation history to optimize context window usage.

Provides two pruning strategies: 1. Response checkpoint pruning: For APIs that support response_id continuation 2. Consolidated strategy pruning: Aggressive pruning when draft is in system prompt

prune_to_response_checkpoint

prune_to_response_checkpoint(history: list[Message]) -> tuple[list[Message], bool]

Prune history to messages after the last response_id checkpoint.

When an AssistantMessage has a response_id, the Responses API already has context up to that point. We only need to send messages that came after.

Parameters:
  • history (list[Message]) –

    List of Message objects

Returns:
  • list[Message]

    Tuple of (pruned_history, using_continuation) where using_continuation

  • bool

    indicates if a checkpoint was found and used.

prune_for_consolidated_strategy

prune_for_consolidated_strategy(history: list[Message]) -> list[Message]

Prune conversation history for consolidated draft strategy.

With consolidate_draft=True, system prompt contains current state, so we only need minimal history: - INITIAL user message (the goal/instruction from template - critical!) - Last assistant message (shows what was just done and what questions were asked) - Tool responses to those calls - User message (if answering questions)

All older block manipulation history is redundant with system prompt.

Parameters:
  • history (list[Message]) –

    List of Message objects

Returns:
  • list[Message]

    Pruned list of messages containing only essential context.

truncate_to_max_turns

truncate_to_max_turns(history: list[Message], max_turns: int) -> list[Message]

Truncate to keep only recent messages.

Parameters:
  • history (list[Message]) –

    List of Message objects

  • max_turns (int) –

    Maximum number of turns to keep (each turn = 2 messages)

Returns:
  • list[Message]

    Truncated list of messages.