Skip to content

fix(api): allow canvas_type in agent create and update APIs - #15201

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
tecpie:feature/agent-canvas-type
May 26, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
tecpie:feature/agent-canvas-type

Conversation

@huang-aoqin

@huang-aoqin huang-aoqin commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Creating or updating an agent via POST /api/v1/agents and PUT /api/v1/agents/{agent_id} did not persist canvas_type because the handler req dict never assigned the field before UserCanvasService.save / update_by_id.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

Assign canvas_type on the request payload before persisting to user_canvas.

Expose canvas_type on Python SDK create_agent and update_agent helpers.

Co-authored-by: Cursor <[email protected]>
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 25, 2026
@coderabbitai

coderabbitai Bot commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request adds canvas_type as an optional parameter to agent creation and update flows. The SDK methods accept the new parameter and conditionally include it in API requests, the backend handlers ensure the field is always populated in persisted payloads, and unit tests verify the parameter flows correctly through both operations.

Changes

Agent Canvas Type Support

Layer / File(s) Summary
Backend canvas_type persistence in handlers
api/apps/restful_apis/agent_api.py
The create_agent and update_agent request handlers now ensure canvas_type is always populated in the persisted payload by setting it to the provided value or an empty string if absent.
SDK canvas_type parameter and payload construction
sdk/python/ragflow_sdk/ragflow.py
The SDK's RAGFlow.create_agent and RAGFlow.update_agent methods are extended with optional canvas_type parameters, and their request payloads conditionally include the parameter when provided.
Agent CRUD test coverage for canvas_type
test/testcases/test_sdk_api/test_agent_management/test_agent_crud_unit.py
Unit tests for agent creation and update are extended to verify that the canvas_type parameter is correctly included in the outgoing request payloads for both operations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • infiniflow/ragflow#14597: Both PRs modify api/apps/restful_apis/agent_api.py in the update_agent request handler—one adds canvas_type to the persisted update payload, while the other changes the authorization check to use UserCanvasService.accessible(...).

Suggested labels

🐖api, size:XS, lgtm

Suggested reviewers

  • Magicbook1108
  • wangq8

Poem

🐰 A canvas type hops into the fold,
From SDK down to handlers bold,
Parameters flow, defaults take hold,
Tests verify the story told! 🎨✨

🚥 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 and concisely summarizes the main change: allowing canvas_type in agent creation and update APIs.
Description check ✅ Passed The description addresses all required template sections: it explains the problem, identifies the bug fix type, and provides sufficient context.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@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: 1

🧹 Nitpick comments (1)
api/apps/restful_apis/agent_api.py (1)

613-617: ⚡ Quick win

Add minimal logs for the new canvas_type write path.

These changed create/update flows introduce new persistence behavior for canvas_type but don’t emit any audit/diagnostic log for it.

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

Also applies to: 870-874

🤖 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 613 - 617, Add minimal
audit/diagnostic logging for the new canvas_type write path in create_agent (and
the corresponding update function, e.g., update_agent): after you compute
req["canvas_type"] and before persisting, emit a concise log via the module
logger stating tenant_id, the canvas_type value, and whether it was defaulted
(e.g., empty/defaulted vs provided); do the same in the update flow where
canvas_type is written (lines ~870-874) so both create_agent and update_agent
record the canvas_type change. Ensure you use the existing module logger
variable and keep the log level informational/diagnostic.
🤖 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`:
- Around line 872-873: The handler is unconditionally overwriting stored fields
by defaulting req["canvas_type"] = "" and req["release"] =
bool(req.get("release", "")); change this so only provided fields are normalized
before persisting: do not set req["canvas_type"] unless "canvas_type" is present
in the incoming payload (i.e., check "canvas_type" in req before assigning), and
only coerce req["release"] to bool when "release" is present (e.g., if "release"
in req then convert to bool). Update the logic around the request normalization
that runs before the persistence call (the block that assigns to req and the
code that persists the agent) so absent fields are left out and thus not
overwritten in the stored agent.

---

Nitpick comments:
In `@api/apps/restful_apis/agent_api.py`:
- Around line 613-617: Add minimal audit/diagnostic logging for the new
canvas_type write path in create_agent (and the corresponding update function,
e.g., update_agent): after you compute req["canvas_type"] and before persisting,
emit a concise log via the module logger stating tenant_id, the canvas_type
value, and whether it was defaulted (e.g., empty/defaulted vs provided); do the
same in the update flow where canvas_type is written (lines ~870-874) so both
create_agent and update_agent record the canvas_type change. Ensure you use the
existing module logger variable and keep the log level informational/diagnostic.
🪄 Autofix (Beta)

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

Run ID: 9c096997-64b8-4ee0-ba6e-c5eff1041c15

📥 Commits

Reviewing files that changed from the base of the PR and between 5d022d8 and d1dcca6.

📒 Files selected for processing (3)
  • api/apps/restful_apis/agent_api.py
  • sdk/python/ragflow_sdk/ragflow.py
  • test/testcases/test_sdk_api/test_agent_management/test_agent_crud_unit.py

Comment on lines +872 to 873
req["canvas_type"] = req.get("canvas_type","")
req["release"] = bool(req.get("release", ""))

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid clearing canvas_type on partial updates.

At Line 872, defaulting canvas_type to "" means any PUT /agents/{agent_id} that does not send canvas_type will still overwrite the stored value when Line 895 persists req. This is a silent data-loss regression for normal title/description-only updates.

Suggested fix
 async def update_agent(agent_id, tenant_id):
     req = {k: v for k, v in (await get_request_json()).items() if v is not None}
-    req["canvas_type"] = req.get("canvas_type","")
     req["release"] = bool(req.get("release", ""))

Also applies to: 895-895

🤖 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 872 - 873, The handler is
unconditionally overwriting stored fields by defaulting req["canvas_type"] = ""
and req["release"] = bool(req.get("release", "")); change this so only provided
fields are normalized before persisting: do not set req["canvas_type"] unless
"canvas_type" is present in the incoming payload (i.e., check "canvas_type" in
req before assigning), and only coerce req["release"] to bool when "release" is
present (e.g., if "release" in req then convert to bool). Update the logic
around the request normalization that runs before the persistence call (the
block that assigns to req and the code that persists the agent) so absent fields
are left out and thus not overwritten in the stored agent.

@wangq8 wangq8 added the ci Continue Integration label May 26, 2026
@wangq8
wangq8 marked this pull request as draft May 26, 2026 02:47
@wangq8
wangq8 marked this pull request as ready for review May 26, 2026 02:48
@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (8d8ea71) to head (d1dcca6).
⚠️ Report is 25 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15201      +/-   ##
==========================================
+ Coverage   93.12%   93.16%   +0.03%     
==========================================
  Files          10       10              
  Lines         713      717       +4     
  Branches      116      118       +2     
==========================================
+ Hits          664      668       +4     
  Misses         29       29              
  Partials       20       20              

☔ View full report in Codecov by Sentry.
📢 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.

@wangq8
wangq8 merged commit 0d2a172 into infiniflow:main May 26, 2026
1 check passed
@huang-aoqin
huang-aoqin deleted the feature/agent-canvas-type branch May 27, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants