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: increase the func return char limit (#714)

Charles Packer42e2a301ebe9
diff --git a/memgpt/agent.py b/memgpt/agent.py
index c150eaf6e..2af63094a 100644
--- a/memgpt/agent.py
+++ b/memgpt/agent.py
@@ -519,7 +519,14 @@ class Agent(object):
try:
function_args["self"] = self # need to attach self to arg since it's dynamically linked
function_response = function_to_call(**function_args)
- function_response_string = validate_function_response(function_response)
+ if function_name in ["conversation_search", "conversation_search_date", "archival_memory_search"]:
+ # with certain functions we rely on the paging mechanism to handle overflow
+ truncate = False
+ else:
+ # but by default, we add a truncation safeguard to prevent bad functions from
+ # overflow the agent context window
+ truncate = True
+ function_response_string = validate_function_response(function_response, truncate=truncate)
function_args.pop("self", None)
function_response = package_function_response(True, function_response_string)
function_failed = False
diff --git a/memgpt/cli/cli.py b/memgpt/cli/cli.py
index cf482c993..c035c802f 100644
--- a/memgpt/cli/cli.py
+++ b/memgpt/cli/cli.py
@@ -491,8 +491,9 @@ def attach(
agent_config = AgentConfig.load(agent)
# get storage connectors
- source_storage = StorageConnector.get_storage_connector(name=data_source)
- dest_storage = StorageConnector.get_storage_connector(agent_config=agent_config)
+ with suppress_stdout():
+ source_storage = StorageConnector.get_storage_connector(name=data_source)
+ dest_storage = StorageConnector.get_storage_connector(agent_config=agent_config)
size = source_storage.size()
typer.secho(f"Ingesting {size} passages into {agent_config.name}", fg=typer.colors.GREEN)
@@ -513,7 +514,7 @@ def attach(
fg=typer.colors.GREEN,
)
except KeyboardInterrupt:
- typer.secho(" Operation interrupted by KeyboardInterrupt.", fg=typer.colors.YELLOW)
+ typer.secho("Operation interrupted by KeyboardInterrupt.", fg=typer.colors.YELLOW)
def version():
diff --git a/memgpt/constants.py b/memgpt/constants.py
index 6a66710b1..9710e8d73 100644
--- a/memgpt/constants.py
+++ b/memgpt/constants.py
@@ -67,7 +67,7 @@ CORE_MEMORY_PERSONA_CHAR_LIMIT = 2000
CORE_MEMORY_HUMAN_CHAR_LIMIT = 2000
# Function return limits
-FUNCTION_RETURN_CHAR_LIMIT = 2000
+FUNCTION_RETURN_CHAR_LIMIT = 3000 # ~300 words
MAX_PAUSE_HEARTBEATS = 360 # in min
diff --git a/memgpt/main.py b/memgpt/main.py
index d456bf925..5a228eb90 100644
--- a/memgpt/main.py
+++ b/memgpt/main.py
@@ -22,7 +22,7 @@ import memgpt.agent as agent
import memgpt.system as system
import memgpt.constants as constants
import memgpt.errors as errors
-from memgpt.cli.cli import run, attach, version, server, open_folder, quickstart
+from memgpt.cli.cli import run, attach, version, server, open_folder, quickstart, suppress_stdout
from memgpt.cli.cli_config import configure, list, add
from memgpt.cli.cli_load import app as load_app
from memgpt.connectors.storage import StorageConnector
@@ -119,9 +119,10 @@ def run_agent_loop(memgpt_agent, first, no_verify=False, cfg=None, strip_ui=Fals
# reload agent with new data source
# TODO: maybe make this less ugly...
- memgpt_agent.persistence_manager.archival_memory.storage = StorageConnector.get_storage_connector(
- agent_config=memgpt_agent.config
- )
+ with suppress_stdout():
+ memgpt_agent.persistence_manager.archival_memory.storage = StorageConnector.get_storage_connector(
+ agent_config=memgpt_agent.config
+ )
continue
elif user_input.lower() == "/dump" or user_input.lower().startswith("/dump "):
diff --git a/memgpt/utils.py b/memgpt/utils.py
index 8e864a423..0b36e620b 100644
--- a/memgpt/utils.py
+++ b/memgpt/utils.py
@@ -150,7 +150,7 @@ def parse_json(string):
raise e
-def validate_function_response(function_response_string: any, strict: bool = False) -> str:
+def validate_function_response(function_response_string: any, strict: bool = False, truncate: bool = True) -> str:
"""Check to make sure that a function used by MemGPT returned a valid response
Responses need to be strings (or None) that fall under a certain text count limit.
@@ -187,7 +187,7 @@ def validate_function_response(function_response_string: any, strict: bool = Fal
# Now check the length and make sure it doesn't go over the limit
# TODO we should change this to a max token limit that's variable based on tokens remaining (or context-window)
- if len(function_response_string) > FUNCTION_RETURN_CHAR_LIMIT:
+ if truncate and len(function_response_string) > FUNCTION_RETURN_CHAR_LIMIT:
print(
f"{CLI_WARNING_PREFIX}function return was over limit ({len(function_response_string)} > {FUNCTION_RETURN_CHAR_LIMIT}) and was truncated"
)