From eb9a90ee42b4f560b20d5396238b85e9679bba7e Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 8 May 2026 15:34:13 +0800 Subject: [PATCH] fix: add env.get_module_dbname() for dynamic database lookup --- harnessed_agent/core.py | 63 ++++++++++++++++++++++++++++----- harnessed_agent/orchestrator.py | 35 +++++++++++++++--- 2 files changed, 84 insertions(+), 14 deletions(-) diff --git a/harnessed_agent/core.py b/harnessed_agent/core.py index 94c86bb..cb0a59f 100644 --- a/harnessed_agent/core.py +++ b/harnessed_agent/core.py @@ -361,12 +361,17 @@ class HermesAgent: selected_memories = [] try: + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: # High priority memories ns = {'user_id': user_id, 'priority__gte': self.config.high_priority_threshold, 'sort': 'priority desc,last_accessed desc'} hp_rows = await sor.R('hermes_memory', ns) @@ -418,12 +423,17 @@ class HermesAgent: async def _update_memory_access_stats(self, user_id: str, memory_id: str): """Update memory access statistics""" try: + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: memories = await sor.R('hermes_memory', {'id': memory_id, 'user_id': user_id}) if memories: current_count = memories[0].get('access_count', 0) @@ -444,12 +454,17 @@ class HermesAgent: return try: + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: # Calculate cutoff date cutoff_date = datetime.now().replace( day=datetime.now().day - self.config.min_retention_days @@ -553,12 +568,17 @@ class HermesAgent: user_id = self._get_current_user_id(context) if context else "anonymous" try: + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: if action == "add": memory_id = str(uuid.uuid4()) # Auto-classify priority if not provided @@ -671,12 +691,17 @@ class HermesAgent: user_id = self._get_current_user_id(context) if context else "anonymous" try: + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: filters = {'user_id': user_id} if query: filters['$or'] = [ @@ -718,12 +743,17 @@ class HermesAgent: return {"success": False, "error": "Invalid skill name", "user_id": user_id} try: + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: if action == "view": filters = {'user_id': user_id, 'name': name} skills = await sor.R('harnessed_skills', {'user_id': user_id, 'name': name}) @@ -807,12 +837,17 @@ class HermesAgent: user_id = self._get_current_user_id(context) if context else "anonymous" try: + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: if action == "create": # Create new remote skill configuration new_skill_id = str(uuid.uuid4()) @@ -1217,12 +1252,17 @@ class HermesAgent: """List workflows for current user""" user_id = self._get_current_user_id(context) if context else "anonymous" try: + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: workflows = await sor.R('hermes_workflows', {'sort': 'created_at desc', 'user_id': user_id}) return {"success": True, "workflows": workflows or [], "user_id": user_id} except Exception as e: @@ -1234,12 +1274,17 @@ class HermesAgent: """List executions for current user (optionally filtered by workflow)""" user_id = self._get_current_user_id(context) if context else "anonymous" try: + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: filters = {'user_id': user_id} if workflow_id: filters['workflow_id'] = workflow_id diff --git a/harnessed_agent/orchestrator.py b/harnessed_agent/orchestrator.py index f7a1f4e..a8ede59 100644 --- a/harnessed_agent/orchestrator.py +++ b/harnessed_agent/orchestrator.py @@ -86,12 +86,17 @@ class HermesOrchestrator: try: workflow_id = str(uuid.uuid4()) + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: data = { 'id': workflow_id, 'user_id': user_id, @@ -123,12 +128,17 @@ class HermesOrchestrator: try: # Verify workflow exists and belongs to user + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: workflows = await sor.R('hermes_workflows', { 'id': workflow_id, 'user_id': user_id @@ -191,12 +201,17 @@ class HermesOrchestrator: async def _load_workflow_definition(self, workflow_id: str, user_id: str) -> Dict[str, Any]: """Load complete workflow definition with all tasks""" try: + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: # Load workflow workflows = await sor.R('hermes_workflows', { 'id': workflow_id, @@ -490,12 +505,17 @@ class HermesOrchestrator: task: TaskDefinition, context: Dict[str, Any]): """Record execution start in database""" try: + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: data = { 'id': execution_id, 'user_id': user_id, @@ -515,12 +535,17 @@ class HermesOrchestrator: result: Dict[str, Any], error: str, retry_count: int): """Record execution end in database""" try: + env = ServerEnv() + + dbname = env.get_module_dbname('harnessed_agent') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('harnessed_agent') as sor: + + async with db.sqlorContext(dbname) as sor: end_time = datetime.now() data = { 'id': execution_id,