Skip to content

feat: allow specifying custom agent_id when creating experts - #121

Open
miaowmint wants to merge 5 commits into
TencentCloud:developfrom
miaowmint:feature/custom-agent-id
Open

feat: allow specifying custom agent_id when creating experts#121
miaowmint wants to merge 5 commits into
TencentCloud:developfrom
miaowmint:feature/custom-agent-id

Conversation

@miaowmint

@miaowmint miaowmint commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

概述

允许用户在通过 API、CLI 和 Dashboard 创建 Expert(专家)/ Agent(智能体)时,自定义指定 Agent ID。

AgentCreateSpecAgentManager.create() 本身已经支持传入 agent_id 参数,但此前该能力并未对 API、CLI 用户以及 Dashboard 前端开放。本次修改将这一能力贯穿至所有入口,并增加了统一的输入校验。

变更内容

后端(Python)

文件 修改内容
src/octop/api/routers/agents.py AgentCreateBody 添加 agent_id 字段,并使用 Pydantic 进行校验(正则、长度、去除首尾空格)
src/octop/api/routers/experts.py FromExpertBody 添加 agent_id 字段,使用相同校验规则,并在创建流程中透传
src/octop/cli/commands/agent.py createfrom-expert 命令新增 --agent-id 参数
src/octop/infra/agents/experts/market_creation.py SkillHubMarketAgentCreateOptions 添加 agent_id 字段,并传递至创建配置

前端(TypeScript)

文件 修改内容
dashboard/src/.../CreateFromExpertDrawer.tsx 新增 Agent ID 输入框及表单校验
dashboard/src/.../ExpertMarketTab.tsx 在安装 Market Expert 前新增配置弹窗
dashboard/src/api/modules/expertMarket.ts CreateMarketExpertBody 添加 agent_id 字段
dashboard/src/locales/en.json 新增英文文案
dashboard/src/locales/zh.json 新增中文文案

校验规则

规则 行为
未填写 / 空值 自动生成随机 6 位 Crockford Base32 ID
仅包含空白字符 自动去除首尾空格,若为空则视为未填写
长度 1~64 个字符
格式 ^[a-zA-Z0-9][a-zA-Z0-9_-]*$
重复 ID AgentManager.create() 返回 AGENT_BUSY 错误

使用入口

路径 用法
POST /api/agents 请求体中传入 {"agent_id": "my-id"}
POST /api/agents/from-expert/{id} 请求体中传入 {"agent_id": "my-id"}
POST /api/experts/hub/{slug}/install 请求体中传入 {"agent_id": "my-id"}
octop agent create 使用 --agent-id my-id
octop agent from-expert 使用 --agent-id my-id
Dashboard:Built-in Experts 创建表单新增 Agent ID 输入框
Dashboard:Expert Market 安装前配置弹窗新增 Agent ID 输入框

Summary

Allow users to specify a custom ID when creating experts/agents via API, CLI, and dashboard UI.

The AgentCreateSpec and AgentManager.create() already support a user-provided agent_id parameter. However, this parameter was not exposed to API consumers, CLI users, or the dashboard frontend. This PR wires it through all layers and adds input validation.

Changes

Backend (Python)

File Change
src/octop/api/routers/agents.py Add agent_id field to AgentCreateBody with Pydantic validator (regex, length, trim)
src/octop/api/routers/experts.py Add agent_id field to FromExpertBody with same validator; pass through in create flows
src/octop/cli/commands/agent.py Add --agent-id option to create and from-expert commands
src/octop/infra/agents/experts/market_creation.py Add agent_id to SkillHubMarketAgentCreateOptions and pass to create spec

Frontend (TypeScript)

File Change
dashboard/src/.../CreateFromExpertDrawer.tsx Agent ID input field with form validation
dashboard/src/.../ExpertMarketTab.tsx Config modal before market install
dashboard/src/api/modules/expertMarket.ts Add agent_id to CreateMarketExpertBody type
dashboard/src/locales/en.json English translations
dashboard/src/locales/zh.json Chinese translations

Validation Rules

Rule Behavior
Omitted / empty Auto-generates random 6-char Crockford base32 ID
Whitespace-only Rejected (auto-trimmed on frontend)
Length 1-64 characters
Format ^[a-zA-Z0-9][a-zA-Z0-9_-]*$
Duplicate AGENT_BUSY error from AgentManager.create()

Entry Points

Path Usage
POST /api/agents {"agent_id": "my-id"} in body
POST /api/agents/from-expert/{id} {"agent_id": "my-id"} in body
POST /api/experts/hub/{slug}/install {"agent_id": "my-id"} in body
octop agent create --agent-id my-id
octop agent from-expert --agent-id my-id
Dashboard: Built-in Experts Input field in create form
Dashboard: Expert Market Config modal before install

@jubaoliang

Copy link
Copy Markdown
Collaborator

这个是否考虑加一个对输入id的规范校验?

- API: add agent_id field to AgentCreateBody, FromExpertBody, and pass to create specs
- CLI: add --agent-id option to 'octop agent create' and 'octop agent from-expert'
- Market creation: add agent_id to SkillHubMarketAgentCreateOptions
- Dashboard: add agent_id input field in CreateFromExpertDrawer form
- i18n: add English and Chinese translations for agent_id field

The agent_id is optional. When omitted, a random ID is auto-generated as before.
When provided, it must be unique or AGENT_BUSY error is returned.
Previously, clicking 'Install' on a market expert card immediately created
the agent with a random ID. Now a modal dialog is shown first, allowing the
user to optionally specify a custom agent ID before creation.

- ExpertMarketTab: replace direct createMarketExpert() calls with
  handleOpenCreateModal(), add Modal with Form for agent_id input
- expertMarket.ts: add CreateMarketExpertBody type import
- i18n: add marketCreateModalTitle and marketCreateModalHint keys
- Backend: Pydantic field_validator checks format (starts with alphanumeric,
  only letters/numbers/hyphens/underscores, 1-64 chars, auto-trim)
- Frontend: Ant Design form rule with pattern + length validation
- i18n: Chinese and English error messages for invalid/toolong cases
Move setCreateModalOpen(false) after createMarketExpert() completes
so the confirmLoading spinner actually shows during creation.
Also clean up pendingExpert after completion.
@miaowmint
miaowmint force-pushed the feature/custom-agent-id branch from 3595190 to 237c560 Compare August 1, 2026 05:53
@miaowmint

Copy link
Copy Markdown
Contributor Author

这个是否考虑加一个对输入id的规范校验?

加了,顺便给从市场安装专家的时候也改了,不直接安装,加了个自定义ID的输入框

Wrap long lines for --agent-id option decorators and from_expert
function signature to satisfy project line-length limit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants