fix: replace invalid sor.R(orderby/limit) calls with sqlExe
- All sor.R() calls with orderby= and/or limit= parameters replaced with raw SQL via sor.sqlExe() for correct execution - Fixed in core.py (memory, sessions, workflows, executions, skills) - Fixed in llm_client.py (config lookup)
This commit is contained in:
parent
a7f99fc710
commit
6165c4b1cd
@ -359,12 +359,10 @@ class HermesAgent:
|
|||||||
try:
|
try:
|
||||||
async with self.db.sqlorContext('default') as sor:
|
async with self.db.sqlorContext('default') as sor:
|
||||||
# First, get high priority memories (priority >= high_priority_threshold)
|
# First, get high priority memories (priority >= high_priority_threshold)
|
||||||
high_priority_filters = {
|
high_priority_filters = {'user_id': user_id, 'priority__gte': self.config.high_priority_threshold}
|
||||||
'user_id': user_id,
|
# Fallback to sqlExe for ordering
|
||||||
'priority': {'$gte': self.config.high_priority_threshold}
|
sql = "SELECT * FROM hermes_memory WHERE user_id = :user_id AND priority >= :priority ORDER BY priority DESC, last_accessed DESC"
|
||||||
}
|
high_priority_memories = await sor.sqlExe(sql, {'user_id': user_id, 'priority': self.config.high_priority_threshold})
|
||||||
high_priority_memories = await sor.R('hermes_memory', high_priority_filters,
|
|
||||||
orderby='priority DESC, last_accessed DESC')
|
|
||||||
|
|
||||||
# Add high priority memories first (they're always included if within token limit)
|
# Add high priority memories first (they're always included if within token limit)
|
||||||
for memory in high_priority_memories:
|
for memory in high_priority_memories:
|
||||||
@ -380,15 +378,11 @@ class HermesAgent:
|
|||||||
# If we have remaining tokens, add medium priority memories
|
# If we have remaining tokens, add medium priority memories
|
||||||
remaining_tokens = max_tokens - current_tokens
|
remaining_tokens = max_tokens - current_tokens
|
||||||
if remaining_tokens > 0:
|
if remaining_tokens > 0:
|
||||||
medium_priority_filters = {
|
sql_medium = "SELECT * FROM hermes_memory WHERE user_id = :user_id AND priority >= :low_p AND priority < :high_p ORDER BY last_accessed DESC, priority DESC"
|
||||||
'user_id': user_id,
|
medium_priority_memories = await sor.sqlExe(sql_medium, {
|
||||||
'priority': {
|
'user_id': user_id, 'low_p': self.config.low_priority_threshold,
|
||||||
'$gte': self.config.low_priority_threshold,
|
'high_p': self.config.high_priority_threshold
|
||||||
'$lt': self.config.high_priority_threshold
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
medium_priority_memories = await sor.R('hermes_memory', medium_priority_filters,
|
|
||||||
orderby='last_accessed DESC, priority DESC')
|
|
||||||
|
|
||||||
for memory in medium_priority_memories:
|
for memory in medium_priority_memories:
|
||||||
memory_tokens = self._estimate_tokens(memory['content'])
|
memory_tokens = self._estimate_tokens(memory['content'])
|
||||||
@ -402,12 +396,8 @@ class HermesAgent:
|
|||||||
# Finally, if still tokens available, add low priority recent memories
|
# Finally, if still tokens available, add low priority recent memories
|
||||||
remaining_tokens = max_tokens - current_tokens
|
remaining_tokens = max_tokens - current_tokens
|
||||||
if remaining_tokens > 0:
|
if remaining_tokens > 0:
|
||||||
low_priority_filters = {
|
sql_low = "SELECT * FROM hermes_memory WHERE user_id = :user_id AND priority < :low_p ORDER BY last_accessed DESC"
|
||||||
'user_id': user_id,
|
low_priority_memories = await sor.sqlExe(sql_low, {'user_id': user_id, 'low_p': self.config.low_priority_threshold})
|
||||||
'priority': {'$lt': self.config.low_priority_threshold}
|
|
||||||
}
|
|
||||||
low_priority_memories = await sor.R('hermes_memory', low_priority_filters,
|
|
||||||
orderby='last_accessed DESC')
|
|
||||||
|
|
||||||
for memory in low_priority_memories:
|
for memory in low_priority_memories:
|
||||||
memory_tokens = self._estimate_tokens(memory['content'])
|
memory_tokens = self._estimate_tokens(memory['content'])
|
||||||
@ -675,8 +665,8 @@ class HermesAgent:
|
|||||||
{'tags': {'$like': f'%{query}%'}}
|
{'tags': {'$like': f'%{query}%'}}
|
||||||
]
|
]
|
||||||
|
|
||||||
sessions = await sor.R('hermes_sessions', filters,
|
sql_sess = f"SELECT * FROM hermes_sessions WHERE user_id = :user_id ORDER BY started_at DESC LIMIT {limit}"
|
||||||
orderby='started_at DESC', limit=limit)
|
sessions = await sor.sqlExe(sql_sess, {'user_id': user_id})
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"sessions": sessions,
|
"sessions": sessions,
|
||||||
@ -881,7 +871,8 @@ class HermesAgent:
|
|||||||
if 'enabled' in kwargs:
|
if 'enabled' in kwargs:
|
||||||
filters['enabled'] = kwargs['enabled']
|
filters['enabled'] = kwargs['enabled']
|
||||||
|
|
||||||
skills = await sor.R('harnessed_remote_skills', filters, orderby='name ASC')
|
sql_skills = "SELECT * FROM harnessed_remote_skills WHERE user_id = :user_id ORDER BY name ASC"
|
||||||
|
skills = await sor.sqlExe(sql_skills, {'user_id': user_id})
|
||||||
return {"success": True, "skills": skills, "user_id": user_id}
|
return {"success": True, "skills": skills, "user_id": user_id}
|
||||||
|
|
||||||
elif action == "deploy":
|
elif action == "deploy":
|
||||||
@ -1196,9 +1187,8 @@ class HermesAgent:
|
|||||||
user_id = self._get_current_user_id(context) if context else "anonymous"
|
user_id = self._get_current_user_id(context) if context else "anonymous"
|
||||||
try:
|
try:
|
||||||
async with self.db.sqlorContext('default') as sor:
|
async with self.db.sqlorContext('default') as sor:
|
||||||
workflows = await sor.R('hermes_workflows', {
|
sql_wf = "SELECT * FROM hermes_workflows WHERE user_id = :user_id ORDER BY created_at DESC"
|
||||||
'user_id': user_id
|
workflows = await sor.sqlExe(sql_wf, {'user_id': user_id})
|
||||||
}, orderby='created_at DESC')
|
|
||||||
return {"success": True, "workflows": workflows, "user_id": user_id}
|
return {"success": True, "workflows": workflows, "user_id": user_id}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {"success": False, "error": str(e), "user_id": user_id}
|
return {"success": False, "error": str(e), "user_id": user_id}
|
||||||
@ -1214,9 +1204,8 @@ class HermesAgent:
|
|||||||
if workflow_id:
|
if workflow_id:
|
||||||
filters['workflow_id'] = workflow_id
|
filters['workflow_id'] = workflow_id
|
||||||
|
|
||||||
executions = await sor.R('hermes_executions', filters,
|
sql_exec = f"SELECT * FROM hermes_executions WHERE user_id = :user_id ORDER BY created_at DESC LIMIT {limit} OFFSET {offset}"
|
||||||
orderby='created_at DESC',
|
executions = await sor.sqlExe(sql_exec, {'user_id': user_id})
|
||||||
limit=limit, offset=offset)
|
|
||||||
return {"success": True, "executions": executions, "user_id": user_id}
|
return {"success": True, "executions": executions, "user_id": user_id}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {"success": False, "error": str(e), "user_id": user_id}
|
return {"success": False, "error": str(e), "user_id": user_id}
|
||||||
|
|||||||
@ -89,8 +89,8 @@ async def _get_llm_config() -> Dict[str, Any]:
|
|||||||
for dbname in dbnames_to_try:
|
for dbname in dbnames_to_try:
|
||||||
try:
|
try:
|
||||||
async with DBPools().sqlorContext(dbname) as sor:
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
rows = await sor.R('harnessed_agent_config', {},
|
sql = "SELECT * FROM harnessed_agent_config ORDER BY updated_at DESC LIMIT 1"
|
||||||
orderby='updated_at DESC', limit=1)
|
rows = await sor.sqlExe(sql, {})
|
||||||
if rows:
|
if rows:
|
||||||
info(f"Loaded LLM config from DB '{dbname}'")
|
info(f"Loaded LLM config from DB '{dbname}'")
|
||||||
return rows[0]
|
return rows[0]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user