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