mirror of https://github.com/kortix-ai/suna.git
debug agent icons
This commit is contained in:
parent
a7df37b0ba
commit
47238cba3b
|
@ -18,7 +18,7 @@ from services import redis
|
|||
from utils.auth_utils import get_current_user_id_from_jwt, get_user_id_from_stream_auth, verify_thread_access, verify_admin_api_key
|
||||
from utils.logger import logger, structlog
|
||||
from services.billing import check_billing_status, can_use_model
|
||||
from utils.config import config
|
||||
from utils.config import config, EnvMode
|
||||
from sandbox.sandbox import create_sandbox, delete_sandbox, get_or_start_sandbox
|
||||
from services.llm import make_llm_api_call
|
||||
from run_agent_background import run_agent_background, _cleanup_redis_response_list, update_agent_run_status
|
||||
|
@ -1546,7 +1546,7 @@ async def get_agents(
|
|||
custom_mcps = agent_config['custom_mcps']
|
||||
agentpress_tools = agent_config['agentpress_tools']
|
||||
|
||||
agent_list.append(AgentResponse(
|
||||
agent_response = AgentResponse(
|
||||
agent_id=agent['agent_id'],
|
||||
name=agent['name'],
|
||||
description=agent.get('description'),
|
||||
|
@ -1569,7 +1569,10 @@ async def get_agents(
|
|||
version_count=agent.get('version_count', 1),
|
||||
current_version=current_version,
|
||||
metadata=agent.get('metadata')
|
||||
))
|
||||
)
|
||||
|
||||
print(f"[DEBUG] get_agents RESPONSE item {agent['name']}: icon_name={agent_response.icon_name}, icon_color={agent_response.icon_color}, icon_background={agent_response.icon_background}")
|
||||
agent_list.append(agent_response)
|
||||
|
||||
total_pages = (total_count + limit - 1) // limit
|
||||
|
||||
|
@ -1598,6 +1601,11 @@ async def get_agent(agent_id: str, user_id: str = Depends(get_current_user_id_fr
|
|||
)
|
||||
|
||||
logger.debug(f"Fetching agent {agent_id} for user: {user_id}")
|
||||
|
||||
# Debug logging
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
print(f"[DEBUG] get_agent: Starting to fetch agent {agent_id}")
|
||||
|
||||
client = await db.client
|
||||
|
||||
try:
|
||||
|
@ -1609,6 +1617,11 @@ async def get_agent(agent_id: str, user_id: str = Depends(get_current_user_id_fr
|
|||
|
||||
agent_data = agent.data[0]
|
||||
|
||||
# Debug logging for fetched agent data
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
print(f"[DEBUG] get_agent: Fetched agent from DB - icon_name={agent_data.get('icon_name')}, icon_color={agent_data.get('icon_color')}, icon_background={agent_data.get('icon_background')}")
|
||||
print(f"[DEBUG] get_agent: Also has - profile_image_url={agent_data.get('profile_image_url')}, avatar={agent_data.get('avatar')}, avatar_color={agent_data.get('avatar_color')}")
|
||||
|
||||
# Check ownership - only owner can access non-public agents
|
||||
if agent_data['account_id'] != user_id and not agent_data.get('is_public', False):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
|
@ -1667,14 +1680,24 @@ async def get_agent(agent_id: str, user_id: str = Depends(get_current_user_id_fr
|
|||
}
|
||||
|
||||
from agent.config_helper import extract_agent_config
|
||||
|
||||
# Debug logging before extract_agent_config
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
print(f"[DEBUG] get_agent: Before extract_agent_config - agent_data has icon_name={agent_data.get('icon_name')}, icon_color={agent_data.get('icon_color')}, icon_background={agent_data.get('icon_background')}")
|
||||
|
||||
agent_config = extract_agent_config(agent_data, version_data)
|
||||
|
||||
# Debug logging after extract_agent_config
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
print(f"[DEBUG] get_agent: After extract_agent_config - agent_config has icon_name={agent_config.get('icon_name')}, icon_color={agent_config.get('icon_color')}, icon_background={agent_config.get('icon_background')}")
|
||||
print(f"[DEBUG] get_agent: Final response will use icon fields from agent_config")
|
||||
|
||||
system_prompt = agent_config['system_prompt']
|
||||
configured_mcps = agent_config['configured_mcps']
|
||||
custom_mcps = agent_config['custom_mcps']
|
||||
agentpress_tools = agent_config['agentpress_tools']
|
||||
|
||||
return AgentResponse(
|
||||
response = AgentResponse(
|
||||
agent_id=agent_data['agent_id'],
|
||||
name=agent_data['name'],
|
||||
description=agent_data.get('description'),
|
||||
|
@ -1699,6 +1722,15 @@ async def get_agent(agent_id: str, user_id: str = Depends(get_current_user_id_fr
|
|||
metadata=agent_data.get('metadata')
|
||||
)
|
||||
|
||||
# Debug logging for the actual response
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
print(f"[DEBUG] get_agent FINAL RESPONSE: agent_id={response.agent_id}")
|
||||
print(f"[DEBUG] get_agent FINAL RESPONSE: icon_name={response.icon_name}, icon_color={response.icon_color}, icon_background={response.icon_background}")
|
||||
print(f"[DEBUG] get_agent FINAL RESPONSE: profile_image_url={response.profile_image_url}, avatar={response.avatar}, avatar_color={response.avatar_color}")
|
||||
print(f"[DEBUG] get_agent FINAL RESPONSE: Response being sent to frontend with icon fields from agent_config")
|
||||
|
||||
return response
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
|
@ -1934,13 +1966,16 @@ async def create_agent(
|
|||
"avatar": agent_data.avatar,
|
||||
"avatar_color": agent_data.avatar_color,
|
||||
"profile_image_url": agent_data.profile_image_url,
|
||||
"icon_name": agent_data.icon_name or "brain",
|
||||
"icon_name": agent_data.icon_name or "bot",
|
||||
"icon_color": agent_data.icon_color or "#000000",
|
||||
"icon_background": agent_data.icon_background or "#F3F4F6",
|
||||
"is_default": agent_data.is_default or False,
|
||||
"version_count": 1
|
||||
}
|
||||
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
print(f"[DEBUG] create_agent: Creating with icon_name={insert_data.get('icon_name')}, icon_color={insert_data.get('icon_color')}, icon_background={insert_data.get('icon_background')}")
|
||||
|
||||
new_agent = await client.table('agents').insert(insert_data).execute()
|
||||
|
||||
if not new_agent.data:
|
||||
|
@ -1999,7 +2034,8 @@ async def create_agent(
|
|||
await Cache.invalidate(f"agent_count_limit:{user_id}")
|
||||
|
||||
logger.debug(f"Created agent {agent['agent_id']} with v1 for user: {user_id}")
|
||||
return AgentResponse(
|
||||
|
||||
response = AgentResponse(
|
||||
agent_id=agent['agent_id'],
|
||||
name=agent['name'],
|
||||
description=agent.get('description'),
|
||||
|
@ -2025,6 +2061,12 @@ async def create_agent(
|
|||
metadata=agent.get('metadata')
|
||||
)
|
||||
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
print(f"[DEBUG] create_agent RESPONSE: Returning icon_name={response.icon_name}, icon_color={response.icon_color}, icon_background={response.icon_background}")
|
||||
print(f"[DEBUG] create_agent RESPONSE: Also returning profile_image_url={response.profile_image_url}, avatar={response.avatar}, avatar_color={response.avatar_color}")
|
||||
|
||||
return response
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
|
@ -2065,6 +2107,12 @@ async def update_agent(
|
|||
detail="Custom agent currently disabled. This feature is not available at the moment."
|
||||
)
|
||||
logger.debug(f"Updating agent {agent_id} for user: {user_id}")
|
||||
|
||||
# Debug logging for icon fields
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
print(f"[DEBUG] update_agent: Received icon fields - icon_name={agent_data.icon_name}, icon_color={agent_data.icon_color}, icon_background={agent_data.icon_background}")
|
||||
print(f"[DEBUG] update_agent: Also received - profile_image_url={agent_data.profile_image_url}, avatar={agent_data.avatar}, avatar_color={agent_data.avatar_color}")
|
||||
|
||||
client = await db.client
|
||||
|
||||
try:
|
||||
|
@ -2272,6 +2320,10 @@ async def update_agent(
|
|||
if agent_data.icon_background is not None:
|
||||
update_data["icon_background"] = agent_data.icon_background
|
||||
|
||||
# Debug logging for update_data
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
print(f"[DEBUG] update_agent: Prepared update_data with icon fields - icon_name={update_data.get('icon_name')}, icon_color={update_data.get('icon_color')}, icon_background={update_data.get('icon_background')}")
|
||||
|
||||
current_system_prompt = agent_data.system_prompt if agent_data.system_prompt is not None else current_version_data.get('system_prompt', '')
|
||||
current_configured_mcps = agent_data.configured_mcps if agent_data.configured_mcps is not None else current_version_data.get('configured_mcps', [])
|
||||
|
||||
|
@ -2315,12 +2367,24 @@ async def update_agent(
|
|||
|
||||
if update_data:
|
||||
try:
|
||||
print(f"[DEBUG] update_agent DB UPDATE: About to update agent {agent_id} with data: {update_data}")
|
||||
|
||||
update_result = await client.table('agents').update(update_data).eq("agent_id", agent_id).eq("account_id", user_id).execute()
|
||||
|
||||
# Debug logging after DB update
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
if update_result.data:
|
||||
print(f"[DEBUG] update_agent DB UPDATE SUCCESS: Updated {len(update_result.data)} row(s)")
|
||||
print(f"[DEBUG] update_agent DB UPDATE RESULT: {update_result.data[0] if update_result.data else 'No data'}")
|
||||
else:
|
||||
print(f"[DEBUG] update_agent DB UPDATE FAILED: No rows affected")
|
||||
|
||||
if not update_result.data:
|
||||
raise HTTPException(status_code=500, detail="Failed to update agent - no rows affected")
|
||||
except Exception as e:
|
||||
logger.error(f"Error updating agent {agent_id}: {str(e)}")
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
print(f"[DEBUG] update_agent DB UPDATE ERROR: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=f"Failed to update agent: {str(e)}")
|
||||
|
||||
updated_agent = await client.table('agents').select('*').eq("agent_id", agent_id).eq("account_id", user_id).maybe_single().execute()
|
||||
|
@ -2330,6 +2394,11 @@ async def update_agent(
|
|||
|
||||
agent = updated_agent.data
|
||||
|
||||
print(f"[DEBUG] update_agent AFTER UPDATE FETCH: agent_id={agent.get('agent_id')}")
|
||||
print(f"[DEBUG] update_agent AFTER UPDATE FETCH: icon_name={agent.get('icon_name')}, icon_color={agent.get('icon_color')}, icon_background={agent.get('icon_background')}")
|
||||
print(f"[DEBUG] update_agent AFTER UPDATE FETCH: profile_image_url={agent.get('profile_image_url')}, avatar={agent.get('avatar')}, avatar_color={agent.get('avatar_color')}")
|
||||
print(f"[DEBUG] update_agent AFTER UPDATE FETCH: All keys in agent: {agent.keys()}")
|
||||
|
||||
current_version = None
|
||||
if agent.get('current_version_id'):
|
||||
try:
|
||||
|
@ -2378,14 +2447,23 @@ async def update_agent(
|
|||
}
|
||||
|
||||
from agent.config_helper import extract_agent_config
|
||||
|
||||
# Debug logging before extract_agent_config
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
print(f"[DEBUG] update_agent: Before extract_agent_config - agent has icon_name={agent.get('icon_name')}, icon_color={agent.get('icon_color')}, icon_background={agent.get('icon_background')}")
|
||||
|
||||
agent_config = extract_agent_config(agent, version_data)
|
||||
|
||||
# Debug logging after extract_agent_config
|
||||
if config.ENV_MODE == EnvMode.STAGING:
|
||||
print(f"[DEBUG] update_agent: After extract_agent_config - agent_config has icon_name={agent_config.get('icon_name')}, icon_color={agent_config.get('icon_color')}, icon_background={agent_config.get('icon_background')}")
|
||||
|
||||
system_prompt = agent_config['system_prompt']
|
||||
configured_mcps = agent_config['configured_mcps']
|
||||
custom_mcps = agent_config['custom_mcps']
|
||||
agentpress_tools = agent_config['agentpress_tools']
|
||||
|
||||
return AgentResponse(
|
||||
response = AgentResponse(
|
||||
agent_id=agent['agent_id'],
|
||||
name=agent['name'],
|
||||
description=agent.get('description'),
|
||||
|
@ -2410,6 +2488,14 @@ async def update_agent(
|
|||
metadata=agent.get('metadata')
|
||||
)
|
||||
|
||||
|
||||
print(f"[DEBUG] update_agent FINAL RESPONSE: agent_id={response.agent_id}")
|
||||
print(f"[DEBUG] update_agent FINAL RESPONSE: icon_name={response.icon_name}, icon_color={response.icon_color}, icon_background={response.icon_background}")
|
||||
print(f"[DEBUG] update_agent FINAL RESPONSE: profile_image_url={response.profile_image_url}, avatar={response.avatar}, avatar_color={response.avatar_color}")
|
||||
print(f"[DEBUG] update_agent FINAL RESPONSE: Full response dict keys: {response.dict().keys()}")
|
||||
|
||||
return response
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from typing import Dict, Any, Optional, List
|
||||
from utils.logger import logger
|
||||
import os
|
||||
|
||||
|
||||
def extract_agent_config(agent_data: Dict[str, Any], version_data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
|
@ -8,6 +9,11 @@ def extract_agent_config(agent_data: Dict[str, Any], version_data: Optional[Dict
|
|||
metadata = agent_data.get('metadata', {})
|
||||
is_suna_default = metadata.get('is_suna_default', False)
|
||||
|
||||
# Debug logging
|
||||
if os.getenv("ENV_MODE", "").upper() == "STAGING":
|
||||
print(f"[DEBUG] extract_agent_config: Called for agent {agent_id}, is_suna_default={is_suna_default}")
|
||||
print(f"[DEBUG] extract_agent_config: Input agent_data has icon_name={agent_data.get('icon_name')}, icon_color={agent_data.get('icon_color')}, icon_background={agent_data.get('icon_background')}")
|
||||
|
||||
# Handle Suna agents with special logic
|
||||
if is_suna_default:
|
||||
return _extract_suna_agent_config(agent_data, version_data)
|
||||
|
@ -74,6 +80,10 @@ def _extract_suna_agent_config(agent_data: Dict[str, Any], version_data: Optiona
|
|||
def _extract_custom_agent_config(agent_data: Dict[str, Any], version_data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
agent_id = agent_data.get('agent_id', 'Unknown')
|
||||
|
||||
# Debug logging for icon fields
|
||||
if os.getenv("ENV_MODE", "").upper() == "STAGING":
|
||||
print(f"[DEBUG] _extract_custom_agent_config: Input agent_data has icon_name={agent_data.get('icon_name')}, icon_color={agent_data.get('icon_color')}, icon_background={agent_data.get('icon_background')}")
|
||||
|
||||
if version_data:
|
||||
logger.debug(f"Using version data for custom agent {agent_id} (version: {version_data.get('version_name', 'unknown')})")
|
||||
|
||||
|
@ -96,7 +106,7 @@ def _extract_custom_agent_config(agent_data: Dict[str, Any], version_data: Optio
|
|||
workflows = []
|
||||
triggers = []
|
||||
|
||||
return {
|
||||
config = {
|
||||
'agent_id': agent_data['agent_id'],
|
||||
'name': agent_data['name'],
|
||||
'description': agent_data.get('description'),
|
||||
|
@ -121,10 +131,16 @@ def _extract_custom_agent_config(agent_data: Dict[str, Any], version_data: Optio
|
|||
'version_name': version_data.get('version_name', 'v1'),
|
||||
'restrictions': {}
|
||||
}
|
||||
|
||||
# Debug logging for returned config
|
||||
if os.getenv("ENV_MODE", "").upper() == "STAGING":
|
||||
print(f"[DEBUG] _extract_custom_agent_config: Returning config with icon_name={config.get('icon_name')}, icon_color={config.get('icon_color')}, icon_background={config.get('icon_background')}")
|
||||
|
||||
return config
|
||||
|
||||
logger.warning(f"No version data found for custom agent {agent_id}, creating default configuration")
|
||||
|
||||
return {
|
||||
fallback_config = {
|
||||
'agent_id': agent_data['agent_id'],
|
||||
'name': agent_data.get('name', 'Unnamed Agent'),
|
||||
'description': agent_data.get('description', ''),
|
||||
|
@ -149,6 +165,12 @@ def _extract_custom_agent_config(agent_data: Dict[str, Any], version_data: Optio
|
|||
'version_name': 'v1',
|
||||
'restrictions': {}
|
||||
}
|
||||
|
||||
# Debug logging for fallback config
|
||||
if os.getenv("ENV_MODE", "").upper() == "STAGING":
|
||||
print(f"[DEBUG] _extract_custom_agent_config: Fallback config with icon_name={fallback_config.get('icon_name')}, icon_color={fallback_config.get('icon_color')}, icon_background={fallback_config.get('icon_background')}")
|
||||
|
||||
return fallback_config
|
||||
|
||||
|
||||
def build_unified_config(
|
||||
|
|
Loading…
Reference in New Issue