Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
use a consistent warning prefix across codebase (#569)
Charles Packerdf999de4c15e
diff --git a/memgpt/agent.py b/memgpt/agent.pyindex 46b74f7e7..24bce1ef4 100644--- a/memgpt/agent.py+++ b/memgpt/agent.py@@ -18,6 +18,7 @@ from memgpt.constants import (CORE_MEMORY_HUMAN_CHAR_LIMIT,CORE_MEMORY_PERSONA_CHAR_LIMIT,LLM_MAX_TOKENS,+ CLI_WARNING_PREFIX,)from .errors import LLMErrorfrom .functions.functions import load_all_function_sets@@ -505,7 +506,7 @@ class Agent(object):heartbeat_request = function_args.pop("request_heartbeat", None)if not (isinstance(heartbeat_request, bool) or heartbeat_request is None):printd(- f"Warning: 'request_heartbeat' arg parsed was not a bool or None, type={type(heartbeat_request)}, value={heartbeat_request}"+ f"{CLI_WARNING_PREFIX}'request_heartbeat' arg parsed was not a bool or None, type={type(heartbeat_request)}, value={heartbeat_request}")heartbeat_request = None@@ -568,7 +569,7 @@ class Agent(object):input_message_sequence = self.messagesif len(input_message_sequence) > 1 and input_message_sequence[-1]["role"] != "user":- printd(f"WARNING: attempting to run ChatCompletion without user as the last message in the queue")+ printd(f"{CLI_WARNING_PREFIX}Attempting to run ChatCompletion without user as the last message in the queue")# Step 1: send the conversation and available functions to GPTif not skip_verify and (first_message or self.messages_total == self.messages_total_init):@@ -620,7 +621,7 @@ class Agent(object):# We can't do summarize logic properly if context_window is undefinedif self.config.context_window is None:# Fallback if for some reason context_window is missing, just set to the default- print(f"WARNING: could not find context_window in config, setting to default {LLM_MAX_TOKENS['DEFAULT']}")+ print(f"{CLI_WARNING_PREFIX}could not find context_window in config, setting to default {LLM_MAX_TOKENS['DEFAULT']}")print(f"{self.config}")self.config.context_window = (str(LLM_MAX_TOKENS[self.model])@@ -629,7 +630,7 @@ class Agent(object):)if current_total_tokens > MESSAGE_SUMMARY_WARNING_FRAC * int(self.config.context_window):printd(- f"WARNING: last response total_tokens ({current_total_tokens}) > {MESSAGE_SUMMARY_WARNING_FRAC * int(self.config.context_window)}"+ f"{CLI_WARNING_PREFIX}last response total_tokens ({current_total_tokens}) > {MESSAGE_SUMMARY_WARNING_FRAC * int(self.config.context_window)}")# Only deliver the alert if we haven't already (this period)if not self.agent_alerted_about_memory_pressure:@@ -712,7 +713,7 @@ class Agent(object):# We can't do summarize logic properly if context_window is undefinedif self.config.context_window is None:# Fallback if for some reason context_window is missing, just set to the default- print(f"WARNING: could not find context_window in config, setting to default {LLM_MAX_TOKENS['DEFAULT']}")+ print(f"{CLI_WARNING_PREFIX}could not find context_window in config, setting to default {LLM_MAX_TOKENS['DEFAULT']}")print(f"{self.config}")self.config.context_window = (str(LLM_MAX_TOKENS[self.model])diff --git a/memgpt/autogen/interface.py b/memgpt/autogen/interface.pyindex af074f8b9..ebc2edf70 100644--- a/memgpt/autogen/interface.py+++ b/memgpt/autogen/interface.py@@ -3,6 +3,8 @@ import refrom colorama import Fore, Style, init+from memgpt.constants import CLI_WARNING_PREFIX+init(autoreset=True)@@ -104,7 +106,7 @@ class AutoGenInterface(object):try:msg_json = json.loads(msg)except:- print(f"Warning: failed to parse user message into json")+ print(f"{CLI_WARNING_PREFIX}failed to parse user message into json")message = f"{Fore.GREEN}{Style.BRIGHT}🧑 {Fore.GREEN}{msg}{Style.RESET_ALL}" if self.fancy else f"[user] {msg}"self.message_list.append(message)return@@ -175,7 +177,7 @@ class AutoGenInterface(object):print(e)message = msg_dictelse:- print(f"Warning: did not recognize function message")+ print(f"{CLI_WARNING_PREFIX}did not recognize function message")message = (f"{Fore.RED}{Style.BRIGHT}⚡ [function] {Fore.RED}{msg}{Style.RESET_ALL}" if self.fancy else f"[function] {msg}")@@ -194,7 +196,7 @@ class AutoGenInterface(object):f"{Fore.GREEN}{Style.BRIGHT}⚡ [function] {Fore.GREEN}{msg}{Style.RESET_ALL}" if self.fancy else f"[function] {msg}")except Exception:- print(f"Warning: did not recognize function message {type(msg)} {msg}")+ print(f"{CLI_WARNING_PREFIX}did not recognize function message {type(msg)} {msg}")message = f"{Fore.RED}{Style.BRIGHT}⚡ [function] {Fore.RED}{msg}{Style.RESET_ALL}" if self.fancy else f"[function] {msg}"if message:diff --git a/memgpt/cli/cli.py b/memgpt/cli/cli.pyindex 0a3bcebb3..71fea4584 100644--- a/memgpt/cli/cli.py+++ b/memgpt/cli/cli.py@@ -15,7 +15,7 @@ import memgpt.utils as utilsfrom memgpt.utils import printdfrom memgpt.persistence_manager import LocalStateManagerfrom memgpt.config import MemGPTConfig, AgentConfig-from memgpt.constants import MEMGPT_DIR+from memgpt.constants import MEMGPT_DIR, CLI_WARNING_PREFIXfrom memgpt.agent import Agentfrom memgpt.embeddings import embedding_model@@ -107,36 +107,39 @@ def run(# persistence_manager = LocalStateManager(agent_config).load() # TODO: implement load# TODO: load prior agent stateif persona and persona != agent_config.persona:- typer.secho(f"Warning: Overriding existing persona {agent_config.persona} with {persona}", fg=typer.colors.YELLOW)+ typer.secho(f"{CLI_WARNING_PREFIX}Overriding existing persona {agent_config.persona} with {persona}", fg=typer.colors.YELLOW)agent_config.persona = persona# raise ValueError(f"Cannot override {agent_config.name} existing persona {agent_config.persona} with {persona}")if human and human != agent_config.human:- typer.secho(f"Warning: Overriding existing human {agent_config.human} with {human}", fg=typer.colors.YELLOW)+ typer.secho(f"{CLI_WARNING_PREFIX}Overriding existing human {agent_config.human} with {human}", fg=typer.colors.YELLOW)agent_config.human = human# raise ValueError(f"Cannot override {agent_config.name} existing human {agent_config.human} with {human}")# Allow overriding model specifics (model, model wrapper, model endpoint IP + type, context_window)if model and model != agent_config.model:- typer.secho(f"Warning: Overriding existing model {agent_config.model} with {model}", fg=typer.colors.YELLOW)+ typer.secho(f"{CLI_WARNING_PREFIX}Overriding existing model {agent_config.model} with {model}", fg=typer.colors.YELLOW)agent_config.model = modelif context_window is not None and int(context_window) != agent_config.context_window:typer.secho(- f"Warning: Overriding existing context window {agent_config.context_window} with {context_window}", fg=typer.colors.YELLOW+ f"{CLI_WARNING_PREFIX}Overriding existing context window {agent_config.context_window} with {context_window}",+ fg=typer.colors.YELLOW,)agent_config.context_window = context_windowif model_wrapper and model_wrapper != agent_config.model_wrapper:typer.secho(- f"Warning: Overriding existing model wrapper {agent_config.model_wrapper} with {model_wrapper}", fg=typer.colors.YELLOW+ f"{CLI_WARNING_PREFIX}Overriding existing model wrapper {agent_config.model_wrapper} with {model_wrapper}",+ fg=typer.colors.YELLOW,)agent_config.model_wrapper = model_wrapperif model_endpoint and model_endpoint != agent_config.model_endpoint:typer.secho(- f"Warning: Overriding existing model endpoint {agent_config.model_endpoint} with {model_endpoint}", fg=typer.colors.YELLOW+ f"{CLI_WARNING_PREFIX}Overriding existing model endpoint {agent_config.model_endpoint} with {model_endpoint}",+ fg=typer.colors.YELLOW,)agent_config.model_endpoint = model_endpointif model_endpoint_type and model_endpoint_type != agent_config.model_endpoint_type:typer.secho(- f"Warning: Overriding existing model endpoint type {agent_config.model_endpoint_type} with {model_endpoint_type}",+ f"{CLI_WARNING_PREFIX}Overriding existing model endpoint type {agent_config.model_endpoint_type} with {model_endpoint_type}",fg=typer.colors.YELLOW,)agent_config.model_endpoint_type = model_endpoint_typediff --git a/memgpt/constants.py b/memgpt/constants.pyindex dcbd009f2..a722a64c7 100644--- a/memgpt/constants.py+++ b/memgpt/constants.py@@ -17,6 +17,8 @@ STARTUP_QUOTES = []INITIAL_BOOT_MESSAGE_SEND_MESSAGE_FIRST_MSG = STARTUP_QUOTES[2]+CLI_WARNING_PREFIX = "Warning: "+# Constants to do with summarization / conversation length window# The max amount of tokens supported by the underlying model (eg 8k for gpt-4 and Mistral 7B)LLM_MAX_TOKENS = {diff --git a/memgpt/functions/functions.py b/memgpt/functions/functions.pyindex 449f40f43..e5296f7a2 100644--- a/memgpt/functions/functions.py+++ b/memgpt/functions/functions.py@@ -5,7 +5,7 @@ import sysfrom memgpt.functions.schema_generator import generate_schema-from memgpt.constants import MEMGPT_DIR+from memgpt.constants import MEMGPT_DIR, CLI_WARNING_PREFIXsys.path.append(os.path.join(MEMGPT_DIR, "functions"))diff --git a/memgpt/interface.py b/memgpt/interface.pyindex 1639455f2..c8da15bb4 100644--- a/memgpt/interface.py+++ b/memgpt/interface.py@@ -5,6 +5,7 @@ import refrom colorama import Fore, Style, initfrom memgpt.utils import printd+from memgpt.constants import CLI_WARNING_PREFIXinit(autoreset=True)@@ -108,7 +109,7 @@ class CLIInterface(AgentInterface):try:msg_json = json.loads(msg)except:- printd(f"Warning: failed to parse user message into json")+ printd(f"{CLI_WARNING_PREFIX}failed to parse user message into json")printd_user_message("🧑", msg)returnif msg_json["type"] == "user_message":@@ -186,7 +187,7 @@ class CLIInterface(AgentInterface):printd(msg_dict)passelse:- printd(f"Warning: did not recognize function message")+ printd(f"{CLI_WARNING_PREFIX}did not recognize function message")printd_function_message("", msg)else:try:@@ -196,7 +197,7 @@ class CLIInterface(AgentInterface):else:printd_function_message("", str(msg), color=Fore.RED)except Exception:- print(f"Warning: did not recognize function message {type(msg)} {msg}")+ print(f"{CLI_WARNING_PREFIX}did not recognize function message {type(msg)} {msg}")printd_function_message("", msg)@staticmethoddiff --git a/memgpt/local_llm/chat_completion_proxy.py b/memgpt/local_llm/chat_completion_proxy.pyindex cae4d11fd..b4fd794fe 100644--- a/memgpt/local_llm/chat_completion_proxy.py+++ b/memgpt/local_llm/chat_completion_proxy.py@@ -18,6 +18,7 @@ from memgpt.local_llm.constants import DEFAULT_WRAPPERfrom memgpt.local_llm.utils import get_available_wrappersfrom memgpt.prompts.gpt_summarize import SYSTEM as SUMMARIZE_SYSTEM_MESSAGEfrom memgpt.errors import LocalLLMConnectionError, LocalLLMError+from memgpt.constants import CLI_WARNING_PREFIXDEBUG = False# DEBUG = True@@ -54,7 +55,7 @@ def get_chat_completion(# Warn the user that we're using the fallbackif not has_shown_warning:print(- f"Warning: no wrapper specified for local LLM, using the default wrapper (you can remove this warning by specifying the wrapper with --wrapper)"+ f"{CLI_WARNING_PREFIX}no wrapper specified for local LLM, using the default wrapper (you can remove this warning by specifying the wrapper with --wrapper)")has_shown_warning = Trueif endpoint_type in ["koboldcpp", "llamacpp", "webui"]:@@ -72,7 +73,7 @@ def get_chat_completion(grammar_name = "json_func_calls_with_inner_thoughts"if grammar_name is not None and endpoint_type not in ["koboldcpp", "llamacpp", "webui"]:- print(f"Warning: grammars are currently only supported when using llama.cpp as the MemGPT local LLM backend")+ print(f"{CLI_WARNING_PREFIX}grammars are currently only supported when using llama.cpp as the MemGPT local LLM backend")# First step: turn the message sequence into a prompt that the model expectstry:diff --git a/memgpt/openai_tools.py b/memgpt/openai_tools.pyindex 257a2f179..adc2b23fd 100644--- a/memgpt/openai_tools.py+++ b/memgpt/openai_tools.py@@ -9,6 +9,7 @@ import urllibfrom box import Boxfrom memgpt.local_llm.chat_completion_proxy import get_chat_completion+from memgpt.constants import CLI_WARNING_PREFIXdef is_context_overflow_error(exception):@@ -294,7 +295,10 @@ def retry_with_exponential_backoff(delay *= exponential_base * (1 + jitter * random.random())# Sleep for the delay- printd(f"Got a rate limit error ('{http_err}') on LLM backend request, waiting {int(delay)}s then retrying...")+ # printd(f"Got a rate limit error ('{http_err}') on LLM backend request, waiting {int(delay)}s then retrying...")+ print(+ f"{CLI_WARNING_PREFIX}Got a rate limit error ('{http_err}') on LLM backend request, waiting {int(delay)}s then retrying..."+ )time.sleep(delay)else:# For other HTTP errors, re-raise the exception