nexus-agentd 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -15
- package/dist/a2a/runtime.d.ts +2 -0
- package/dist/a2a/runtime.js +9 -1
- package/dist/acp/runtime.d.ts +3 -1
- package/dist/acp/runtime.js +10 -2
- package/dist/agent-instructions.d.ts +11 -0
- package/dist/agent-instructions.js +44 -0
- package/dist/config.js +3 -0
- package/dist/control-plane.d.ts +1 -0
- package/dist/control-plane.js +17 -0
- package/dist/server.js +2 -0
- package/dist/session.js +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/webui/app.js +2 -0
- package/nexus-agentd.example.json +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,22 +11,23 @@ Agent,并向 Koishi AgentNexus 或其他客户端提供 HTTP/SSE API。管理
|
|
|
11
11
|
|
|
12
12
|
## 快速开始
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
当前稳定版本已发布到 npm,推荐按下面的 npm 流程启动;如果要运行 GitHub 上尚未发布的分支代码,
|
|
15
|
+
再使用下方的源码部署方式。首次初始化、systemd 和 Agent 准备的完整说明见下文。
|
|
15
16
|
|
|
16
17
|
```bash
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
NPM_CONFIG_PREFIX="$HOME/.local"
|
|
19
|
+
npm install --global --prefix "$NPM_CONFIG_PREFIX" nexus-agentd@latest
|
|
20
|
+
export PATH="$NPM_CONFIG_PREFIX/bin:$PATH"
|
|
19
21
|
mkdir -p "$HOME/.config/agent-nexus" "$HOME/projects"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
--port 8787 \
|
|
26
|
-
--workspace "$HOME/projects"
|
|
22
|
+
nexus-agentd \
|
|
23
|
+
--config "$HOME/.config/agent-nexus/nexus-agentd.json" \
|
|
24
|
+
--host 0.0.0.0 \
|
|
25
|
+
--port 8787 \
|
|
26
|
+
--workspace "$HOME/projects"
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
当前仓库版本 `0.1.6` 已发布到 npm;可用 `npm view nexus-agentd version` 检查 registry 的 latest,
|
|
30
|
+
也可以将安装命令固定为 `nexus-agentd@0.1.6`。
|
|
30
31
|
|
|
31
32
|
## 安装与部署
|
|
32
33
|
|
|
@@ -41,15 +42,15 @@ Gateway 不会替你安装 Agent,也不会替你执行 OpenCode、Claude Code
|
|
|
41
42
|
|
|
42
43
|
### npm 包安装(已发布版本)
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
`0.1.6` 已发布到 npm。目标版本尚未发布时,请使用下面的源码部署,或将本仓库打包后的 tarball 安装到目标机器。
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
发布状态可用 `npm view nexus-agentd version` 检查;生产环境需要可复现部署时,建议固定为 `nexus-agentd@0.1.6`。
|
|
47
48
|
|
|
48
49
|
生产环境建议使用专用的低权限系统用户,并把 npm 全局包安装到用户目录:
|
|
49
50
|
|
|
50
51
|
~~~bash
|
|
51
52
|
NPM_CONFIG_PREFIX="$HOME/.local"
|
|
52
|
-
npm install --global --prefix "$NPM_CONFIG_PREFIX" nexus-agentd
|
|
53
|
+
npm install --global --prefix "$NPM_CONFIG_PREFIX" nexus-agentd@0.1.6
|
|
53
54
|
export PATH="$NPM_CONFIG_PREFIX/bin:$PATH"
|
|
54
55
|
~~~
|
|
55
56
|
|
|
@@ -129,7 +130,7 @@ curl http://127.0.0.1:8787/health
|
|
|
129
130
|
绝对路径加上 `dist/cli.js`,例如:`/usr/bin/node %h/nexus-gateway/dist/cli.js --config
|
|
130
131
|
%h/.config/agent-nexus/nexus-agentd.json`。不要在 systemd 中依赖交互式 Shell 的 nvm 初始化。
|
|
131
132
|
|
|
132
|
-
###
|
|
133
|
+
### 源码部署(开发分支或未发布版本)
|
|
133
134
|
|
|
134
135
|
源码部署适合当前仓库和尚未发布到 npm 的版本;生产环境请使用外部进程管理器负责守护,
|
|
135
136
|
不要把运行数据、Artifact 仓库或密钥放进 Git 工作树:
|
|
@@ -268,6 +269,12 @@ command -v hermes && hermes acp --check
|
|
|
268
269
|
|
|
269
270
|
`workspace` 必须位于 `workspaceRoots` 之下;如果只通过 WebUI 配置,Gateway 会校验并保存这些字段。
|
|
270
271
|
|
|
272
|
+
Gateway 会在每个 Agent Session 的首次请求前自动注入一段 Agent Nexus 交互规范,提醒 Agent 在需要
|
|
273
|
+
用户选择、确认、支付或补充信息时使用 ACP elicitation/A2A `input-required`,不要只输出普通文本问题。
|
|
274
|
+
这段规范不需要为 OpenCode、Claude Code 或 Hermes 手工重复配置。若某个 Agent 还需要额外规则,可在 Agent
|
|
275
|
+
配置中增加 `instructions`;它会在内置规范之后追加,并限制为最多 32768 个字符。提示词注入只是行为约定,
|
|
276
|
+
Agent 仍必须实际支持相应的 ACP/A2A/MCP 用户输入机制,Gateway 不会把普通文本自动猜成等待状态。
|
|
277
|
+
|
|
271
278
|
### A2A
|
|
272
279
|
|
|
273
280
|
A2A 使用官方 `@a2a-js/sdk` 客户端,通过完整的 Agent Card URL 发现名称、能力和实际调用地址,
|
|
@@ -279,6 +286,7 @@ A2A 使用官方 `@a2a-js/sdk` 客户端,通过完整的 Agent Card URL 发现
|
|
|
279
286
|
{
|
|
280
287
|
"protocol": "a2a",
|
|
281
288
|
"name": "Research Agent",
|
|
289
|
+
"instructions": "需要用户确认时保持任务等待,并使用 Agent 的 input-required 能力。",
|
|
282
290
|
"agentCardUrl": "http://192.168.1.20:8080/.well-known/agent-card.json",
|
|
283
291
|
"preferredTransport": "auto",
|
|
284
292
|
"auth": {
|
|
@@ -329,6 +337,27 @@ HTTP 上传总上限由 `maxAttachmentBytes` 控制,默认 32 MiB,允许调
|
|
|
329
337
|
24 小时。上传和复制均使用流,不把文件编码进 JSON;公开 URL 使用 256 位随机 token,过期文件由
|
|
330
338
|
后台清理。ACP/A2A 返回的内联二进制 Artifact 也会先落入该仓库,再在 Session 响应中改为 URL。
|
|
331
339
|
|
|
340
|
+
### 多轮输入与确认
|
|
341
|
+
|
|
342
|
+
ACP elicitation、ACP permission request 和 A2A `input_required` 都会让 Session 进入等待状态,并在
|
|
343
|
+
Session 响应的 `pendingRequest` 中返回等待提示和可选项。客户端只需重复调用同一个
|
|
344
|
+
`POST /v1/sessions/:id/message`:
|
|
345
|
+
|
|
346
|
+
~~~text
|
|
347
|
+
POST /v1/sessions/:id/message
|
|
348
|
+
{"message":"第一个"}
|
|
349
|
+
~~~
|
|
350
|
+
|
|
351
|
+
Gateway 会复用原来的协议 Session/Task/Context,不会创建新任务。Agent 可以在下一轮再次进入
|
|
352
|
+
`input_required`,因此套餐选择、堂食方式、取餐时间和支付完成可以组成一条连续流程。需要表达业务
|
|
353
|
+
步骤时,可在 `pendingRequest` 中提供可选的 `step`、`inputType` 和 JSON-safe `metadata`;这些字段
|
|
354
|
+
不应放入密钥或其他敏感信息。支付完成消息仍必须由上游 MCP 根据订单/支付状态核验,不能只信任用户文本。
|
|
355
|
+
|
|
356
|
+
对 ACP Agent,Gateway 会在 Session 首次 prompt 前注入内置交互规范;对 A2A Agent,则把同一规范放在首个
|
|
357
|
+
用户消息的前缀中。由于 A2A/ACP 的 system-message 能力在不同 Agent 实现中并不统一,这是一种兼容性更好的
|
|
358
|
+
宿主提示方式。它不能替代 Agent 对 elicitation 或 `input-required` 的实现:Agent 必须真正发起协议级等待,
|
|
359
|
+
Gateway 才能暂停 Session 并在用户回复后继续。
|
|
360
|
+
|
|
332
361
|
API Key 与 A2A 认证值支持 `env:VAR`。Console Password 哈希由 WebUI 管理,不要手工生成或把
|
|
333
362
|
旧 `authToken` 复制到该字段。
|
|
334
363
|
|
package/dist/a2a/runtime.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export declare class A2AClientRuntime implements AgentSessionRuntime {
|
|
|
10
10
|
private taskId;
|
|
11
11
|
private contextId;
|
|
12
12
|
private prompting;
|
|
13
|
+
private firstPrompt;
|
|
14
|
+
private readonly instructions;
|
|
13
15
|
private disposed;
|
|
14
16
|
private activeController?;
|
|
15
17
|
private readonly artifactCache;
|
package/dist/a2a/runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { Role, TaskState } from '@a2a-js/sdk';
|
|
3
3
|
import { ClientFactory, DefaultAgentCardResolver, JsonRpcTransportFactory, RestTransportFactory } from '@a2a-js/sdk/client';
|
|
4
|
+
import { buildAgentInstructions, composeInitialAgentPrompt } from '../agent-instructions.js';
|
|
4
5
|
export async function probeA2AAgent(id, config) {
|
|
5
6
|
const startedAt = Date.now();
|
|
6
7
|
if (config.enabled === false)
|
|
@@ -43,6 +44,8 @@ export class A2AClientRuntime {
|
|
|
43
44
|
taskId = '';
|
|
44
45
|
contextId = '';
|
|
45
46
|
prompting = false;
|
|
47
|
+
firstPrompt = true;
|
|
48
|
+
instructions;
|
|
46
49
|
disposed = false;
|
|
47
50
|
activeController;
|
|
48
51
|
artifactCache = new Map();
|
|
@@ -51,6 +54,7 @@ export class A2AClientRuntime {
|
|
|
51
54
|
this.config = config;
|
|
52
55
|
this.sink = sink;
|
|
53
56
|
this.promptTimeoutMs = promptTimeoutMs;
|
|
57
|
+
this.instructions = buildAgentInstructions(config.instructions);
|
|
54
58
|
}
|
|
55
59
|
async start() {
|
|
56
60
|
const resolver = createResolver(this.config);
|
|
@@ -78,12 +82,16 @@ export class A2AClientRuntime {
|
|
|
78
82
|
this.prompting = true;
|
|
79
83
|
this.sink.clearPending();
|
|
80
84
|
this.sink.setState('running');
|
|
85
|
+
const promptMessage = this.firstPrompt
|
|
86
|
+
? composeInitialAgentPrompt(this.instructions, message)
|
|
87
|
+
: message;
|
|
88
|
+
this.firstPrompt = false;
|
|
81
89
|
const controller = new AbortController();
|
|
82
90
|
this.activeController = controller;
|
|
83
91
|
const timer = setTimeout(() => controller.abort(new Error('A2A message timed out')), Math.min(this.promptTimeoutMs, this.config.timeoutMs || this.promptTimeoutMs));
|
|
84
92
|
timer.unref?.();
|
|
85
93
|
try {
|
|
86
|
-
const request = this.messageRequest(
|
|
94
|
+
const request = this.messageRequest(promptMessage, attachments);
|
|
87
95
|
for await (const response of this.client.sendMessageStream(request, {
|
|
88
96
|
signal: controller.signal
|
|
89
97
|
})) {
|
package/dist/acp/runtime.d.ts
CHANGED
|
@@ -12,9 +12,11 @@ export declare class AcpProcessRuntime {
|
|
|
12
12
|
private prompting;
|
|
13
13
|
private readonly maxStderrChunkChars;
|
|
14
14
|
private readonly promptTimeoutMs;
|
|
15
|
+
private readonly instructions;
|
|
16
|
+
private firstPrompt;
|
|
15
17
|
private promptCapabilities;
|
|
16
18
|
private inputDirectory?;
|
|
17
|
-
constructor(driver: AgentDriver, sink: AcpSessionSink, maxStderrChunkChars?: number, promptTimeoutMs?: number);
|
|
19
|
+
constructor(driver: AgentDriver, sink: AcpSessionSink, maxStderrChunkChars?: number, promptTimeoutMs?: number, customInstructions?: string);
|
|
18
20
|
start(workspace: string): Promise<void>;
|
|
19
21
|
prompt(message: string, attachments?: AgentdInputAttachment[]): Promise<void>;
|
|
20
22
|
respondPending(message: string, _attachments?: AgentdInputAttachment[]): Promise<void>;
|
package/dist/acp/runtime.js
CHANGED
|
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import { Readable, Writable } from 'node:stream';
|
|
5
5
|
import { pathToFileURL } from 'node:url';
|
|
6
6
|
import * as acp from '@agentclientprotocol/sdk';
|
|
7
|
+
import { buildAgentInstructions, composeInitialAgentPrompt } from '../agent-instructions.js';
|
|
7
8
|
export class AcpProcessRuntime {
|
|
8
9
|
driver;
|
|
9
10
|
sink;
|
|
@@ -15,9 +16,11 @@ export class AcpProcessRuntime {
|
|
|
15
16
|
prompting = false;
|
|
16
17
|
maxStderrChunkChars;
|
|
17
18
|
promptTimeoutMs;
|
|
19
|
+
instructions;
|
|
20
|
+
firstPrompt = true;
|
|
18
21
|
promptCapabilities = {};
|
|
19
22
|
inputDirectory;
|
|
20
|
-
constructor(driver, sink, maxStderrChunkChars = 16 * 1024, promptTimeoutMs = 30 * 60 * 1000) {
|
|
23
|
+
constructor(driver, sink, maxStderrChunkChars = 16 * 1024, promptTimeoutMs = 30 * 60 * 1000, customInstructions) {
|
|
21
24
|
this.driver = driver;
|
|
22
25
|
this.sink = sink;
|
|
23
26
|
const limit = Number.isFinite(maxStderrChunkChars)
|
|
@@ -25,6 +28,7 @@ export class AcpProcessRuntime {
|
|
|
25
28
|
: 16 * 1024;
|
|
26
29
|
this.maxStderrChunkChars = Math.max(1, Math.min(16 * 1024, limit));
|
|
27
30
|
this.promptTimeoutMs = Math.max(10_000, Math.trunc(promptTimeoutMs));
|
|
31
|
+
this.instructions = buildAgentInstructions(customInstructions);
|
|
28
32
|
}
|
|
29
33
|
async start(workspace) {
|
|
30
34
|
if (this.process)
|
|
@@ -86,10 +90,14 @@ export class AcpProcessRuntime {
|
|
|
86
90
|
this.prompting = true;
|
|
87
91
|
this.sink.clearPending();
|
|
88
92
|
this.sink.setState('running');
|
|
93
|
+
const promptMessage = this.firstPrompt
|
|
94
|
+
? composeInitialAgentPrompt(this.instructions, message)
|
|
95
|
+
: message;
|
|
96
|
+
this.firstPrompt = false;
|
|
89
97
|
try {
|
|
90
98
|
const response = await withTimeout(this.connection.agent.request(acp.methods.agent.session.prompt, {
|
|
91
99
|
sessionId,
|
|
92
|
-
prompt: await this.promptBlocks(
|
|
100
|
+
prompt: await this.promptBlocks(promptMessage, attachments)
|
|
93
101
|
}), this.promptTimeoutMs, 'ACP prompt timed out');
|
|
94
102
|
if (this.sink.state === 'canceled' || this.sink.state === 'failed') {
|
|
95
103
|
return;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const MAX_AGENT_INSTRUCTIONS_CHARS: number;
|
|
2
|
+
/**
|
|
3
|
+
* Baseline guidance for Agents running behind Agent Nexus.
|
|
4
|
+
*
|
|
5
|
+
* This is delivered as the first prompt because ACP and A2A do not expose a
|
|
6
|
+
* portable system-message field across all supported Agent implementations.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_AGENT_INSTRUCTIONS: string;
|
|
9
|
+
export declare function normalizeAgentInstructions(value: unknown, field?: string): string | undefined;
|
|
10
|
+
export declare function buildAgentInstructions(custom?: string): string;
|
|
11
|
+
export declare function composeInitialAgentPrompt(instructions: string, userMessage: string): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export const MAX_AGENT_INSTRUCTIONS_CHARS = 32 * 1024;
|
|
2
|
+
/**
|
|
3
|
+
* Baseline guidance for Agents running behind Agent Nexus.
|
|
4
|
+
*
|
|
5
|
+
* This is delivered as the first prompt because ACP and A2A do not expose a
|
|
6
|
+
* portable system-message field across all supported Agent implementations.
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_AGENT_INSTRUCTIONS = [
|
|
9
|
+
'You are running behind the Agent Nexus conversational host.',
|
|
10
|
+
'When an external tool or operation needs the user to choose, confirm, authorize, pay, or provide more information before it can continue:',
|
|
11
|
+
'1. Do not present the task as completed.',
|
|
12
|
+
'2. Use the host\'s native user-input, elicitation, or permission request mechanism when available; do not only print a normal-text question and stop.',
|
|
13
|
+
'3. Include a concise prompt and structured options when the mechanism supports them. For payment, include the payment URL and stable order metadata.',
|
|
14
|
+
'4. After the user replies, validate the result with the upstream tool. Never treat a message such as "payment completed" as proof that payment succeeded.',
|
|
15
|
+
'Only finish the task after the external operation has actually completed.'
|
|
16
|
+
].join('\n');
|
|
17
|
+
export function normalizeAgentInstructions(value, field = 'instructions') {
|
|
18
|
+
if (value === undefined || value === null)
|
|
19
|
+
return undefined;
|
|
20
|
+
if (typeof value !== 'string')
|
|
21
|
+
throw new Error(`${field} must be a string`);
|
|
22
|
+
const text = value.trim();
|
|
23
|
+
if (text.length > MAX_AGENT_INSTRUCTIONS_CHARS) {
|
|
24
|
+
throw new Error(`${field} must be at most ${MAX_AGENT_INSTRUCTIONS_CHARS} characters`);
|
|
25
|
+
}
|
|
26
|
+
return text || undefined;
|
|
27
|
+
}
|
|
28
|
+
export function buildAgentInstructions(custom) {
|
|
29
|
+
const extra = normalizeAgentInstructions(custom);
|
|
30
|
+
return extra
|
|
31
|
+
? `${DEFAULT_AGENT_INSTRUCTIONS}\n\nAdditional agent-specific instructions:\n${extra}`
|
|
32
|
+
: DEFAULT_AGENT_INSTRUCTIONS;
|
|
33
|
+
}
|
|
34
|
+
export function composeInitialAgentPrompt(instructions, userMessage) {
|
|
35
|
+
return [
|
|
36
|
+
'<agent-nexus-host-instructions>',
|
|
37
|
+
instructions,
|
|
38
|
+
'</agent-nexus-host-instructions>',
|
|
39
|
+
'',
|
|
40
|
+
'<user-request>',
|
|
41
|
+
userMessage,
|
|
42
|
+
'</user-request>'
|
|
43
|
+
].join('\n');
|
|
44
|
+
}
|
package/dist/config.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mkdir, open, readFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { normalizeAgentInstructions } from './agent-instructions.js';
|
|
3
4
|
import { agentdDriverKinds } from './types.js';
|
|
4
5
|
export async function ensureAgentdConfig(filePath, options = {}) {
|
|
5
6
|
const absolute = path.resolve(filePath);
|
|
@@ -148,6 +149,7 @@ function parseAgent(id, value) {
|
|
|
148
149
|
driver,
|
|
149
150
|
name: optionalString(input.name, `agents.${id}.name`),
|
|
150
151
|
description: optionalString(input.description, `agents.${id}.description`),
|
|
152
|
+
instructions: normalizeAgentInstructions(input.instructions, `agents.${id}.instructions`),
|
|
151
153
|
enabled: optionalBoolean(input.enabled, `agents.${id}.enabled`) ?? true,
|
|
152
154
|
workspace: optionalString(input.workspace, `agents.${id}.workspace`),
|
|
153
155
|
command: optionalString(input.command, `agents.${id}.command`),
|
|
@@ -203,6 +205,7 @@ function parseA2AAgent(id, input) {
|
|
|
203
205
|
protocol: 'a2a',
|
|
204
206
|
name: optionalString(input.name, `agents.${id}.name`),
|
|
205
207
|
description: optionalString(input.description, `agents.${id}.description`),
|
|
208
|
+
instructions: normalizeAgentInstructions(input.instructions, `agents.${id}.instructions`),
|
|
206
209
|
enabled: optionalBoolean(input.enabled, `agents.${id}.enabled`) ?? true,
|
|
207
210
|
agentCardUrl,
|
|
208
211
|
agentUrl,
|
package/dist/control-plane.d.ts
CHANGED
package/dist/control-plane.js
CHANGED
|
@@ -2,6 +2,7 @@ import { randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
|
|
|
2
2
|
import { chmod, open, readFile, rename, rm } from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { hashAdminPassword, validateAdminPassword, verifyAdminPassword } from './auth.js';
|
|
5
|
+
import { normalizeAgentInstructions } from './agent-instructions.js';
|
|
5
6
|
import { loadAgentdConfig } from './config.js';
|
|
6
7
|
import { createDriverRegistry } from './drivers/index.js';
|
|
7
8
|
import { agentdDriverKinds } from './types.js';
|
|
@@ -311,6 +312,7 @@ export class AgentdControlPlane {
|
|
|
311
312
|
next.name = cleanString(update.name) || cleanString(previous.name);
|
|
312
313
|
}
|
|
313
314
|
}
|
|
315
|
+
setOptionalInstructions(next, update.instructions ?? cleanString(previous.instructions));
|
|
314
316
|
setOptionalString(next, 'description', update.description ?? cleanString(previous.description));
|
|
315
317
|
agents[id] = next;
|
|
316
318
|
raw.agents = agents;
|
|
@@ -448,6 +450,7 @@ export class AgentdControlPlane {
|
|
|
448
450
|
protocol: 'a2a',
|
|
449
451
|
name: config.name || id,
|
|
450
452
|
description: config.description,
|
|
453
|
+
instructions: config.instructions,
|
|
451
454
|
enabled: config.enabled !== false,
|
|
452
455
|
agentCardUrl: config.agentCardUrl || defaultAgentCardUrl(config.agentUrl),
|
|
453
456
|
agentUrl: config.agentUrl,
|
|
@@ -466,6 +469,7 @@ export class AgentdControlPlane {
|
|
|
466
469
|
driver: config.driver,
|
|
467
470
|
name: config.name || id,
|
|
468
471
|
description: config.description,
|
|
472
|
+
instructions: config.instructions,
|
|
469
473
|
enabled: config.enabled !== false,
|
|
470
474
|
workspace: config.workspace || this.config.workspaceRoots[0] || '',
|
|
471
475
|
permissionPolicy: config.permissionPolicy || 'ask',
|
|
@@ -607,6 +611,19 @@ function setOptionalString(target, key, value) {
|
|
|
607
611
|
else
|
|
608
612
|
delete target[key];
|
|
609
613
|
}
|
|
614
|
+
function setOptionalInstructions(target, value) {
|
|
615
|
+
let text;
|
|
616
|
+
try {
|
|
617
|
+
text = normalizeAgentInstructions(value);
|
|
618
|
+
}
|
|
619
|
+
catch (error) {
|
|
620
|
+
throw new ControlPlaneError(400, errorMessage(error));
|
|
621
|
+
}
|
|
622
|
+
if (text)
|
|
623
|
+
target.instructions = text;
|
|
624
|
+
else
|
|
625
|
+
delete target.instructions;
|
|
626
|
+
}
|
|
610
627
|
function validHeaderName(value) {
|
|
611
628
|
return /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(value);
|
|
612
629
|
}
|
package/dist/server.js
CHANGED
|
@@ -441,6 +441,7 @@ function readAgentUpdate(body) {
|
|
|
441
441
|
'driver',
|
|
442
442
|
'name',
|
|
443
443
|
'description',
|
|
444
|
+
'instructions',
|
|
444
445
|
'enabled',
|
|
445
446
|
'workspace',
|
|
446
447
|
'permissionPolicy',
|
|
@@ -458,6 +459,7 @@ function readAgentUpdate(body) {
|
|
|
458
459
|
driver: optionalString(body.driver),
|
|
459
460
|
name: optionalString(body.name),
|
|
460
461
|
description: optionalString(body.description),
|
|
462
|
+
instructions: optionalString(body.instructions),
|
|
461
463
|
enabled: optionalBoolean(body.enabled, 'enabled'),
|
|
462
464
|
workspace: optionalString(body.workspace),
|
|
463
465
|
permissionPolicy: optionalString(body.permissionPolicy),
|
package/dist/session.js
CHANGED
|
@@ -374,7 +374,7 @@ export class SessionManager {
|
|
|
374
374
|
const session = new ManagedSession(agentId, config.protocol === 'a2a' ? 'a2a' : 'acp', workspace, ownerKeyId, this.config.maxEventsPerSession, this.config.maxOutputChars, config.name || agentId, this.runStore);
|
|
375
375
|
const runtime = config.protocol === 'a2a'
|
|
376
376
|
? new A2AClientRuntime(config, session, this.config.promptTimeoutMs || 30 * 60_000)
|
|
377
|
-
: new AcpProcessRuntime(driver, session, this.config.maxOutputChars, this.config.promptTimeoutMs || 30 * 60_000);
|
|
377
|
+
: new AcpProcessRuntime(driver, session, this.config.maxOutputChars, this.config.promptTimeoutMs || 30 * 60_000, config.instructions);
|
|
378
378
|
this.sessions.set(session.id, session);
|
|
379
379
|
session.attach(runtime);
|
|
380
380
|
try {
|
package/dist/types.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface AgentdDriverConfig {
|
|
|
14
14
|
args?: string[];
|
|
15
15
|
inheritEnv?: string[];
|
|
16
16
|
env?: Record<string, string>;
|
|
17
|
+
/** Optional extra instructions appended to the built-in Agent Nexus guidance. */
|
|
18
|
+
instructions?: string;
|
|
17
19
|
permissionPolicy?: PermissionPolicy;
|
|
18
20
|
permissionTimeoutMs?: number;
|
|
19
21
|
}
|
|
@@ -23,6 +25,8 @@ export interface AgentdA2AConfig {
|
|
|
23
25
|
protocol: 'a2a';
|
|
24
26
|
name?: string;
|
|
25
27
|
description?: string;
|
|
28
|
+
/** Optional extra instructions sent with the first A2A user message. */
|
|
29
|
+
instructions?: string;
|
|
26
30
|
enabled?: boolean;
|
|
27
31
|
/** Full Agent Card JSON URL. Preferred for new configurations. */
|
|
28
32
|
agentCardUrl?: string;
|
|
@@ -128,6 +132,7 @@ export interface AgentdAgentConfigView {
|
|
|
128
132
|
protocol: AgentdProtocol;
|
|
129
133
|
name: string;
|
|
130
134
|
description?: string;
|
|
135
|
+
instructions?: string;
|
|
131
136
|
enabled: boolean;
|
|
132
137
|
driver?: AgentdDriverKind;
|
|
133
138
|
workspace?: string;
|
|
@@ -181,11 +186,17 @@ export interface AgentdPendingRequest {
|
|
|
181
186
|
id: string;
|
|
182
187
|
kind: 'permission' | 'input';
|
|
183
188
|
prompt: string;
|
|
189
|
+
/** Optional business-facing step, for example `payment` or `pickup_time`. */
|
|
190
|
+
step?: string;
|
|
191
|
+
/** Optional hint for clients rendering the pending interaction. */
|
|
192
|
+
inputType?: 'text' | 'choice' | 'confirmation' | 'payment' | 'unknown';
|
|
184
193
|
options?: Array<{
|
|
185
194
|
id: string;
|
|
186
195
|
name: string;
|
|
187
196
|
kind?: string;
|
|
188
197
|
}>;
|
|
198
|
+
/** JSON-safe metadata for the owning integration. Never put secrets here. */
|
|
199
|
+
metadata?: Record<string, unknown>;
|
|
189
200
|
}
|
|
190
201
|
export interface AgentdArtifact {
|
|
191
202
|
id?: string;
|
package/dist/webui/app.js
CHANGED
|
@@ -672,6 +672,7 @@ export const app = String.raw `
|
|
|
672
672
|
'<div class="field-row"><label>协议<select name="protocol"><option value="acp"' + selected(current.protocol, 'acp') + '>ACP</option><option value="a2a"' + selected(current.protocol, 'a2a') + '>A2A</option></select></label><label class="checkbox"><input name="enabled" type="checkbox"' + checked(current.enabled) + '>启用</label></div>' +
|
|
673
673
|
'<label>名称<input name="name" value="' + escapeHtml(current.name || '') + '" required></label>' +
|
|
674
674
|
'<label>描述<textarea name="description">' + escapeHtml(current.description || '') + '</textarea></label>' +
|
|
675
|
+
'<label>Agent 交互指令<textarea name="instructions" rows="8" placeholder="可选:补充这个 Agent 的专属规则。Gateway 会自动注入多轮确认和用户输入规范。">' + escapeHtml(current.instructions || '') + '</textarea><small class="field-help">可选补充规则,最多 32768 个字符;不要填写密钥等敏感信息。</small></label>' +
|
|
675
676
|
'<div data-protocol-section="acp"><label>驱动<select name="driver">' + drivers + '</select></label><label>工作区<input name="workspace" list="workspace-roots" value="' + escapeHtml(current.workspace || state.config.workspaceRoots[0] || '') + '" required><datalist id="workspace-roots">' + roots + '</datalist></label><div class="field-row"><label>权限策略<select name="permissionPolicy"><option value="ask"' + selected(current.permissionPolicy, 'ask') + '>询问</option><option value="deny"' + selected(current.permissionPolicy, 'deny') + '>拒绝</option></select></label><label>权限确认超时(秒)<input name="permissionTimeoutMs" type="number" min="1" max="86400" step="1" value="' + escapeHtml(permissionTimeoutSeconds) + '"><small class="field-help">单位:秒;默认 900 秒,最长 24 小时。</small></label></div></div>' +
|
|
676
677
|
'<div data-protocol-section="a2a"><label>Agent Card URL<input name="agentCardUrl" type="url" value="' + escapeHtml(current.agentCardUrl || '') + '" placeholder="http://agent.local:8080/.well-known/agent-card.json" required><small class="field-help">填写完整的 Agent Card JSON 地址;调用地址和能力将从 Card 自动发现。</small></label><div class="field-row"><label>首选传输<select name="preferredTransport"><option value="auto"' + selected(current.preferredTransport || 'auto', 'auto') + '>自动(按 Card)</option><option value="jsonrpc"' + selected(current.preferredTransport, 'jsonrpc') + '>JSON-RPC</option><option value="http-json"' + selected(current.preferredTransport, 'http-json') + '>HTTP+JSON</option></select></label><label>认证方式<select name="authType"><option value="none"' + selected(current.auth && current.auth.type || 'none', 'none') + '>无认证</option><option value="bearer"' + selected(current.auth && current.auth.type, 'bearer') + '>Bearer Token</option><option value="header"' + selected(current.auth && current.auth.type, 'header') + '>自定义请求头</option></select></label></div><label data-auth-header>请求头名称<input name="authHeaderName" value="' + escapeHtml(current.auth && current.auth.headerName || '') + '" placeholder="X-API-Key"></label><label data-auth-value><span data-auth-value-label>认证凭据</span><input name="authValue" type="password" autocomplete="off" placeholder="' + (editing && current.auth && current.auth.configured ? '留空以保留当前凭据' : '') + '"></label><label>请求超时(秒)<input name="timeoutMs" type="number" min="1" max="1800" step="1" value="' + escapeHtml(requestTimeoutSeconds) + '"><small class="field-help">单位:秒;默认 60 秒;用于限制这个 A2A Agent 的单次请求,最大 1800 秒(30 分钟)。</small></label></div>'
|
|
677
678
|
openDrawer(editing ? '编辑智能体' : '添加智能体', body, editing ? '保存修改' : '添加智能体', async (form) => {
|
|
@@ -682,6 +683,7 @@ export const app = String.raw `
|
|
|
682
683
|
protocol,
|
|
683
684
|
name: String(data.get('name') || '').trim(),
|
|
684
685
|
description: String(data.get('description') || '').trim(),
|
|
686
|
+
instructions: String(data.get('instructions') || '').trim(),
|
|
685
687
|
enabled: data.get('enabled') === 'on'
|
|
686
688
|
}
|
|
687
689
|
if (protocol === 'acp') {
|