Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: add `Annotated` to CLI options (#906)
Sarah Wooders35b48c5fc063
diff --git a/memgpt/benchmark/benchmark.py b/memgpt/benchmark/benchmark.pyindex 161bc4d41..0a82b1d49 100644--- a/memgpt/benchmark/benchmark.py+++ b/memgpt/benchmark/benchmark.py@@ -3,6 +3,7 @@import uuidimport typerimport time+from typing import Annotated, Optionalfrom memgpt import MemGPTfrom memgpt.config import MemGPTConfig@@ -38,8 +39,8 @@ def send_message(message: str, agent_id, turn: int, fn_type: str, print_msg: boo@app.command()def bench(- print_messages: bool = typer.Option(False, "--messages", help="Print functions calls and messages from the agent."),- n_tries: int = typer.Option(TRIES, "--n-tries", help="Number of benchmark tries to perform for each function."),+ print_messages: Annotated[bool, typer.Option("--messages", help="Print functions calls and messages from the agent.")] = False,+ n_tries: Annotated[int, typer.Option("--n-tries", help="Number of benchmark tries to perform for each function.")] = TRIES,):client = MemGPT()print(f"\nDepending on your hardware, this may take up to 30 minutes. This will also create {n_tries * len(PROMPTS)} new agents.\n")diff --git a/memgpt/cli/cli.py b/memgpt/cli/cli.pyindex c3b8e1c8e..83cceaebe 100644--- a/memgpt/cli/cli.py+++ b/memgpt/cli/cli.py@@ -1,4 +1,3 @@-import typerimport uuidimport jsonimport requests@@ -6,12 +5,14 @@ import sysimport shutilimport ioimport logging-import questionaryfrom pathlib import Pathimport osimport subprocessfrom enum import Enum+from typing import Annotated, Optional+import typer+import questionaryfrom llama_index import set_global_service_contextfrom llama_index import ServiceContext@@ -119,9 +120,9 @@ def set_config_with_dict(new_config: dict) -> bool:def quickstart(- backend: QuickstartChoice = typer.Option("memgpt", help="Quickstart setup backend"),- latest: bool = typer.Option(False, "--latest", help="Use --latest to pull the latest config from online"),- debug: bool = typer.Option(False, "--debug", help="Use --debug to enable debugging output"),+ backend: Annotated[QuickstartChoice, typer.Option(help="Quickstart setup backend")] = "memgpt",+ latest: Annotated[bool, typer.Option(help="Use --latest to pull the latest config from online")] = False,+ debug: Annotated[bool, typer.Option(help="Use --debug to enable debugging output")] = False,terminal: bool = True,):"""Set the base config file with a single command"""@@ -269,10 +270,10 @@ def create_default_user_or_exit(config: MemGPTConfig, ms: MetadataStore):def server(- type: ServerChoice = typer.Option("rest", help="Server to run"),- port: int = typer.Option(None, help="Port to run the server on"),- host: str = typer.Option(None, help="Host to run the server on (default to localhost)"),- debug: bool = typer.Option(True, help="Turn debugging output on"),+ type: Annotated[ServerChoice, typer.Option(help="Server to run")] = "rest",+ port: Annotated[Optional[int], typer.Option(help="Port to run the server on")] = None,+ host: Annotated[Optional[str], typer.Option(help="Host to run the server on (default to localhost)")] = None,+ debug: Annotated[bool, typer.Option(help="Turn debugging output on")] = True,):"""Launch a MemGPT server process"""@@ -341,22 +342,24 @@ def server(def run(- persona: str = typer.Option(None, help="Specify persona"),- agent: str = typer.Option(None, help="Specify agent save file"),- human: str = typer.Option(None, help="Specify human"),- preset: str = typer.Option(None, help="Specify preset"),+ persona: Annotated[Optional[str], typer.Option(help="Specify persona")] = None,+ agent: Annotated[Optional[str], typer.Option(help="Specify agent save file")] = None,+ human: Annotated[Optional[str], typer.Option(help="Specify human")] = None,+ preset: Annotated[Optional[str], typer.Option(help="Specify preset")] = None,# model flags- model: str = typer.Option(None, help="Specify the LLM model"),- model_wrapper: str = typer.Option(None, help="Specify the LLM model wrapper"),- model_endpoint: str = typer.Option(None, help="Specify the LLM model endpoint"),- model_endpoint_type: str = typer.Option(None, help="Specify the LLM model endpoint type"),- context_window: int = typer.Option(None, help="The context window of the LLM you are using (e.g. 8k for most Mistral 7B variants)"),+ model: Annotated[Optional[str], typer.Option(help="Specify the LLM model")] = None,+ model_wrapper: Annotated[Optional[str], typer.Option(help="Specify the LLM model wrapper")] = None,+ model_endpoint: Annotated[Optional[str], typer.Option(help="Specify the LLM model endpoint")] = None,+ model_endpoint_type: Annotated[Optional[str], typer.Option(help="Specify the LLM model endpoint type")] = None,+ context_window: Annotated[+ Optional[int], typer.Option(help="The context window of the LLM you are using (e.g. 8k for most Mistral 7B variants)")+ ] = None,# other- first: bool = typer.Option(False, "--first", help="Use --first to send the first message in the sequence"),- strip_ui: bool = typer.Option(False, help="Remove all the bells and whistles in CLI output (helpful for testing)"),- debug: bool = typer.Option(False, "--debug", help="Use --debug to enable debugging output"),- no_verify: bool = typer.Option(False, help="Bypass message verification"),- yes: bool = typer.Option(False, "-y", help="Skip confirmation prompt and use defaults"),+ first: Annotated[bool, typer.Option(help="Use --first to send the first message in the sequence")] = False,+ strip_ui: Annotated[bool, typer.Option(help="Remove all the bells and whistles in CLI output (helpful for testing)")] = False,+ debug: Annotated[bool, typer.Option(help="Use --debug to enable debugging output")] = False,+ no_verify: Annotated[bool, typer.Option(help="Bypass message verification")] = False,+ yes: Annotated[bool, typer.Option("-y", help="Skip confirmation prompt and use defaults")] = False,):"""Start chatting with an MemGPT agent@@ -648,8 +651,8 @@ def run(def delete_agent(- agent_name: str = typer.Option(help="Specify agent to delete"),- user_id: str = None,+ agent_name: Annotated[str, typer.Option(help="Specify agent to delete")],+ user_id: Annotated[Optional[str], typer.Option(help="User ID to associate with the agent.")] = None,):"""Delete an agent from the database"""# use client ID is no user_id provided@@ -686,8 +689,8 @@ def delete_agent(def attach(- agent_name: str = typer.Option(help="Specify agent to attach data to"),- data_source: str = typer.Option(help="Data source to attach to avent"),+ agent_name: Annotated[str, typer.Option(help="Specify agent to attach data to")],+ data_source: Annotated[str, typer.Option(help="Data source to attach to avent")],user_id: uuid.UUID = None,):# use client ID is no user_id provideddiff --git a/memgpt/cli/cli_config.py b/memgpt/cli/cli_config.pyindex b68e10c9b..4867264d9 100644--- a/memgpt/cli/cli_config.py+++ b/memgpt/cli/cli_config.py@@ -6,7 +6,7 @@ from prettytable import PrettyTableimport typerimport osimport shutil-from typing import Annotated+from typing import Annotated, Optionalfrom enum import Enum# from global logging configuration@@ -742,9 +742,9 @@ def list(arg: Annotated[ListChoice, typer.Argument]):@app.command()def add(option: str, # [human, persona]- name: str = typer.Option(help="Name of human/persona"),- text: str = typer.Option(None, help="Text of human/persona"),- filename: str = typer.Option(None, "-f", help="Specify filename"),+ name: Annotated[str, typer.Option(help="Name of human/persona")],+ text: Annotated[Optional[str], typer.Option(help="Text of human/persona")] = None,+ filename: Annotated[Optional[str], typer.Option("-f", help="Specify filename")] = None,):"""Add a person/human"""diff --git a/memgpt/cli/cli_load.py b/memgpt/cli/cli_load.pyindex 50d4df829..23c3f23ba 100644--- a/memgpt/cli/cli_load.py+++ b/memgpt/cli/cli_load.py@@ -8,7 +8,7 @@ memgpt load <data-connector-type> --name <dataset-name> [ADDITIONAL ARGS]"""-from typing import List, Optional+from typing import List, Optional, Annotatedfrom tqdm import tqdmimport numpy as npimport typer@@ -172,9 +172,9 @@ def store_docs(name, docs, user_id=None, show_progress=True):@app.command("index")def load_index(- name: str = typer.Option(help="Name of dataset to load."),- dir: str = typer.Option(help="Path to directory containing index."),- user_id: uuid.UUID = None,+ name: Annotated[str, typer.Option(help="Name of dataset to load.")],+ dir: Annotated[Optional[str], typer.Option(help="Path to directory containing index.")] = None,+ user_id: Annotated[Optional[uuid.UUID], typer.Option(help="User ID to associate with dataset.")] = None,):"""Load a LlamaIndex saved VectorIndex into MemGPT"""try:@@ -221,12 +221,12 @@ default_extensions = ".txt,.md,.pdf"@app.command("directory")def load_directory(- name: str = typer.Option(help="Name of dataset to load."),- input_dir: Optional[str] = typer.Option(None, help="Path to directory containing dataset."),- input_files: Optional[List[str]] = typer.Option(None, help="List of paths to files containing dataset."),- recursive: bool = typer.Option(False, help="Recursively search for files in directory."),- extensions: str = typer.Option(default_extensions, help="Comma separated list of file extensions to load"),- user_id: Optional[str] = typer.Option(None, help="User ID to associate with dataset."),+ name: Annotated[str, typer.Option(help="Name of dataset to load.")],+ input_dir: Annotated[Optional[str], typer.Option(help="Path to directory containing dataset.")] = None,+ input_files: Annotated[List[str], typer.Option(help="List of paths to files containing dataset.")] = [],+ recursive: Annotated[bool, typer.Option(help="Recursively search for files in directory.")] = False,+ extensions: Annotated[str, typer.Option(help="Comma separated list of file extensions to load")] = default_extensions,+ user_id: Annotated[Optional[uuid.UUID], typer.Option(help="User ID to associate with dataset.")] = None,):try:from llama_index import SimpleDirectoryReader@@ -255,8 +255,8 @@ def load_directory(@app.command("webpage")def load_webpage(- name: str = typer.Option(help="Name of dataset to load."),- urls: Optional[List[str]] = typer.Option(None, help="List of urls to load."),+ name: Annotated[str, typer.Option(help="Name of dataset to load.")],+ urls: Annotated[List[str], typer.Option(help="List of urls to load.")],):try:from llama_index import SimpleWebPageReader@@ -270,15 +270,15 @@ def load_webpage(@app.command("database")def load_database(- name: str = typer.Option(help="Name of dataset to load."),- query: str = typer.Option(help="Database query."),- dump_path: str = typer.Option(None, help="Path to dump file."),- scheme: str = typer.Option(None, help="Database scheme."),- host: str = typer.Option(None, help="Database host."),- port: int = typer.Option(None, help="Database port."),- user: str = typer.Option(None, help="Database user."),- password: str = typer.Option(None, help="Database password."),- dbname: str = typer.Option(None, help="Database name."),+ name: Annotated[str, typer.Option(help="Name of dataset to load.")],+ query: Annotated[str, typer.Option(help="Database query.")],+ dump_path: Annotated[Optional[str], typer.Option(help="Path to dump file.")] = None,+ scheme: Annotated[Optional[str], typer.Option(help="Database scheme.")] = None,+ host: Annotated[Optional[str], typer.Option(help="Database host.")] = None,+ port: Annotated[Optional[int], typer.Option(help="Database port.")] = None,+ user: Annotated[Optional[str], typer.Option(help="Database user.")] = None,+ password: Annotated[Optional[str], typer.Option(help="Database password.")] = None,+ dbname: Annotated[Optional[str], typer.Option(help="Database name.")] = None,):try:from llama_index.readers.database import DatabaseReader@@ -319,12 +319,12 @@ def load_database(@app.command("vector-database")def load_vector_database(- name: str = typer.Option(help="Name of dataset to load."),- uri: str = typer.Option(help="Database URI."),- table_name: str = typer.Option(help="Name of table containing data."),- text_column: str = typer.Option(help="Name of column containing text."),- embedding_column: str = typer.Option(help="Name of column containing embedding."),- user_id: uuid.UUID = None,+ name: Annotated[str, typer.Option(help="Name of dataset to load.")],+ uri: Annotated[str, typer.Option(help="Database URI.")],+ table_name: Annotated[str, typer.Option(help="Name of table containing data.")],+ text_column: Annotated[str, typer.Option(help="Name of column containing text.")],+ embedding_column: Annotated[str, typer.Option(help="Name of column containing embedding.")],+ user_id: Annotated[Optional[uuid.UUID], typer.Option(help="User ID to associate with dataset.")] = None,):"""Load pre-computed embeddings into MemGPT from a database."""diff --git a/tests/test_load_archival.py b/tests/test_load_archival.pyindex 552873358..43eb5137d 100644--- a/tests/test_load_archival.py+++ b/tests/test_load_archival.py@@ -126,7 +126,8 @@ def test_load_directory(metadata_storage_connector, passage_storage_connector, c# test: load directoryprint("Loading directory")- load_directory(name=name, input_dir=None, input_files=[cache_dir], recursive=False, user_id=user_id) # cache_dir,+ # load_directory(name=name, input_dir=None, input_files=[cache_dir], recursive=False, user_id=user_id) # cache_dir,+ load_directory(name=name, input_files=[cache_dir], recursive=False, user_id=user_id) # cache_dir,# test to see if contained in storageprint("Querying table...")