diff --git a/dev-compose.yaml b/dev-compose.yaml index 81d08478..c1127aa0 100644 --- a/dev-compose.yaml +++ b/dev-compose.yaml @@ -14,7 +14,7 @@ services: - ./.persist/pgdata-test:/var/lib/postgresql/data - ./init.sql:/docker-entrypoint-initdb.d/init.sql ports: - - "5432:5432" + - '5432:5432' letta_server: image: letta/letta:latest hostname: letta @@ -25,8 +25,8 @@ services: depends_on: - letta_db ports: - - "8083:8083" - - "8283:8283" + - '8083:8083' + - '8283:8283' environment: - LETTA_PG_DB=${LETTA_PG_DB:-letta} - LETTA_PG_USER=${LETTA_PG_USER:-letta} diff --git a/letta/services/tool_manager.py b/letta/services/tool_manager.py index f243580b..0b46d2e9 100644 --- a/letta/services/tool_manager.py +++ b/letta/services/tool_manager.py @@ -944,13 +944,28 @@ class ToolManager: # Track if we need to check name uniqueness (check is done inside session with lock) needs_name_conflict_check = new_name != current_tool.name - # NOTE: EXTREMELEY HACKY, we need to stop making assumptions about the source_code - if "source_code" in update_data and f"def {new_name}" not in update_data.get("source_code", ""): - raise LettaToolNameSchemaMismatchError( - tool_name=new_name, - json_schema_name=new_schema.get("name") if new_schema else None, - source_code=update_data.get("source_code"), - ) + # Definitive checker for source code type + if "source_code" in update_data: + source_code = update_data.get("source_code", "") + source_type = update_data.get("source_type", current_tool.source_type) + + # Check for function name based on source type + if source_type == "typescript": + # TypeScript: check for "function name" or "export function name" + if f"function {new_name}" not in source_code: + raise LettaToolNameSchemaMismatchError( + tool_name=new_name, + json_schema_name=new_schema.get("name") if new_schema else None, + source_code=source_code, + ) + else: + # Python: check for "def name" + if f"def {new_name}" not in source_code: + raise LettaToolNameSchemaMismatchError( + tool_name=new_name, + json_schema_name=new_schema.get("name") if new_schema else None, + source_code=source_code, + ) # Create a preview of the updated tool by merging current tool with updates # This allows us to compute the hash before the database session