From 3c946a7e58a1329d1188ea5897e527566f9f7c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E6=B5=B7=E8=92=BC=E7=81=86?= Date: Tue, 30 Jun 2026 17:43:26 +0800 Subject: [PATCH] fix(agent): add canvas_type filter and field to list_agents API (#15754) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 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): --- api/apps/restful_apis/agent_api.py | 2 ++ api/db/services/canvas_service.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/api/apps/restful_apis/agent_api.py b/api/apps/restful_apis/agent_api.py index 2bd157b77f..859719bba8 100644 --- a/api/apps/restful_apis/agent_api.py +++ b/api/apps/restful_apis/agent_api.py @@ -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}) diff --git a/api/db/services/canvas_service.py b/api/db/services/canvas_service.py index c560b0bac8..561535259c 100644 --- a/api/db/services/canvas_service.py +++ b/api/db/services/canvas_service.py @@ -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: