fix: fallback to default DB for LLM config lookup

- _get_llm_config now tries module DB and 'default' DB
- Adds logging to show which DB is accessed
- Prevents empty config when table is in default DB
This commit is contained in:
yumoqing 2026-05-07 15:10:53 +08:00
parent d22dfdf383
commit a7f99fc710

View File

@ -77,20 +77,29 @@ LLM_PROVIDERS = {
async def _get_llm_config() -> Dict[str, Any]:
"""Get LLM client configuration from harnessed_agent_config table."""
dbnames_to_try = ['default']
try:
env = ServerEnv()
dbname = env.get_module_dbname('harnessed_agent')
module_db = env.get_module_dbname('harnessed_agent')
if module_db not in dbnames_to_try:
dbnames_to_try.insert(0, module_db)
except Exception:
dbname = 'default'
pass
try:
async with DBPools().sqlorContext(dbname) as sor:
rows = await sor.R('harnessed_agent_config', {},
orderby='updated_at DESC', limit=1)
if rows:
return rows[0]
except Exception as e:
error(f"Failed to fetch LLM config: {e}")
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)
if rows:
info(f"Loaded LLM config from DB '{dbname}'")
return rows[0]
else:
warning(f"No rows in harnessed_agent_config in DB '{dbname}'")
except Exception as e:
error(f"Failed to fetch LLM config from DB '{dbname}': {e}")
error("LLM config not found in any database")
return {}