Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
chore: decrease pool logging
Andy Li235a56ff0d09
diff --git a/letta/local_llm/constants.py b/letta/local_llm/constants.pyindex 441bb4ae5..83681fdef 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 = ChatMLInnerMonologueWrapperDEFAULT_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.pyindex f721e557f..961c32d42 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 manuallycleaned_json_string = re.sub(r"[^\x00-\x7F]+", "", json_string) # Remove non-ASCII charactersfunction_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.pyindex 3d04f25fd..2208ac8fd 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 eventattrs["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 eventattrs["event"] = "checkin"diff --git a/letta/settings.py b/letta/settings.pyindex 619fd466d..1d2005524 100644--- a/letta/settings.py+++ b/letta/settings.py@@ -6,7 +6,7 @@ from typing import Optionalfrom pydantic import AliasChoices, Fieldfrom 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_KWARGfrom 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] = Noneopenllm_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