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
This commit is contained in:
Zamil Majdy
2026-01-30 10:03:36 -06:00
parent f8980ad7dc
commit 0beb4cf351
4 changed files with 29 additions and 10 deletions

View File

@@ -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:

View File

@@ -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,
)

View File

@@ -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
}
}
}

View File

@@ -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,
)