更新Agent
更新时间:2026-11-24
接口说明
- 本接口用于更新一个已存在的 Agent 定义,覆盖 description、spec 及编译产物,version 服务端自增。
- 目标 Agent 不存在时返回 404 AgentDefNotFound,不会新建。
- 不支持修改 metadata.name,它是稳定业务键。
- 仅 status=created 的 Agent 可更新:creating 返回 409 AgentDefNotReady,failed 返回 409 AgentDefFailed,deleting 返回 404。更新只影响之后新建的会话。
- spec 的字段结构与「创建Agent」完全一致。spec.network 不接受 crossVpc,只接受 allowInternetAccess、allowOut、denyOut,因为跨 VPC 只在创建时声明。
请求结构
Plain Text
1POST /v1/agents/update HTTP/1.1
2Host: aw-harness.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "agentId": "ag-7f3c9b2e",
7 "metadata": {
8 "name": "my-agent",
9 "description": "更新后的描述"
10 },
11 "spec": {
12 "harnessType": "opencode",
13 "harnessVersion": "1.18.29",
14 "model": {
15 "modelId": "deepseek-v4.1-flash",
16 "baseURL": "https://your-gateway.example.com/v1",
17 "params": {
18 "temperature": 0.7,
19 "topP": 0.9
20 }
21 },
22 "systemPrompt": "你是 {{name}},请帮助用户完成任务。",
23 "skills": ["registry://nsk-example/skill-example@1.0.1"],
24 "setupScript": "export FOO=bar",
25 "capabilities": ["docx"],
26 "limits": {
27 "maxLifetime": "2h",
28 "idleTimeout": "30m"
29 },
30 "network": {
31 "allowInternetAccess": false,
32 "allowOut": ["203.0.113.0/24"],
33 "denyOut": ["198.51.100.0/24"]
34 },
35 "memorySpaces": [
36 {
37 "memorySpaceId": "ms-xxxx",
38 "accessMode": "read_write"
39 }
40 ],
41 "mcpServers": ["mcp-xxxx"],
42 "harnessConfig": {
43 "tools": {
44 "builtin": ["bash", "file_ops"],
45 "deny": ["web_fetch"],
46 "bash": {
47 "go test *": "allow"
48 }
49 }
50 }
51 }
52}
请求头域
除公共头域外,无其它特殊头域。
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
|---|---|---|---|---|
| agentId | String | 否 | RequestBody参数 | 可选定位断言(ag- 前缀),与 metadata.name 合取。同时提供时二者必须指向同一条定义,对不上返回 404;按 agentId 能找到但 metadata.name 与当前不一致时返回 400 InvalidArgument,details[].field 为 metadata.name。 |
| metadata | Metadata | 是 | RequestBody参数 | Agent 元数据,结构同「创建Agent」。 |
| spec | Spec | 是 | RequestBody参数 | Agent 业务定义,字段结构、取值约束与「创建Agent」完全一致,仅 spec.network 不接受 crossVpc。 |
返回头域
除公共头域,无其它特殊头域。
返回参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| agentId | String | 平台分配的资源 ID,ag- 前缀。更新时保持不变。 |
| agentName | String | Agent 名称。 |
| version | Long | 配置版本号,本次更新后自增。 |
| harnessType | String | 内核类型。 |
| status | String | Agent 状态,保持更新前的值。 |
错误码
| 错误码 | 错误描述 | HTTP状态码 | 中文解释 |
|---|---|---|---|
| InvalidArgument | The request parameters are invalid. | 400 | 请求参数不合法,如字段取值非法、metadata.name 与 agentId 指向不一致、请求体含未识别字段。字段错误可通过 details[].field 定位。 |
| Forbidden | Operation requires an admin caller. | 403 | 缺少鉴权账号、跨账号访问他人资源,或携带 Actor 头调用仅限管理员的写接口。 |
| AgentDefNotFound | Agent def not found. | 404 | 目标 Agent 不存在,或 name 与 agentId 合取不匹配。 |
| AgentDefNotReady | Agent def is not ready. | 409 | Agent 处于 creating 状态,稍后重试。 |
| AgentDefFailed | Agent def creation failed. | 409 | Agent 处于 failed 状态,需删除后重建。 |
| PersistFailed | Failed to persist the agent def. | 500 | 服务端存储读写失败,可重试。 |
| Internal | Internal server error. | 500 | 服务端内部错误,保留 requestId 联系维护方。 |
请求示例
Plain Text
1POST http://aw-harness.bj.baidubce.com/v1/agents/update
2Host: aw-harness.bj.baidubce.com
3Authorization: bce-auth-v1/f81d3b34e48048fbb2634dc7882d7e21/2015-08-11T04:17:29Z/3600/host/74c506f68c65e26c633bfa104c863fffac5190fdec1ec24b7c03eb5d67d2e1de
4Content-Type: application/json
5
6{
7 "agentId": "ag-7f3c9b2e",
8 "metadata": {
9 "name": "my-agent",
10 "description": "更新后的描述"
11 },
12 "spec": {
13 "harnessType": "opencode",
14 "model": {
15 "modelId": "deepseek-v4.1-flash"
16 },
17 "systemPrompt": "你是 {{name}},请帮助用户完成任务。"
18 }
19}
返回示例
Plain Text
1HTTP/1.1 200 OK
2Content-Type: application/json;charset=UTF-8
3x-bce-request-id: 9f3d0e6a-1c2b-4d5e-8a7f-0b1c2d3e4f5a
4Server: BWS
5
6{
7 "result": {
8 "agentId": "ag-7f3c9b2e",
9 "agentName": "my-agent",
10 "version": 2,
11 "harnessType": "opencode",
12 "status": "created"
13 },
14 "requestId": "9f3d0e6a-1c2b-4d5e-8a7f-0b1c2d3e4f5a"
15}
评价此篇文章
