From 1590e4e3e65fe3186f2069a40a165ad8e46dad26 Mon Sep 17 00:00:00 2001 From: Andy Li <55300002+cliandy@users.noreply.github.com> Date: Tue, 22 Jul 2025 14:54:22 -0700 Subject: [PATCH] chore: decrease pool logging --- letta/local_llm/constants.py | 3 ++- letta/local_llm/json_parser.py | 16 ++++++++-------- letta/otel/db_pool_monitoring.py | 25 +++++++++++++------------ letta/settings.py | 15 +++++++++------ 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/letta/local_llm/constants.py b/letta/local_llm/constants.py index 441bb4ae..83681fde 100644 --- a/letta/local_llm/constants.py +++ b/letta/local_llm/constants.py @@ -25,8 +25,9 @@ DEFAULT_OLLAMA_MODEL = "dolphin2.2-mistral:7b-q6_K" DEFAULT_WRAPPER = ChatMLInnerMonologueWrapper DEFAULT_WRAPPER_NAME = "chatml" -INNER_THOUGHTS_KWARG = "thinking" # used to be "inner_thoughts" +INNER_THOUGHTS_KWARG = "thinking" INNER_THOUGHTS_KWARG_VERTEX = "thinking" +VALID_INNER_THOUGHTS_KWARGS = ("thinking", "inner_thoughts") INNER_THOUGHTS_KWARG_DESCRIPTION = "Deep inner monologue private to you only." INNER_THOUGHTS_KWARG_DESCRIPTION_GO_FIRST = f"Deep inner monologue private to you only. Think before you act, so always generate arg '{INNER_THOUGHTS_KWARG}' first before any other arg." INNER_THOUGHTS_CLI_SYMBOL = "💭" diff --git a/letta/local_llm/json_parser.py b/letta/local_llm/json_parser.py index f721e557..961c32d4 100644 --- a/letta/local_llm/json_parser.py +++ b/letta/local_llm/json_parser.py @@ -78,19 +78,19 @@ def add_missing_heartbeat(llm_json): def clean_and_interpret_send_message_json(json_string): - from letta.local_llm.constants import INNER_THOUGHTS_KWARG + from letta.local_llm.constants import INNER_THOUGHTS_KWARG, VALID_INNER_THOUGHTS_KWARGS + from letta.settings import model_settings + + kwarg = model_settings.inner_thoughts_kwarg + if kwarg not in VALID_INNER_THOUGHTS_KWARGS: + warnings.warn(f"INNER_THOUGHTS_KWARG is not valid: {kwarg}") + kwarg = INNER_THOUGHTS_KWARG # If normal parsing fails, attempt to clean and extract manually cleaned_json_string = re.sub(r"[^\x00-\x7F]+", "", json_string) # Remove non-ASCII characters function_match = re.search(r'"function":\s*"send_message"', cleaned_json_string) - if INNER_THOUGHTS_KWARG == "inner_thoughts": - inner_thoughts_match = re.search(r'"inner_thoughts":\s*"([^"]+)"', cleaned_json_string) - elif INNER_THOUGHTS_KWARG == "thinking": - inner_thoughts_match = re.search(r'"thinking":\s*"([^"]+)"', cleaned_json_string) - else: - warnings.warn(f"INNER_THOUGHTS_KWARG is not valid: {INNER_THOUGHTS_KWARG}") - inner_thoughts_match = re.search(r'"inner_thoughts":\s*"([^"]+)"', cleaned_json_string) + inner_thoughts_match = re.search(rf'"{kwarg}":\s*"([^"]+)"', cleaned_json_string) message_match = re.search(r'"message":\s*"([^"]+)"', cleaned_json_string) if function_match and inner_thoughts_match and message_match: diff --git a/letta/otel/db_pool_monitoring.py b/letta/otel/db_pool_monitoring.py index 3d04f25f..2208ac8f 100644 --- a/letta/otel/db_pool_monitoring.py +++ b/letta/otel/db_pool_monitoring.py @@ -89,18 +89,18 @@ class DatabasePoolMonitor: try: from letta.otel.metric_registry import MetricRegistry - # Record current pool statistics - pool_stats = self._get_pool_stats(pool) attrs = { "engine_name": engine_name, **get_ctx_attributes(), } - - MetricRegistry().db_pool_connections_checked_out_gauge.set(pool_stats["checked_out"], attributes=attrs) - MetricRegistry().db_pool_connections_available_gauge.set(pool_stats["available"], attributes=attrs) - MetricRegistry().db_pool_connections_total_gauge.set(pool_stats["total"], attributes=attrs) - if pool_stats["overflow"] is not None: - MetricRegistry().db_pool_connections_overflow_gauge.set(pool_stats["overflow"], attributes=attrs) + # Record current pool statistics + if isinstance(pool, QueuePool): + pool_stats = self._get_pool_stats(pool) + MetricRegistry().db_pool_connections_checked_out_gauge.set(pool_stats["checked_out"], attributes=attrs) + MetricRegistry().db_pool_connections_available_gauge.set(pool_stats["available"], attributes=attrs) + MetricRegistry().db_pool_connections_total_gauge.set(pool_stats["total"], attributes=attrs) + if pool_stats["overflow"] is not None: + MetricRegistry().db_pool_connections_overflow_gauge.set(pool_stats["overflow"], attributes=attrs) # Record checkout event attrs["event"] = "checkout" @@ -137,15 +137,16 @@ class DatabasePoolMonitor: try: from letta.otel.metric_registry import MetricRegistry - # Record current pool statistics after checkin - pool_stats = self._get_pool_stats(pool) attrs = { "engine_name": engine_name, **get_ctx_attributes(), } - MetricRegistry().db_pool_connections_checked_out_gauge.set(pool_stats["checked_out"], attributes=attrs) - MetricRegistry().db_pool_connections_available_gauge.set(pool_stats["available"], attributes=attrs) + # Record current pool statistics after checkin + if isinstance(pool, QueuePool): + pool_stats = self._get_pool_stats(pool) + MetricRegistry().db_pool_connections_checked_out_gauge.set(pool_stats["checked_out"], attributes=attrs) + MetricRegistry().db_pool_connections_available_gauge.set(pool_stats["available"], attributes=attrs) # Record checkin event attrs["event"] = "checkin" diff --git a/letta/settings.py b/letta/settings.py index 619fd466..1d200552 100644 --- a/letta/settings.py +++ b/letta/settings.py @@ -6,7 +6,7 @@ from typing import Optional from pydantic import AliasChoices, Field from pydantic_settings import BaseSettings, SettingsConfigDict -from letta.local_llm.constants import DEFAULT_WRAPPER_NAME +from letta.local_llm.constants import DEFAULT_WRAPPER_NAME, INNER_THOUGHTS_KWARG from letta.services.summarizer.enums import SummarizationMode @@ -83,6 +83,8 @@ class ModelSettings(BaseSettings): global_max_context_window_limit: int = 32000 + inner_thoughts_kwarg: str | None = Field(default=INNER_THOUGHTS_KWARG, description="Key used for passing in inner thoughts.") + # env_prefix='my_prefix_' # when we use /completions APIs (instead of /chat/completions), we need to specify a model wrapper @@ -150,9 +152,6 @@ class ModelSettings(BaseSettings): openllm_auth_type: Optional[str] = None openllm_api_key: Optional[str] = None - # disable openapi schema generation - disable_schema_generation: bool = False - env_cors_origins = os.getenv("ACCEPTABLE_ORIGINS") @@ -316,12 +315,16 @@ class Settings(BaseSettings): class TestSettings(Settings): model_config = SettingsConfigDict(env_prefix="letta_test_", extra="ignore") - letta_dir: Optional[Path] = Field(Path.home() / ".letta/test", env="LETTA_TEST_DIR") + letta_dir: Path | None = Field(Path.home() / ".letta/test", env="LETTA_TEST_DIR") class LogSettings(BaseSettings): model_config = SettingsConfigDict(env_prefix="letta_logging_", extra="ignore") - verbose_telemetry_logging: bool = False + debug: bool | None = Field(False, description="Enable debugging for logging") + json_logging: bool = Field(False, description="Enable json logging instead of text logging") + log_level: str | None = Field("WARNING", description="Logging level") + letta_log_path: Path | None = Field(Path.home() / ".letta" / "logs" / "Letta.log") + verbose_telemetry_logging: bool = Field(False) # singleton