Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: add metadata to GET tools route (#1117)
Charles Packerdeb9b292cb57
diff --git a/memgpt/functions/functions.py b/memgpt/functions/functions.pyindex 03a6bdff8..1dec248de 100644--- a/memgpt/functions/functions.py+++ b/memgpt/functions/functions.py@@ -2,6 +2,7 @@ import importlibimport inspectimport osimport sys+from types import ModuleTypefrom memgpt.functions.schema_generator import generate_schema@@ -12,7 +13,7 @@ USER_FUNCTIONS_DIR = os.path.join(MEMGPT_DIR, "functions")sys.path.append(USER_FUNCTIONS_DIR)-def load_function_set(module):+def load_function_set(module: ModuleType) -> dict:"""Load the functions and generate schema for them, given a module object"""function_dict = {}@@ -36,7 +37,7 @@ def load_function_set(module):return function_dict-def load_all_function_sets(merge=True):+def load_all_function_sets(merge: bool = True) -> dict:# functions/examples/*.pyscripts_dir = os.path.dirname(os.path.abspath(__file__)) # Get the directory of the current scriptfunction_sets_dir = os.path.join(scripts_dir, "function_sets") # Path to the function_sets directory@@ -59,6 +60,7 @@ def load_all_function_sets(merge=True):schemas_and_functions = {}for dir_path, module_files in [(function_sets_dir, example_module_files), (USER_FUNCTIONS_DIR, user_module_files)]:for file in module_files:+ tags = []module_name = file[:-3] # Remove '.py' from filenameif dir_path == USER_FUNCTIONS_DIR:# For user scripts, adjust the module name appropriately@@ -86,6 +88,7 @@ def load_all_function_sets(merge=True):else:# For built-in scripts, use the existing methodfull_module_name = f"memgpt.functions.function_sets.{module_name}"+ tags.append(f"memgpt-{module_name}")try:module = importlib.import_module(full_module_name)except Exception as e:@@ -96,6 +99,10 @@ def load_all_function_sets(merge=True):try:# Load the function setfunction_set = load_function_set(module)+ # Add the metadata tags+ for k, v in function_set.items():+ print(function_set)+ v["tags"] = tagsschemas_and_functions[module_name] = function_setexcept ValueError as e:print(f"Error loading function set '{module_name}': {e}")diff --git a/memgpt/metadata.py b/memgpt/metadata.pyindex 0bc1cf615..e6d2fce4a 100644--- a/memgpt/metadata.py+++ b/memgpt/metadata.py@@ -528,6 +528,7 @@ class MetadataStore:ToolModel(name=k,json_schema=v["json_schema"],+ tags=v["tags"],source_type="python",source_code=python_inspect.getsource(v["python_function"]),)diff --git a/memgpt/models/pydantic_models.py b/memgpt/models/pydantic_models.pyindex 3ee7d7717..c5f06987f 100644--- a/memgpt/models/pydantic_models.py+++ b/memgpt/models/pydantic_models.py@@ -43,6 +43,7 @@ class ToolModel(BaseModel):# TODO move into databasename: str = Field(..., description="The name of the function.")json_schema: dict = Field(..., description="The JSON schema of the function.")+ tags: List[str] = Field(..., description="Metadata tags.")source_type: Optional[Literal["python"]] = Field(None, description="The type of the source code.")source_code: Optional[str] = Field(..., description="The source code of the function.")diff --git a/memgpt/server/rest_api/tools/index.py b/memgpt/server/rest_api/tools/index.pyindex 8137ae61a..8d08e6a31 100644--- a/memgpt/server/rest_api/tools/index.py+++ b/memgpt/server/rest_api/tools/index.py@@ -21,7 +21,7 @@ def setup_tools_index_router(server: SyncServer, interface: QueuingInterface, paget_current_user_with_server = partial(partial(get_current_user, server), password)@router.get("/tools", tags=["tools"], response_model=ListToolsResponse)- async def list_tools(+ async def list_all_tools(user_id: uuid.UUID = Depends(get_current_user_with_server),):"""