Repository navigation
feat(agent-list): support multi-select canvas category filtering - #17843
Conversation
Allow users to filter agents by multiple canvas categories at once instead of a single category. The frontend now sends the selected category IDs as a comma-joined string, and the backend applies an `IN` query against the list.
📝 WalkthroughWalkthroughThe agent list API now accepts multiple canvas categories. It supports groups-only, mixed, and default modes. Matching agents and compilation template groups are merged and paginated consistently. The client serializes all selected category IDs. ChangesAgent category filtering
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant list_agents
participant UserCanvasService
participant CompilationTemplateGroups
Client->>list_agents: Send comma-separated canvas_category values
list_agents->>UserCanvasService: Query agents with filtered categories
list_agents->>CompilationTemplateGroups: Fetch selected template groups
list_agents-->>Client: Return merged paginated results
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
test/testcases/test_web_api/test_agent_app/test_agents_webhook_unit.py (1)
524-532: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for the multi-category request.
The updated fake accepts
canvas_category_list, but this test invokeslist_agentswithoutcanvas_category. The test can pass if category parsing or forwarding is broken. Add a request with"canvas_category": "category-a,category-b"and assert thatcaptured["canvas_category_list"]contains both values. Also cover mixed group and agent pagination.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/testcases/test_web_api/test_agent_app/test_agents_webhook_unit.py` around lines 524 - 532, Add coverage in the test invoking list_agents and fake_get_by_tenant_ids for a request with canvas_category set to “category-a,category-b”; assert captured["canvas_category_list"] contains both categories. Extend the same test to exercise mixed group and agent pagination while preserving existing request parameter assertions.api/apps/restful_apis/agent_api.py (2)
793-804: 🚀 Performance & Scalability | 🔵 TrivialBound the mixed-mode merge before relying on it at tenant scale.
The mixed path disables SQL pagination and loads every matching agent before sorting and slicing in Python. A large tenant can make one request consume high database, memory, and CPU resources. Add a bounded merge strategy or load-test this path with a documented maximum.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@api/apps/restful_apis/agent_api.py` around lines 793 - 804, Update the mixed-mode flow around UserCanvasService.get_by_tenant_ids to avoid unbounded loading when SQL pagination is disabled: introduce a bounded merge strategy or enforce a documented maximum result size before sorting and slicing in Python. Ensure requests cannot load every matching agent for a large tenant while preserving the existing ordering and pagination behavior.
731-741: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd normal-path logging for the new multi-category flow.
The new category filter and group/agent merge paths log failures but not successful routing or result sizes. Add low-volume logs that record the selected mode and counts without logging full identifiers.
api/apps/restful_apis/agent_api.py#L731-L741: log the resolved category mode and whether groups are requested.api/apps/restful_apis/agent_api.py#L787-L827: log mixed-mode agent/group counts and the final page size.api/db/services/canvas_service.py#L163-L164: log that the multi-category filter was applied and record the category count.As per coding guidelines,
**/*.py: Add logging for new flows.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@api/apps/restful_apis/agent_api.py` around lines 731 - 741, Add low-volume success logging for the multi-category flow: in api/apps/restful_apis/agent_api.py lines 731-741, log the resolved category mode and whether compilation template groups are requested; in lines 787-827, log mixed-mode agent and group result counts plus the final page size; in api/db/services/canvas_service.py lines 163-164, log that the multi-category filter was applied and the number of categories, without emitting full identifiers.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/apps/restful_apis/agent_api.py`:
- Line 685: Update the canvas_category_list construction in the agent API to
strip whitespace from each comma-separated token before filtering or mode
selection. Ensure duplicate compilation_template_group tokens are normalized and
handled consistently so the groups-only check cannot fall through without
applying the intended agent filter.
In `@web/src/hooks/use-agent-request.ts`:
- Around line 105-112: Update the remaining buildAgentListParams call in
use-agent-request.ts to pass the category filter using the renamed
canvasCategoryIds property instead of canvasCategory. Preserve the existing
category values so all-agent requests continue applying the filter and the call
matches the function’s current parameter type.
---
Nitpick comments:
In `@api/apps/restful_apis/agent_api.py`:
- Around line 793-804: Update the mixed-mode flow around
UserCanvasService.get_by_tenant_ids to avoid unbounded loading when SQL
pagination is disabled: introduce a bounded merge strategy or enforce a
documented maximum result size before sorting and slicing in Python. Ensure
requests cannot load every matching agent for a large tenant while preserving
the existing ordering and pagination behavior.
- Around line 731-741: Add low-volume success logging for the multi-category
flow: in api/apps/restful_apis/agent_api.py lines 731-741, log the resolved
category mode and whether compilation template groups are requested; in lines
787-827, log mixed-mode agent and group result counts plus the final page size;
in api/db/services/canvas_service.py lines 163-164, log that the multi-category
filter was applied and the number of categories, without emitting full
identifiers.
In `@test/testcases/test_web_api/test_agent_app/test_agents_webhook_unit.py`:
- Around line 524-532: Add coverage in the test invoking list_agents and
fake_get_by_tenant_ids for a request with canvas_category set to
“category-a,category-b”; assert captured["canvas_category_list"] contains both
categories. Extend the same test to exercise mixed group and agent pagination
while preserving existing request parameter assertions.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 97ba24d7-8781-496f-b723-4071f574514b
📒 Files selected for processing (4)
api/apps/restful_apis/agent_api.pyapi/db/services/canvas_service.pytest/testcases/test_web_api/test_agent_app/test_agents_webhook_unit.pyweb/src/hooks/use-agent-request.ts
| def list_agents(tenant_id): | ||
| keywords = request.args.get("keywords", "") | ||
| canvas_category = request.args.get("canvas_category") | ||
| canvas_category_list = [item for item in request.args.get("canvas_category", "").strip().split(",") if item] |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Normalize each category token before mode selection.
The current expression strips only the complete query value. A value such as agent-a, compilation_template_group leaves a leading space on the second token. Duplicate compilation_template_group values also bypass the groups-only check and can fall through with no agent filter.
Proposed fix
- canvas_category_list = [item for item in request.args.get("canvas_category", "").strip().split(",") if item]
+ raw_canvas_categories = request.args.get("canvas_category", "") or ""
+ canvas_category_list = list(
+ dict.fromkeys(item.strip() for item in raw_canvas_categories.split(",") if item.strip())
+ )📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| canvas_category_list = [item for item in request.args.get("canvas_category", "").strip().split(",") if item] | |
| raw_canvas_categories = request.args.get("canvas_category", "") or "" | |
| canvas_category_list = list( | |
| dict.fromkeys(item.strip() for item in raw_canvas_categories.split(",") if item.strip()) | |
| ) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@api/apps/restful_apis/agent_api.py` at line 685, Update the
canvas_category_list construction in the agent API to strip whitespace from each
comma-separated token before filtering or mode selection. Ensure duplicate
compilation_template_group tokens are normalized and handled consistently so the
groups-only check cannot fall through without applying the intended agent
filter.
| canvasCategoryIds, | ||
| ownerIds, | ||
| tags, | ||
| }: { | ||
| page: number; | ||
| pageSize: number; | ||
| keywords?: string; | ||
| canvasCategory?: string; | ||
| canvasCategoryIds?: string[]; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Update the remaining call to buildAgentListParams.
buildAgentListParams now accepts canvasCategoryIds, but Line 217 still passes canvasCategory. TypeScript can report an excess-property error. If type checking is skipped, destructuring drops the old property and the all-agent request loses its category filter.
Proposed fix
- canvasCategory: AgentCategory.AgentCanvas,
+ canvasCategoryIds: [AgentCategory.AgentCanvas],🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/hooks/use-agent-request.ts` around lines 105 - 112, Update the
remaining buildAgentListParams call in use-agent-request.ts to pass the category
filter using the renamed canvasCategoryIds property instead of canvasCategory.
Preserve the existing category values so all-agent requests continue applying
the filter and the call matches the function’s current parameter type.
wangq8
left a comment
There was a problem hiding this comment.
Good feature, well-structured implementation. I reviewed the full logic flow and it looks solid. A few observations:
Architecture — The three-tier approach (groups-only → merge → mixed → agent-only) is clear and consistent with the existing pattern. The mixed mode properly mirrors the existing merge mode strategy (fetch all, interleave by update_time, paginate in Python).
Backend:
canvas_category→canvas_category_listrename in the service layer makes intent clearer — good call.in_()peewee method is the right choice here.- Mixed mode correctly passes
tagsandcanvas_typethrough toget_by_tenant_ids. - Empty
canvas_category_listis handled safely (falsy guard before.in_()call).
Frontend:
canvasCategory→canvasCategoryIdsrename is consistent and descriptive.- Joining with comma preserves backward compatibility — single-select still works as a one-element array.
One non-blocking suggestion: The mixed mode branch is structurally similar to merge mode (fetch all, sort, paginate). Consider extracting a shared helper in a follow-up to reduce duplication.
No regressions, no security concerns. Approved.
|
@dcc123456 fix CI. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17843 +/- ##
=======================================
Coverage 90.65% 90.65%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 650 650
Misses 39 39
Partials 28 28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
feat(agent-list): support multi-select canvas category filtering
Allow users to filter agents by multiple canvas categories at once instead
of a single category. The frontend now sends the selected category IDs as
a comma-joined string, and the backend applies an
INquery against thelist.