Repository navigation
fix(api): allow canvas_type in agent create and update APIs - #15201
Conversation
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]>
📝 WalkthroughWalkthroughThis pull request adds ChangesAgent Canvas Type Support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
api/apps/restful_apis/agent_api.py (1)
613-617: ⚡ Quick winAdd minimal logs for the new
canvas_typewrite path.These changed create/update flows introduce new persistence behavior for
canvas_typebut 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
📒 Files selected for processing (3)
api/apps/restful_apis/agent_api.pysdk/python/ragflow_sdk/ragflow.pytest/testcases/test_sdk_api/test_agent_management/test_agent_crud_unit.py
| req["canvas_type"] = req.get("canvas_type","") | ||
| req["release"] = bool(req.get("release", "")) |
There was a problem hiding this comment.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
Creating or updating an agent via
POST /api/v1/agentsandPUT /api/v1/agents/{agent_id}did not persistcanvas_typebecause the handlerreqdict never assigned the field beforeUserCanvasService.save/update_by_id.Type of change