Files
letta-server/letta/services/summarizer/summarizer_config.py
Sarah Wooders 7ea297231a feat: add compaction_settings to agents (#6625)
* initial commit

* Add database migration for compaction_settings field

This migration adds the compaction_settings column to the agents table
to support customized summarization configuration for each agent.

🐾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>

* fix

* rename

* update apis

* fix tests

* update web test

---------

Co-authored-by: Letta <noreply@letta.com>
Co-authored-by: Kian Jones <kian@letta.com>
2025-12-15 12:02:34 -08:00

47 lines
2.0 KiB
Python

from typing import Literal
from pydantic import BaseModel, Field
from letta.schemas.llm_config import LLMConfig
from letta.schemas.model import ModelSettings
class CompactionSettings(BaseModel):
# summarizer_model: LLMConfig = Field(default=..., description="The model to use for summarization.")
model_settings: ModelSettings = Field(default=..., description="The model settings to use for summarization.")
prompt: str = Field(default=..., description="The prompt to use for summarization.")
prompt_acknowledgement: str = Field(
default=..., description="Whether to include an acknowledgement post-prompt (helps prevent non-summary outputs)."
)
clip_chars: int | None = Field(
default=2000, description="The maximum length of the summary in characters. If none, no clipping is performed."
)
mode: Literal["all", "sliding_window"] = Field(default="sliding_window", description="The type of summarization technique use.")
sliding_window_percentage: float = Field(
default=0.3, description="The percentage of the context window to keep post-summarization (only used in sliding window mode)."
)
def get_default_compaction_settings(model_settings: ModelSettings) -> CompactionSettings:
"""Build a default CompactionSettings from global settings for backward compatibility.
Args:
llm_config: The LLMConfig to use for the summarizer model (typically the agent's llm_config).
Returns:
A CompactionSettings with default values from global settings.
"""
from letta.constants import MESSAGE_SUMMARY_REQUEST_ACK
from letta.prompts import gpt_summarize
from letta.settings import summarizer_settings
return CompactionSettings(
mode="sliding_window",
model_settings=model_settings,
prompt=gpt_summarize.SYSTEM,
prompt_acknowledgement=MESSAGE_SUMMARY_REQUEST_ACK,
clip_chars=2000,
sliding_window_percentage=summarizer_settings.partial_evict_summarizer_percentage,
)