feat(agents): allow custom agent ID when creating agents#3333
feat(agents): allow custom agent ID when creating agents#3333rayrayraykk merged 4 commits intoagentscope-ai:mainfrom
Conversation
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
|
Hi @flystar32, thank you for your first Pull Request! 🎉 📋 About PR TemplateTo help maintainers review your PR faster, please make sure to include:
Complete PR information helps speed up the review process. You can edit the PR description to add these details. 🙌 Join Developer CommunityThanks 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: We truly appreciate your enthusiasm—and look forward to your future contributions! 😊 We'll review your PR soon. |
There was a problem hiding this comment.
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
idin 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 customid. 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.
- 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
|
/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
There was a problem hiding this comment.
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.
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:
Thanks again for helping make QwenPaw better! |

Summary
Allow users to optionally specify a custom
idwhen 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: Addsanitize_agent_id()(strip whitespace) andvalidate_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 optionalidfield toCreateAgentRequestwith sanitize validator. Updatecreate_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: Addid?: stringtoCreateAgentRequest.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: AddidLabelandidHelpi18n 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 —
idis 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).