Skip to content

feat(agent-list): support multi-select canvas category filtering - #17843

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:feat/agent-list-multi-category-filter
Aug 5, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:feat/agent-list-multi-category-filter

Conversation

@dcc123456

Copy link
Copy Markdown
Collaborator

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 IN query against the
list.

  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.
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🌈 python Pull requests that update Python code 💞 feature Feature request, pull request that fullfill a new feature. 🧰 typescript Pull requests that update Typescript code labels Aug 5, 2026
@dcc123456
dcc123456 requested a review from wangq8 August 5, 2026 05:51
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Agent category filtering

Layer / File(s) Summary
Category query contract
api/db/services/canvas_service.py, test/testcases/test_web_api/test_agent_app/test_agents_webhook_unit.py
UserCanvasService.get_by_tenant_ids accepts canvas_category_list and filters with category membership. The test stub uses the renamed parameter.
Agent list routing and merge
api/apps/restful_apis/agent_api.py
list_agents parses multiple categories, handles groups-only and mixed modes, merges results by update_time, and applies pagination.
Client category parameters
web/src/hooks/use-agent-request.ts
The client serializes selected category IDs as a comma-separated query value and preserves all IDs during pagination.

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
Loading

Suggested reviewers: wangq8, jinhai-cn, cike8899

Poem

I’m a small rabbit, quick and bright,
Sorting category paths just right.
Agents hop in, groups join the queue,
Pages merge with timestamps in view.
Commas guide each request along—
A tidy burrow, fast and strong!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description includes the required Summary section and clearly explains the multi-category filtering change.
Title check ✅ Passed The title clearly and concisely describes the main change: multi-select canvas category filtering for the agent list.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dcc123456 dcc123456 added the ci Continue Integration label Aug 5, 2026
@dcc123456
dcc123456 marked this pull request as draft August 5, 2026 05:51
@dcc123456
dcc123456 marked this pull request as ready for review August 5, 2026 05:51
@dcc123456
dcc123456 requested a review from Lynn-Inf August 5, 2026 05:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Add coverage for the multi-category request.

The updated fake accepts canvas_category_list, but this test invokes list_agents without canvas_category. The test can pass if category parsing or forwarding is broken. Add a request with "canvas_category": "category-a,category-b" and assert that captured["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 | 🔵 Trivial

Bound 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 win

Add 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

📥 Commits

Reviewing files that changed from the base of the PR and between f057544 and 94e9c0b.

📒 Files selected for processing (4)
  • api/apps/restful_apis/agent_api.py
  • api/db/services/canvas_service.py
  • test/testcases/test_web_api/test_agent_app/test_agents_webhook_unit.py
  • web/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]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
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.

Comment on lines +105 to +112
canvasCategoryIds,
ownerIds,
tags,
}: {
page: number;
pageSize: number;
keywords?: string;
canvasCategory?: string;
canvasCategoryIds?: string[];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_list rename in the service layer makes intent clearer — good call.
  • in_() peewee method is the right choice here.
  • Mixed mode correctly passes tags and canvas_type through to get_by_tenant_ids.
  • Empty canvas_category_list is handled safely (falsy guard before .in_() call).

Frontend:

  • canvasCategory → canvasCategoryIds rename 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.

@wangq8

wangq8 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

@dcc123456 fix CI.

@dcc123456
dcc123456 marked this pull request as draft August 5, 2026 08:43
@dcc123456
dcc123456 marked this pull request as ready for review August 5, 2026 08:43
@wangq8 wangq8 added ci Continue Integration and removed ci Continue Integration labels Aug 5, 2026
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (f063cfd) to head (94e9c0b).
⚠️ Report is 27 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. 🌈 python Pull requests that update Python code size:M This PR changes 30-99 lines, ignoring generated files. 🧰 typescript Pull requests that update Typescript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants