Skip to content

feat(agents): allow custom agent ID when creating agents#3333

Merged
rayrayraykk merged 4 commits intoagentscope-ai:mainfrom
flystar32:feat/custom-agent-id
Apr 16, 2026
Merged

feat(agents): allow custom agent ID when creating agents#3333
rayrayraykk merged 4 commits intoagentscope-ai:mainfrom
flystar32:feat/custom-agent-id

Conversation

@flystar32
Copy link
Copy Markdown
Contributor

@flystar32 flystar32 commented Apr 13, 2026

Summary

Allow users to optionally specify a custom id when creating an agent via the API or Console. When omitted, the existing random short UUID behavior is preserved.

Closes #3325

Changes

Backend

  • src/qwenpaw/config/config.py: Add sanitize_agent_id() (strip whitespace) and validate_agent_id() with pattern [a-zA-Z0-9][a-zA-Z0-9_-]*[a-zA-Z0-9], length 2–64, reserved ID rejection, and duplicate check. Agent IDs are case-sensitive.
  • src/qwenpaw/app/routers/agents.py: Add optional id field to CreateAgentRequest with sanitize validator. Update create_agent() to use custom ID when provided, otherwise generate random ID via _generate_unique_id() helper. Update route description.

Frontend

  • console/src/api/types/agents.ts: Add id?: string to CreateAgentRequest.
  • console/src/pages/Settings/Agents/components/AgentModal.tsx: Add optional ID input in create mode with client-side regex validation.
  • console/src/locales/{en,zh,ja,ru}.json: Add idLabel and idHelp i18n keys.

Tests

  • tests/unit/workspace/test_agent_id.py: Add 21 new test cases covering sanitization, valid/invalid patterns (including mixed-case), length limits, reserved IDs, and duplicate rejection. All 24 tests pass.

Backward Compatibility

Fully backward compatible — id is optional, existing agents with random IDs are unaffected, no migration needed. Case-sensitivity is preserved to stay consistent with existing auto-generated IDs (shortuuid uses mixed-case characters).

Add optional 'id' field to CreateAgentRequest. When provided, the ID is
validated (lowercase alphanumeric, hyphens, underscores, 2-64 chars) and
used as the agent identifier. When omitted, a random short UUID is
generated as before.

Changes:
- Add sanitize_agent_id() and validate_agent_id() in config.py
- Update CreateAgentRequest and create_agent() in agents.py
- Add id field to frontend TypeScript types
- Add ID input in AgentModal create mode with client-side validation
- Add i18n keys (en/zh/ja/ru) for ID label and help text
- Add 21 new test cases for sanitization and validation
Copilot AI review requested due to automatic review settings April 13, 2026 09:18
@github-project-automation github-project-automation bot moved this to Todo in QwenPaw Apr 13, 2026
@flystar32 flystar32 requested a deployment to maintainer-approved April 13, 2026 09:18 — with GitHub Actions Waiting
@github-actions github-actions bot added the first-time-contributor PR created by a first time contributor label Apr 13, 2026
@github-actions
Copy link
Copy Markdown

Welcome to QwenPaw! 🐾

Hi @flystar32, thank you for your first Pull Request! 🎉

📋 About PR Template

To help maintainers review your PR faster, please make sure to include:

  • Description - What this PR does and why
  • Type of Change - Bug fix / Feature / Breaking change / Documentation / Refactoring
  • Component(s) Affected - Core / Console / Channels / Skills / CLI / Documentation / Tests / CI/CD / Scripts
  • Checklist:
    • Run and pass pre-commit run --all-files
    • Run and pass relevant tests (pytest or as applicable)
    • Update documentation if needed
  • Testing - How to test these changes
  • Local Verification Evidence:
    pre-commit run --all-files
    # paste summary result
    
    pytest
    # paste summary result

Complete PR information helps speed up the review process. You can edit the PR description to add these details.

🙌 Join Developer Community

Thanks so much for your contribution! We'd love to invite you to join the official QwenPaw developer group! You can find the Discord and DingTalk group links under the "Developer Community" section on our docs page:
https://qwenpaw.agentscope.io/docs/community

We truly appreciate your enthusiasm—and look forward to your future contributions! 😊

We'll review your PR soon.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for user-specified agent IDs during agent creation (API + Console) while preserving the existing server-generated short UUID behavior when no ID is provided.

