Files
letta-server/letta/services/summarizer/summarizer_all.py
2025-12-15 12:02:19 -08:00

44 lines
1.5 KiB
Python

from typing import List
from letta.log import get_logger
from letta.schemas.llm_config import LLMConfig
from letta.schemas.message import Message
from letta.schemas.user import User
from letta.services.summarizer.summarizer import simple_summary
from letta.services.summarizer.summarizer_config import SummarizerConfig
logger = get_logger(__name__)
async def summarize_all(
# Required to tag LLM calls
actor: User,
# LLM config for the summarizer model
llm_config: LLMConfig,
# Actual summarization configuration
summarizer_config: SummarizerConfig,
in_context_messages: List[Message],
new_messages: List[Message],
) -> str:
"""
Summarize the entire conversation history into a single summary.
Returns:
- The summary string
"""
all_in_context_messages = in_context_messages + new_messages
summary_message_str = await simple_summary(
messages=all_in_context_messages,
llm_config=llm_config,
actor=actor,
include_ack=bool(summarizer_config.prompt_acknowledgement),
prompt=summarizer_config.prompt,
)
if summarizer_config.clip_chars is not None and len(summary_message_str) > summarizer_config.clip_chars:
logger.warning(f"Summary length {len(summary_message_str)} exceeds clip length {summarizer_config.clip_chars}. Truncating.")
summary_message_str = summary_message_str[: summarizer_config.clip_chars] + "... [summary truncated to fit]"
return summary_message_str