mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-04 06:40:29 +08:00
fix(agent): add canvas_type filter and field to list_agents API (#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):
This commit is contained in:
@@ -641,6 +641,7 @@ def prompts():
|
||||
def list_agents(tenant_id):
|
||||
keywords = request.args.get("keywords", "")
|
||||
canvas_category = request.args.get("canvas_category")
|
||||
canvas_type = request.args.get("canvas_type")
|
||||
owner_ids = [item for item in request.args.get("owner_ids", "").strip().split(",") if item]
|
||||
tags = [item for item in request.args.get("tags", "").strip().split(",") if item]
|
||||
|
||||
@@ -675,6 +676,7 @@ def list_agents(tenant_id):
|
||||
keywords,
|
||||
canvas_category,
|
||||
tags,
|
||||
canvas_type,
|
||||
)
|
||||
|
||||
return get_json_result(data={"canvas": canvas, "total": total})
|
||||
|
||||
@@ -152,6 +152,7 @@ class UserCanvasService(CommonService):
|
||||
keywords,
|
||||
canvas_category=None,
|
||||
tags=None,
|
||||
canvas_type=None,
|
||||
):
|
||||
fields = [
|
||||
cls.model.id,
|
||||
@@ -163,6 +164,7 @@ class UserCanvasService(CommonService):
|
||||
User.nickname,
|
||||
User.avatar.alias('tenant_avatar'),
|
||||
cls.model.update_time,
|
||||
cls.model.canvas_type,
|
||||
cls.model.canvas_category,
|
||||
cls.model.tags,
|
||||
]
|
||||
@@ -177,6 +179,8 @@ class UserCanvasService(CommonService):
|
||||
)
|
||||
if canvas_category:
|
||||
agents = agents.where(cls.model.canvas_category == canvas_category)
|
||||
if canvas_type:
|
||||
agents = agents.where(cls.model.canvas_type == canvas_type)
|
||||
if tags:
|
||||
tag_list = [t.strip() for t in tags if t and t.strip()] if isinstance(tags, (list, tuple)) else [t.strip() for t in str(tags).split(",") if t.strip()]
|
||||
if tag_list:
|
||||
|
||||
Reference in New Issue
Block a user