Add configurable summary_message_template to LLMContextSummarizationConfig
Allows applications to customize how the summary is wrapped when injected into context (e.g., XML tags, custom delimiters) so system prompts can distinguish summaries from live conversation.
This commit is contained in:
@@ -306,8 +306,10 @@ class LLMContextSummarizer(BaseObject):
|
||||
# Get recent messages to keep
|
||||
recent_messages = messages[last_summarized_index + 1 :]
|
||||
|
||||
# Create summary message as an user message
|
||||
summary_message = {"role": "user", "content": f"Conversation summary: {summary}"}
|
||||
# Create summary message as a user message (the summary is context
|
||||
# provided *to* the assistant, not something the assistant said)
|
||||
summary_content = self._config.summary_message_template.format(summary=summary)
|
||||
summary_message = {"role": "user", "content": summary_content}
|
||||
|
||||
# Reconstruct context
|
||||
new_messages = []
|
||||
|
||||
@@ -73,6 +73,11 @@ class LLMContextSummarizationConfig:
|
||||
immediate conversational context.
|
||||
summarization_prompt: Custom prompt for the LLM to use when generating
|
||||
summaries. If None, uses DEFAULT_SUMMARIZATION_PROMPT.
|
||||
summary_message_template: Template for formatting the summary when
|
||||
injected into context. Must contain ``{summary}`` as a placeholder
|
||||
for the generated summary text. Allows applications to wrap the
|
||||
summary in custom delimiters (e.g., XML tags) so that system
|
||||
prompts can distinguish summaries from live conversation.
|
||||
"""
|
||||
|
||||
max_context_tokens: int = 8000
|
||||
@@ -80,6 +85,7 @@ class LLMContextSummarizationConfig:
|
||||
max_unsummarized_messages: int = 20
|
||||
min_messages_after_summary: int = 4
|
||||
summarization_prompt: Optional[str] = None
|
||||
summary_message_template: str = "Conversation summary: {summary}"
|
||||
|
||||
def __post_init__(self):
|
||||
"""Validate configuration parameters."""
|
||||
|
||||
Reference in New Issue
Block a user