From 0beb4cf351049412ac5cb69edc0f9f68e8df0f27 Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Fri, 30 Jan 2026 10:03:36 -0600 Subject: [PATCH] fix: address test failures and PR review comments - Fix executionStatus.value crash when status is a string not enum - Update snapshot with new LibraryAgent fields (execution_count, etc.) - Update test mocks to include include_executions=True parameter - Fix potential KeyError/AttributeError in agent deduplication by using .get() with defaults instead of direct dict access --- .../features/chat/tools/agent_generator/core.py | 15 +++++++++------ .../backend/backend/api/features/library/model.py | 7 ++++++- .../backend/snapshots/lib_agts_search | 10 +++++++++- .../test/agent_generator/test_library_agents.py | 7 +++++-- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py b/autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py index b3258a3df5..7d2f720368 100644 --- a/autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py +++ b/autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py @@ -337,10 +337,12 @@ async def get_all_relevant_agents_for_generation( if graph_id == exclude_graph_id: continue agent = await get_library_agent_by_graph_id(user_id, graph_id) - if agent and agent["graph_id"] not in seen_graph_ids: + if agent and agent.get("graph_id") not in seen_graph_ids: agents.append(agent) - seen_graph_ids.add(agent["graph_id"]) - logger.debug(f"Found explicitly mentioned agent: {agent['name']}") + seen_graph_ids.add(agent.get("graph_id", "")) + logger.debug( + f"Found explicitly mentioned agent: {agent.get('name', 'Unknown')}" + ) if include_library: library_agents = await get_library_agents_for_generation( @@ -350,16 +352,17 @@ async def get_all_relevant_agents_for_generation( max_results=max_library_results, ) for agent in library_agents: - if agent["graph_id"] not in seen_graph_ids: + graph_id = agent.get("graph_id") + if graph_id and graph_id not in seen_graph_ids: agents.append(agent) - seen_graph_ids.add(agent["graph_id"]) + seen_graph_ids.add(graph_id) if include_marketplace and search_query: marketplace_agents = await search_marketplace_agents_for_generation( search_query=search_query, max_results=max_marketplace_results, ) - library_names = {a["name"].lower() for a in agents if a.get("name")} + library_names = {name.lower() for a in agents if (name := a.get("name"))} for agent in marketplace_agents: agent_name = agent.get("name") if agent_name and agent_name.lower() not in library_names: diff --git a/autogpt_platform/backend/backend/api/features/library/model.py b/autogpt_platform/backend/backend/api/features/library/model.py index bde91f5b80..a29fe7e60f 100644 --- a/autogpt_platform/backend/backend/api/features/library/model.py +++ b/autogpt_platform/backend/backend/api/features/library/model.py @@ -183,9 +183,14 @@ class LibraryAgent(pydantic.BaseModel): summary = e.stats.get("activity_status") if summary is not None and isinstance(summary, str): exec_summary = summary + exec_status = ( + e.executionStatus.value + if hasattr(e.executionStatus, "value") + else str(e.executionStatus) + ) recent_executions.append( RecentExecution( - status=e.executionStatus.value, + status=exec_status, correctness_score=exec_score, activity_summary=exec_summary, ) diff --git a/autogpt_platform/backend/snapshots/lib_agts_search b/autogpt_platform/backend/snapshots/lib_agts_search index 67c307b09e..43201b12eb 100644 --- a/autogpt_platform/backend/snapshots/lib_agts_search +++ b/autogpt_platform/backend/snapshots/lib_agts_search @@ -31,6 +31,10 @@ "has_sensitive_action": false, "trigger_setup_info": null, "new_output": false, + "execution_count": 0, + "success_rate": null, + "avg_correctness_score": null, + "recent_executions": [], "can_access_graph": true, "is_latest_version": true, "is_favorite": false, @@ -72,6 +76,10 @@ "has_sensitive_action": false, "trigger_setup_info": null, "new_output": false, + "execution_count": 0, + "success_rate": null, + "avg_correctness_score": null, + "recent_executions": [], "can_access_graph": false, "is_latest_version": true, "is_favorite": false, @@ -89,4 +97,4 @@ "current_page": 1, "page_size": 50 } -} \ No newline at end of file +} diff --git a/autogpt_platform/backend/test/agent_generator/test_library_agents.py b/autogpt_platform/backend/test/agent_generator/test_library_agents.py index a8f69fc09c..e62b0746e7 100644 --- a/autogpt_platform/backend/test/agent_generator/test_library_agents.py +++ b/autogpt_platform/backend/test/agent_generator/test_library_agents.py @@ -26,6 +26,7 @@ class TestGetLibraryAgentsForGeneration: mock_agent.description = "Sends emails" mock_agent.input_schema = {"properties": {}} mock_agent.output_schema = {"properties": {}} + mock_agent.recent_executions = [] mock_response = MagicMock() mock_response.agents = [mock_agent] @@ -41,12 +42,12 @@ class TestGetLibraryAgentsForGeneration: search_query="send email", ) - # Verify search_term was passed mock_list.assert_called_once_with( user_id="user-123", search_term="send email", page=1, page_size=15, + include_executions=True, ) # Verify result format @@ -66,6 +67,7 @@ class TestGetLibraryAgentsForGeneration: description="First agent", input_schema={}, output_schema={}, + recent_executions=[], ), MagicMock( graph_id="agent-456", @@ -74,6 +76,7 @@ class TestGetLibraryAgentsForGeneration: description="Second agent", input_schema={}, output_schema={}, + recent_executions=[], ), ] @@ -109,12 +112,12 @@ class TestGetLibraryAgentsForGeneration: max_results=5, ) - # Verify page_size was set to max_results mock_list.assert_called_once_with( user_id="user-123", search_term=None, page=1, page_size=5, + include_executions=True, )