Skip to content

feat(agent): add Duplicate option to agent dropdown menu#14840

Open
plind-junior wants to merge 2 commits into
infiniflow:mainfrom
plind-junior:feat/duplicate-agent
Open

feat(agent): add Duplicate option to agent dropdown menu#14840
plind-junior wants to merge 2 commits into
infiniflow:mainfrom
plind-junior:feat/duplicate-agent

Conversation

@plind-junior
Copy link
Copy Markdown

What problem does this PR solve?

Closes #14769.

Currently the agents list dropdown only exposes Rename and Delete. Users
who want to create a variation of an existing agent have to either rebuild
from scratch or use the Export JSON → Import JSON workaround, which is a
two-step manual flow that is not discoverable.

This PR adds a Duplicate entry to the dropdown that clones the agent
in one click:

  • Fetches the source agent's full DSL via the existing GET /agents/<id>.
  • Resolves a non-colliding title (Copy of <name>, then (2), (3), …)
    client-side using the existing listAgents keyword search, so the
    backend's unique-title check at agent_api.py:449-454 is never hit
    on the happy path.
  • Calls the existing POST /agents with the same DSL + canvas_category
    • a fresh title. No backend changes.

Files changed

  • web/src/pages/agents/use-duplicate-agent.ts — new hook
  • web/src/pages/agents/agent-dropdown.tsx — dropdown entry, Copy icon,
    disabled while the create is in flight
  • web/src/locales/en.ts, web/src/locales/zh.ts — adds flow.duplicate,
    flow.copyOf, flow.duplicated, flow.duplicateFailed

Other locales fall back to the literal i18n key, matching the repo's
existing convention.

Test plan

  • Open /agents, click ⋯ on any agent → Duplicate
  • Verify a new agent appears titled Copy of <name> with the same DSL
  • Duplicate the same agent twice → second copy is titled Copy of <name> (2)
  • Duplicate a Dataflow-category agent → new agent retains
    canvas_category = dataflow_canvas
  • Open the new agent and confirm the graph, globals, and variables match

Type of change

  • New Feature (non-breaking change which adds functionality)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

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: 56ed7403-7eea-4d42-b5f7-9870b9dcd213

📥 Commits

Reviewing files that changed from the base of the PR and between 050f9d6 and 1eba8b1.

📒 Files selected for processing (1)
  • web/src/pages/agents/use-duplicate-agent.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/agents/use-duplicate-agent.ts

📝 Walkthrough

Walkthrough

Implements agent duplication: adds useDuplicateAgent (title collision handling, setAgent creation), integrates duplication into the agent dropdown UI, and adds English/Chinese locale keys for duplicate-related text.

Changes

Agent Duplication Feature

Layer / File(s) Summary
Agent duplication hook and title generation
web/src/pages/agents/use-duplicate-agent.ts
useDuplicateAgent and buildCopyTitle fetch full agent details, compute a collision-free copy title, create the duplicated agent via setAgent, and emit localized success/failure messages.
Dropdown menu integration
web/src/pages/agents/agent-dropdown.tsx
Adds Copy icon and useDuplicateAgent import, initializes hook state, defines handleDuplicate to call duplicateAgent, and adds a disabled-while-loading duplicate menu item (data-testid="agent-duplicate").
Duplication UI text
web/src/locales/en.ts, web/src/locales/zh.ts
Adds four translation keys: duplicate, copyOf, duplicated (with {{title}}), and duplicateFailed in English and Chinese locales.

Sequence Diagram(s)

sequenceDiagram
  participant UI as Agent Dropdown
  participant Hook as useDuplicateAgent
  participant AgentService as agentService
  participant Storage as setAgent
  UI->>Hook: duplicateAgent(id, title, canvas_category)
  Hook->>AgentService: getAgent(id)
  AgentService-->>Hook: agent details (incl. dsl)
  Hook->>AgentService: listAgents(canvas_category?)
  AgentService-->>Hook: existing agent titles
  Hook->>Hook: buildCopyTitle(base, taken)
  Hook->>Storage: setAgent(duplicated agent data)
  Storage-->>Hook: success
  Hook->>UI: show flow.duplicated ({{title}})
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

size:M

🐰 I hopped through code with nimble paws,
Cloned a flow with careful laws,
Titles that dodge a naming spat,
Click the dropdown — duplicate, like that!

🚥 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 summarizes the main change: adding a Duplicate option to the agent dropdown menu, which is the core feature of this PR.
Description check ✅ Passed The description fully addresses the template requirements with a clear problem statement, type of change selection, and comprehensive implementation details.
Linked Issues check ✅ Passed All coding requirements from #14769 are met: duplicate functionality added to agent list view, creates new agent with source configuration, and follows SaaS UX patterns.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the linked issue #14769: new duplicate hook, dropdown UI entry, and i18n strings are all required for the feature.

✏️ 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.

@plind-junior plind-junior marked this pull request as ready for review May 12, 2026 09:52
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 12, 2026
Closes infiniflow#14769. Adds a "Duplicate" entry to the agent list dropdown that
clones an agent's full DSL into a new one titled "Copy of <name>", with
collision-safe numeric suffixes resolved client-side via the existing
listAgents keyword search. No backend changes; reuses POST /agents.
@plind-junior plind-junior force-pushed the feat/duplicate-agent branch from b23de6c to 7493009 Compare May 12, 2026 09:57
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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 `@web/src/pages/agents/use-duplicate-agent.ts`:
- Around line 58-60: The code only shows success when result?.code === 0 and
ignores non-zero responses; update the duplicate flow in use-duplicate-agent.ts
to handle non-success responses from setAgent: after calling setAgent (the
variable `result`), if result?.code !== 0 show an error (e.g., message.error)
using result?.message or a translated fallback, and optionally log the result
and return early; keep the existing message.success path for result?.code === 0
so both success and failure paths provide user feedback.
- Line 53: When constructing the duplicate agent payload in
use-duplicate-agent.ts, replace the caller-supplied agent.canvas_category with
the canonical value fetched from getAgent (detail.canvas_category) so the
duplicate uses the authoritative category; update the object property assignment
where canvas_category is set (the place referencing agent.canvas_category) to
use detail.canvas_category instead and ensure detail is the fetched agent
returned by getAgent.
🪄 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: 86f5c373-cdfb-4e5a-9af2-7d7391c1fda9

📥 Commits

Reviewing files that changed from the base of the PR and between 7d38369 and b23de6c.

📒 Files selected for processing (4)
  • web/src/locales/en.ts
  • web/src/locales/zh.ts
  • web/src/pages/agents/agent-dropdown.tsx
  • web/src/pages/agents/use-duplicate-agent.ts

Comment thread web/src/pages/agents/use-duplicate-agent.ts Outdated
Comment thread web/src/pages/agents/use-duplicate-agent.ts
plind-junior added a commit to plind-junior/ragflow that referenced this pull request May 12, 2026
- Use detail.canvas_category from getAgent as canonical source, falling back to
  the caller-supplied value.
- Surface setAgent failures via message.error when code !== 0 so the duplicate
  flow no longer fails silently.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Use detail.canvas_category from getAgent as canonical source, falling back to
  the caller-supplied value.
- Surface setAgent failures via message.error when code !== 0 so the duplicate
  flow no longer fails silently.
@plind-junior plind-junior force-pushed the feat/duplicate-agent branch from 050f9d6 to 1eba8b1 Compare May 12, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add Copy Agent / Duplicate functionality in Agent creation UI

1 participant