Skip to content

fix(agent): add canvas_type filter and field to list_agents API - #15754

Merged
yuzhichang merged 2 commits into
infiniflow:mainfrom
tecpie:feature/list-agents-canvas-type
Jun 30, 2026
Merged

yuzhichang merged 2 commits into
infiniflow:mainfrom
tecpie:feature/list-agents-canvas-type

Conversation

@huang-aoqin

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

GET /api/v1/agents (list_agents) already supports filtering by canvas_category, keywords, tags, and owner_ids, but it does not support canvas_type — even though canvas_type is a persisted field on UserCanvas and is already accepted on agent create/update APIs.

This gap causes two issues:

Filtering — clients cannot list agents by business category (e.g. Marketing, Agent, Ingestion Pipeline) without fetching all agents and filtering client-side.
Response payload — list_agents did not return canvas_type in each canvas item, so consumers had to call GET /api/v1/agents/{id} per agent to read it.
This PR adds optional canvas_type query parameter support and includes canvas_type in the list response.

Type of change

  • [√] Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

- 在 agent API 中新增 canvas_type 参数支持
- 修改 list_agents 函数以接收 canvas_type 查询参数
- 更新 CanvasService.query 方法以支持 canvas_type 筛选条件
- 在查询字段中添加 canvas_type 字段
- 实现基于 canvas_type 的数据过滤逻辑
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jun 8, 2026
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 74718851-213b-4155-be85-3e70d9a79658

📥 Commits

Reviewing files that changed from the base of the PR and between fee8417 and c43c9a0.

📒 Files selected for processing (2)
  • api/apps/restful_apis/agent_api.py
  • api/db/services/canvas_service.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • api/apps/restful_apis/agent_api.py
  • api/db/services/canvas_service.py

📝 Walkthrough

Walkthrough

This PR adds canvas type filtering to the agent listing endpoint. The agent API now accepts a canvas_type query parameter and passes it through to the canvas service, which filters results and includes canvas_type in returned data.

Changes

Canvas Type Filtering for Agent List

Layer / File(s) Summary
Database service canvas_type filtering
api/db/services/canvas_service.py
UserCanvasService.get_by_tenant_ids accepts an optional canvas_type parameter, includes it in selected fields, and applies a WHERE clause to filter results when provided.
API endpoint canvas_type parameter handling
api/apps/restful_apis/agent_api.py
list_agents reads canvas_type from request query parameters and forwards it to UserCanvasService.get_by_tenant_ids as a filter argument.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A canvas type now filters the way,
The API learns to sort and sift the day,
Where agents bloom like springtime clover,
Each kind of canvas neatly sorted over! 🌱

🚥 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
Title check ✅ Passed The title clearly matches the main change: adding canvas_type filtering and returning canvas_type in list_agents.
Description check ✅ Passed It explains the problem and change clearly, though it uses a custom heading instead of the template's 'Summary' section.
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.

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.

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

🧹 Nitpick comments (1)
api/db/services/canvas_service.py (1)

144-215: ⚡ Quick win

Consider adding logging to improve observability of canvas_type filtering.

The get_by_tenant_ids method now supports canvas_type filtering, but the filter application is not logged. Other query methods in this service (list_tags at lines 233-238 and update_tags at lines 272-277) include structured logging. Adding a log statement would help with debugging and usage tracking, similar to the pattern used in those methods.

📊 Suggested logging addition
# Add after line 215, before the return statement
logging.info(
    "UserCanvasService.get_by_tenant_ids user=%s canvas_category=%s canvas_type=%s tags=%s keywords=%s count=%d",
    user_id,
    canvas_category,
    canvas_type,
    tags,
    keywords,
    count,
)

As per coding guidelines: "Add logging for new flows" for **/*.py.

🤖 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/db/services/canvas_service.py` around lines 144 - 215, The
get_by_tenant_ids method applies canvas_type filtering but doesn't log it; add a
structured logging.info call in UserCanvasService.get_by_tenant_ids (just before
the return) that records user_id, canvas_category, canvas_type, tags, keywords
and the computed count to match the pattern used in list_tags/update_tags; use
the existing logging module and the agents/count variables (e.g., reference
agents_list/count/user_id/canvas_category/canvas_type/tags/keywords) so the
filter and result size are observable.

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.

Nitpick comments:
In `@api/db/services/canvas_service.py`:
- Around line 144-215: The get_by_tenant_ids method applies canvas_type
filtering but doesn't log it; add a structured logging.info call in
UserCanvasService.get_by_tenant_ids (just before the return) that records
user_id, canvas_category, canvas_type, tags, keywords and the computed count to
match the pattern used in list_tags/update_tags; use the existing logging module
and the agents/count variables (e.g., reference
agents_list/count/user_id/canvas_category/canvas_type/tags/keywords) so the
filter and result size are observable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0503fc59-c144-4c4c-a08a-c4c0bce43035

📥 Commits

Reviewing files that changed from the base of the PR and between 220ee9d and fee8417.

📒 Files selected for processing (2)
  • api/apps/restful_apis/agent_api.py
  • api/db/services/canvas_service.py

@yuzhichang
yuzhichang self-requested a review June 28, 2026 00:49
@yuzhichang

yuzhichang commented Jun 28, 2026 •

Copy link
Copy Markdown
Member

The head branch of this PR lives in an external fork and cannot be updated via the current reviewer token. Please rebase against main locally and push:

git fetch origin main
git rebase origin/main
# or
git merge origin/main

If the 403 persists after pushing, please contact the repository maintainers to verify fork write permissions.

Triggered by reviewer yuzhichang (request-for-action)

@huang-aoqin

Copy link
Copy Markdown
Contributor Author

The head branch of this PR lives in an external fork and cannot be updated via the current reviewer token. Please rebase against main locally and push:

git fetch origin main
git rebase origin/main
# or
git merge origin/main

If the 403 persists after pushing, please contact the repository maintainers to verify fork write permissions.

Triggered by reviewer yuzhichang (request-for-action)

Done

@yuzhichang yuzhichang added the ci Continue Integration label Jun 29, 2026
@yuzhichang
yuzhichang merged commit 3c946a7 into infiniflow:main Jun 30, 2026
9 of 12 checks passed
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 1, 2026
…niflow#15754)

### What problem does this PR solve?

GET /api/v1/agents (list_agents) already supports filtering by
canvas_category, keywords, tags, and owner_ids, but it does not support
canvas_type — even though canvas_type is a persisted field on UserCanvas
and is already accepted on agent create/update APIs.

This gap causes two issues:

Filtering — clients cannot list agents by business category (e.g.
Marketing, Agent, Ingestion Pipeline) without fetching all agents and
filtering client-side.
Response payload — list_agents did not return canvas_type in each canvas
item, so consumers had to call GET /api/v1/agents/{id} per agent to read
it.
This PR adds optional canvas_type query parameter support and includes
canvas_type in the list response.
### Type of change

- [√] Bug Fix (non-breaking change which fixes an issue)
- [ ] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):
yuzhichang pushed a commit that referenced this pull request Jul 2, 2026
### Summary

Port the following PRs to GO in this PR

#14210
#14641
#15220
#15228
#15384
#15754
#16413
#16483
#16419
#16361   
#16050
@huang-aoqin
huang-aoqin deleted the feature/list-agents-canvas-type branch September 14, 2026 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants