mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-30 01:18:07 -05:00
fix: address PR review comments
- Add try/except error handling to get_library_agents_for_generation for graceful degradation (consistent with marketplace search) - Add null checks when deduplicating agents by name to prevent AttributeError if agent name is None - Use actual graph ID from current_agent in edit_agent.py to properly exclude the agent being edited (agent_id might be a library agent ID)
This commit is contained in:
@@ -56,26 +56,30 @@ async def get_library_agents_for_generation(
|
||||
Returns:
|
||||
List of library agent dicts with schemas for sub-agent composition
|
||||
"""
|
||||
response = await library_db.list_library_agents(
|
||||
user_id=user_id,
|
||||
search_term=search_query, # Use search API
|
||||
page=1,
|
||||
page_size=max_results,
|
||||
)
|
||||
try:
|
||||
response = await library_db.list_library_agents(
|
||||
user_id=user_id,
|
||||
search_term=search_query, # Use search API
|
||||
page=1,
|
||||
page_size=max_results,
|
||||
)
|
||||
|
||||
return [
|
||||
{
|
||||
"graph_id": agent.graph_id,
|
||||
"graph_version": agent.graph_version,
|
||||
"name": agent.name,
|
||||
"description": agent.description,
|
||||
"input_schema": agent.input_schema,
|
||||
"output_schema": agent.output_schema,
|
||||
}
|
||||
for agent in response.agents
|
||||
# Exclude the agent being generated/edited to prevent circular references
|
||||
if exclude_graph_id is None or agent.graph_id != exclude_graph_id
|
||||
]
|
||||
return [
|
||||
{
|
||||
"graph_id": agent.graph_id,
|
||||
"graph_version": agent.graph_version,
|
||||
"name": agent.name,
|
||||
"description": agent.description,
|
||||
"input_schema": agent.input_schema,
|
||||
"output_schema": agent.output_schema,
|
||||
}
|
||||
for agent in response.agents
|
||||
# Exclude the agent being generated/edited to prevent circular references
|
||||
if exclude_graph_id is None or agent.graph_id != exclude_graph_id
|
||||
]
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to fetch library agents: {e}")
|
||||
return []
|
||||
|
||||
|
||||
async def search_marketplace_agents_for_generation(
|
||||
@@ -163,9 +167,10 @@ async def get_all_relevant_agents_for_generation(
|
||||
max_results=max_marketplace_results,
|
||||
)
|
||||
# Add marketplace agents that aren't already in library (by name)
|
||||
library_names = {a["name"].lower() for a in library_agents}
|
||||
library_names = {a["name"].lower() for a in library_agents if a.get("name")}
|
||||
for agent in marketplace_agents:
|
||||
if agent["name"].lower() not in library_names:
|
||||
agent_name = agent.get("name")
|
||||
if agent_name and agent_name.lower() not in library_names:
|
||||
agents.append(agent)
|
||||
|
||||
return agents
|
||||
|
||||
@@ -132,10 +132,13 @@ class EditAgentTool(BaseTool):
|
||||
library_agents = None
|
||||
if user_id:
|
||||
try:
|
||||
# Use the actual graph ID from current_agent to properly exclude
|
||||
# the agent being edited (agent_id might be a library agent ID)
|
||||
exclude_id = current_agent.get("id") or agent_id
|
||||
library_agents = await get_all_relevant_agents_for_generation(
|
||||
user_id=user_id,
|
||||
search_query=changes, # Use changes as search term
|
||||
exclude_graph_id=agent_id, # Don't include the agent being edited
|
||||
exclude_graph_id=exclude_id, # Don't include the agent being edited
|
||||
include_marketplace=True,
|
||||
)
|
||||
logger.debug(
|
||||
|
||||
Reference in New Issue
Block a user