Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix: cleanup CLI tool prints (#2130)

Charles Packerb01f0cc1b0bb
diff --git a/letta/local_llm/utils.py b/letta/local_llm/utils.py
index 5b46c0d24..b0529c358 100644
--- a/letta/local_llm/utils.py
+++ b/letta/local_llm/utils.py
@@ -88,7 +88,9 @@ def num_tokens_from_functions(functions: List[dict], model: str = "gpt-4"):
try:
encoding = tiktoken.encoding_for_model(model)
except KeyError:
- warnings.warn("Warning: model not found. Using cl100k_base encoding.")
+ from letta.utils import printd
+
+ printd(f"Warning: model not found. Using cl100k_base encoding.")
encoding = tiktoken.get_encoding("cl100k_base")
num_tokens = 0
@@ -215,8 +217,10 @@ def num_tokens_from_messages(messages: List[dict], model: str = "gpt-4") -> int:
# print("Warning: gpt-4 may update over time. Returning num tokens assuming gpt-4-0613.")
return num_tokens_from_messages(messages, model="gpt-4-0613")
else:
- warnings.warn(
- f"""num_tokens_from_messages() is not implemented for model {model}. See https://github.com/openai/openai-python/blob/main/chatml.md for information on how messages are converted to tokens."""
+ from letta.utils import printd
+
+ printd(
+ f"num_tokens_from_messages() is not implemented for model {model}. See https://github.com/openai/openai-python/blob/main/chatml.md for information on how messages are converted to tokens."
)
return num_tokens_from_messages(messages, model="gpt-4-0613")
# raise NotImplementedError(
diff --git a/letta/metadata.py b/letta/metadata.py
index 3fdfa4038..475ad4a14 100644
--- a/letta/metadata.py
+++ b/letta/metadata.py
@@ -2,7 +2,6 @@
import os
import secrets
-import warnings
from typing import List, Optional, Union
from sqlalchemy import JSON, Column, DateTime, Index, String, TypeDecorator
@@ -359,8 +358,8 @@ class MetadataStore:
# warnings.warn(f"Agent {agent.id} has no _internal_memory field")
if "tags" in fields:
del fields["tags"]
- else:
- warnings.warn(f"Agent {agent.id} has no tags field")
+ # else:
+ # warnings.warn(f"Agent {agent.id} has no tags field")
session.add(AgentModel(**fields))
session.commit()
@@ -376,8 +375,8 @@ class MetadataStore:
# warnings.warn(f"Agent {agent.id} has no _internal_memory field")
if "tags" in fields:
del fields["tags"]
- else:
- warnings.warn(f"Agent {agent.id} has no tags field")
+ # else:
+ # warnings.warn(f"Agent {agent.id} has no tags field")
session.query(AgentModel).filter(AgentModel.id == agent.id).update(fields)
session.commit()
diff --git a/letta/services/tool_execution_sandbox.py b/letta/services/tool_execution_sandbox.py
index 2e7950fcd..97a4903c4 100644
--- a/letta/services/tool_execution_sandbox.py
+++ b/letta/services/tool_execution_sandbox.py
@@ -59,19 +59,19 @@ class ToolExecutionSandbox:
Tuple[Any, Optional[AgentState]]: Tuple containing (tool_result, agent_state)
"""
if tool_settings.e2b_api_key:
- logger.info(f"Using e2b sandbox to execute {self.tool_name}")
+ logger.debug(f"Using e2b sandbox to execute {self.tool_name}")
code = self.generate_execution_script(agent_state=agent_state)
result = self.run_e2b_sandbox(code=code)
else:
- logger.info(f"Using local sandbox to execute {self.tool_name}")
+ logger.debug(f"Using local sandbox to execute {self.tool_name}")
code = self.generate_execution_script(agent_state=agent_state)
result = self.run_local_dir_sandbox(code=code)
# Log out any stdout from the tool run
- logger.info(f"Executed tool '{self.tool_name}', logging stdout from tool run: \n")
+ logger.debug(f"Executed tool '{self.tool_name}', logging stdout from tool run: \n")
for log_line in result.stdout:
- logger.info(f"{log_line}")
- logger.info(f"Ending stdout log from tool run.")
+ logger.debug(f"{log_line}")
+ logger.debug(f"Ending stdout log from tool run.")
# Return result
return result