Changes:

  • Backend: introduce agent ID sanitization/validation helpers and allow optional id in the create-agent request (fallback to generated unique ID).
  • Frontend: extend create-agent request typing and add an optional “Agent ID” input with client-side validation.
  • Tests: expand unit tests to cover sanitization/validation behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/qwenpaw/config/config.py Adds sanitize_agent_id() / validate_agent_id() and ID validation constants/regex.
src/qwenpaw/app/routers/agents.py Extends create-agent API to accept optional id and centralizes unique-ID generation.
console/src/api/types/agents.ts Adds optional id to CreateAgentRequest.
console/src/pages/Settings/Agents/components/AgentModal.tsx Adds optional Agent ID input in create mode with regex rule.
tests/unit/workspace/test_agent_id.py Adds tests for sanitization/validation behaviors.
console/src/locales/en.json Adds i18n strings for optional Agent ID field/help.
console/src/locales/zh.json Adds i18n strings for optional Agent ID field/help.
console/src/locales/ja.json Adds i18n strings for optional Agent ID field/help.
console/src/locales/ru.json Adds i18n strings for optional Agent ID field/help.
Comments suppressed due to low confidence (1)

src/qwenpaw/app/routers/agents.py:289

  • The OpenAPI route metadata still says the agent ID is auto-generated by the server (description="Create a new agent (ID is auto-generated by server)"), but this endpoint now accepts an optional custom id. Please update the route description/summary to avoid misleading API/Console users.
@router.post(
    "",
    response_model=AgentProfileRef,
    status_code=201,
    summary="Create new agent",
    description="Create a new agent (ID is auto-generated by server)",
)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/qwenpaw/config/config.py Outdated
Comment thread tests/unit/workspace/test_agent_id.py Outdated
Comment thread console/src/pages/Settings/Agents/components/AgentModal.tsx Outdated
Comment thread src/qwenpaw/config/config.py
- Remove single-char alternative from _AGENT_ID_PATTERN to match min length 2
- Update route description to reflect optional custom ID support
- Align frontend regex with backend (require min 2 chars)
- Remove misleading single-char 'x' test case
@flystar32 flystar32 requested a deployment to maintainer-approved April 13, 2026 09:37 — with GitHub Actions Waiting
@xieyxclack xieyxclack requested a review from rayrayraykk April 13, 2026 09:43
@xieyxclack
Copy link
Copy Markdown
Member

/gemini review

Auto-generated agent IDs from shortuuid contain mixed-case characters.
Forcing lowercase would break consistency with existing IDs.

- Change ID pattern from [a-z0-9] to [a-zA-Z0-9]
- sanitize_agent_id() now only strips whitespace, no longer lowercases
- Update frontend regex and i18n to remove 'lowercase' constraint
- Update tests: add mixed-case valid IDs, remove UPPER from invalid
Copilot AI review requested due to automatic review settings April 15, 2026 02:57
@flystar32 flystar32 requested a deployment to maintainer-approved April 15, 2026 02:57 — with GitHub Actions Waiting
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread console/src/pages/Settings/Agents/components/AgentModal.tsx
Comment thread src/qwenpaw/config/config.py
Comment thread src/qwenpaw/config/config.py
Comment thread src/qwenpaw/app/routers/agents.py
@flystar32 flystar32 temporarily deployed to maintainer-approved April 16, 2026 03:03 — with GitHub Actions Inactive
Copy link
Copy Markdown
Member

@rayrayraykk rayrayraykk left a comment

Choose a reason for hiding this comment

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

LGTM

@rayrayraykk rayrayraykk merged commit aad1004 into agentscope-ai:main Apr 16, 2026
14 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in QwenPaw Apr 16, 2026
@github-actions
Copy link
Copy Markdown

Welcome to QwenPaw! 🎉

Thank you @flystar32 for your first contribution! Your PR has been merged. 🚀

We'd love to give you a shout-out in our release notes! If you're comfortable sharing, please reply to this comment with your social media handles using the format below:

discord: your_discord_handle
x: your_x_handle
xiaohongshu: your_xiaohongshu_id

Note: Only share what you're comfortable with — all fields are optional.

Thanks again for helping make QwenPaw better!

shaojun pushed a commit to shaojun/QwenPaw that referenced this pull request Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first-time-contributor PR created by a first time contributor Under Review

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

feat: Allow custom Agent ID when creating agents

4 participants