plexus.cli.procedure.conversation_utils module
Conversation utilities for procedure AI execution.
This module provides utilities for managing conversation history, including filtering and processing messages for AI model context limits.
- class plexus.cli.procedure.conversation_utils.ConversationUtils
Bases:
objectUtility class for conversation management in procedure execution.
- static filter_conversation_history_for_model(full_conversation_history: List, max_tokens: int | None = None) List
Filter the conversation history for the AI model to prevent context overflow.
CRITICAL: This function creates a FILTERED representation of the conversation that is sent to the AI model. It is NOT the same as the complete conversation history that we maintain for chat recording and orchestration purposes.
Filtering Rules: 1. Keep all non-tool messages (SystemMessage, HumanMessage, AIMessage) intact 2. Keep the most recent 2 tool result messages in full 3. Truncate all older tool result messages to 500 characters + truncation notice 4. This forces the AI to summarize its learnings since older tool details become ephemeral
Token Counting (when max_tokens is provided): - Uses TikToken to count tokens in conversation - Currently logs token usage for monitoring (future: implement token-based filtering)
- Args:
full_conversation_history: Complete conversation history with all messages max_tokens: Optional maximum token limit for the conversation
- Returns:
Filtered conversation history suitable for model context limits