@springbrand/agent-runtime 0.2.0-alpha.31 → 0.2.0-alpha.32
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/package.json +1 -1
- package/src/lib/prompt.ts +16 -12
- package/src/pi/message/contract.ts +1 -1
- package/src/pi/runtime-adapter/index.ts +7 -0
- package/src/pi/tool/core-host.ts +6 -2
- package/src/runtime.ts +11 -1
package/package.json
CHANGED
package/src/lib/prompt.ts
CHANGED
|
@@ -18,8 +18,7 @@ export const PERSONA =
|
|
|
18
18
|
export const RUNTIME =
|
|
19
19
|
"Runtime: this agent runs on Cloudflare Workers. When execute is present, its Code Mode Dynamic Worker is your " +
|
|
20
20
|
"instrument — code there runs with outbound network access (fetch), your " +
|
|
21
|
-
"workspace filesystem (state.*), and
|
|
22
|
-
"in one execute instead of making consecutive top-level Tool calls. Use it for raw or customized HTTP " +
|
|
21
|
+
"workspace filesystem (state.*), and the tools.* methods listed in its own description. Use it for raw or customized HTTP " +
|
|
23
22
|
"requests, parsing a payload, hitting several known endpoints, or computing over a file. Write plain " +
|
|
24
23
|
"JavaScript — the sandbox evaluates " +
|
|
25
24
|
"it directly, so TypeScript type annotations (`: number`, `as Type`) are a syntax error, and there " +
|
|
@@ -33,7 +32,9 @@ export const BEHAVIOR =
|
|
|
33
32
|
"When uncertain, investigate before answering rather than guess or confirm a belief. Match response " +
|
|
34
33
|
"length to the task — a short question gets a short answer; skip filler preamble and don't restate " +
|
|
35
34
|
"what you just did. Be proactive when asked to *do* something (take the needed follow-up actions too), " +
|
|
36
|
-
"but when the user only asks *how* to approach something, answer first and don't jump into changes."
|
|
35
|
+
"but when the user only asks *how* to approach something, answer first and don't jump into changes. " +
|
|
36
|
+
"A failed Tool call produced no requested result. Never infer completion or fabricate URLs, files, identifiers, or business results " +
|
|
37
|
+
"from a failed call's arguments or identifiers; correct the Tool route or report the failure.";
|
|
37
38
|
|
|
38
39
|
// The main Agent alone owns user-visible planning.
|
|
39
40
|
export const PLANNING =
|
|
@@ -43,15 +44,18 @@ export const PLANNING =
|
|
|
43
44
|
"one step in_progress at a time and don't batch completions. Do not make a plan for a single trivial " +
|
|
44
45
|
"step or a purely conversational reply — just do it.";
|
|
45
46
|
|
|
47
|
+
const TOOL_ROUTING =
|
|
48
|
+
"Tools: execute can call only the tools.* methods explicitly listed in its description; that list is exhaustive. Never guess a tools.* method. " +
|
|
49
|
+
"If a required top-level Tool is not visible, do not use execute. Call top-level Tool Search with that exact name, then call the discovered Tool directly. " +
|
|
50
|
+
"codemode.search searches only methods already installed inside execute; it cannot discover deferred top-level Tools.";
|
|
51
|
+
|
|
46
52
|
// Tool-selection guidance mirrors the actual approval and network boundaries.
|
|
47
53
|
export const TOOLS =
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"workspace file operations, tools.* for other host capabilities, a loop for repeated calls, and Promise.all for independent calls. " +
|
|
52
|
-
"
|
|
53
|
-
"Some Tools may be deferred and absent from the initial list. When Tool Search is available, before saying that a requested capability or named Tool is unavailable, use the available Tool Search once. " +
|
|
54
|
-
"If the user names a Tool, search that exact name by itself first. Searchable categories may include workspace and files, browser and web, interaction and planning, memory and scheduling, Skills, Extensions, MCP, Plugins, and Host capabilities; discover them only when needed. " +
|
|
54
|
+
TOOL_ROUTING +
|
|
55
|
+
" Relatedness, repetition, or multiple calls never overrides this availability rule. " +
|
|
56
|
+
"When every required Tool is available inside execute, use one execute for repeated or related calls, branching, or repetition. Inside execute, " +
|
|
57
|
+
"use state.* for workspace file operations, tools.* for other host capabilities, a loop for repeated calls, and Promise.all for independent calls. " +
|
|
58
|
+
"Top-level-only Tools remain Direct even when called repeatedly. " +
|
|
55
59
|
"For web tasks, use web_search for web discovery, current facts, cited research, " +
|
|
56
60
|
"and public URL analysis. For web access specifically, use execute Code Mode only for raw or customized network requests, structured " +
|
|
57
61
|
"API calls, or when web_search cannot retrieve the required content; do not use execute for ordinary web " +
|
|
@@ -65,7 +69,7 @@ export const TOOLS =
|
|
|
65
69
|
"When execute is present, make related file changes in one execute with state.*; when execute is absent, use one write or bash operation instead of serial edits. " +
|
|
66
70
|
"Do not re-plan or explain between consecutive tool calls. When a run is within the last five model turns, stop expanding scope and " +
|
|
67
71
|
"prioritize verification, saving durable results, and the final response. " +
|
|
68
|
-
"When related Tool calls can run independently and execute is present, run them inside that execute rather than as parallel top-level calls; " +
|
|
72
|
+
"When related Tool calls can run independently, all are available inside execute, and execute is present, run them inside that execute rather than as parallel top-level calls; " +
|
|
69
73
|
"only independent top-level-only Direct Tools should be issued together in one turn. When you reference " +
|
|
70
74
|
"code, cite it as file_path:line_number.";
|
|
71
75
|
|
|
@@ -166,5 +170,5 @@ export function assembleSystemPrompt(base?: string | null): string {
|
|
|
166
170
|
* Agent、Runtime 和 Memory 的术语见 `src/index.ts`。
|
|
167
171
|
*/
|
|
168
172
|
export function assembleSubagentPrompt(persona: string): string {
|
|
169
|
-
return [persona, RUNTIME, BEHAVIOR].join("\n\n");
|
|
173
|
+
return [persona, RUNTIME, BEHAVIOR, TOOL_ROUTING].join("\n\n");
|
|
170
174
|
}
|
|
@@ -4,7 +4,7 @@ export type UIChatTrigger = "submit-message" | "regenerate-message";
|
|
|
4
4
|
|
|
5
5
|
/** A user-selected Runtime capability persisted with the visible UIMessage. */
|
|
6
6
|
export interface RequestedCapability {
|
|
7
|
-
readonly kind: "skill" | "plan";
|
|
7
|
+
readonly kind: "skill" | "tool" | "plan";
|
|
8
8
|
readonly name: string;
|
|
9
9
|
readonly label: string;
|
|
10
10
|
}
|
|
@@ -18,6 +18,7 @@ export {
|
|
|
18
18
|
import {
|
|
19
19
|
pinPiRuntime,
|
|
20
20
|
preparePiRuntime,
|
|
21
|
+
readPreparedPiRuntime,
|
|
21
22
|
type PinPiRuntimeOptions,
|
|
22
23
|
type PinnedPiRuntime,
|
|
23
24
|
type PreparePiRuntimeOptions,
|
|
@@ -143,6 +144,12 @@ export class PiRuntimeAdapter {
|
|
|
143
144
|
return preparePiRuntime(options, this.owner);
|
|
144
145
|
}
|
|
145
146
|
|
|
147
|
+
hasTool(prepared: PreparedPiRuntime, name: string): boolean {
|
|
148
|
+
return readPreparedPiRuntime(prepared, this.owner).candidates.some(
|
|
149
|
+
(candidate) => candidate.tool.name === name,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
146
153
|
/**
|
|
147
154
|
* 用已经通过加载检查的快照启用当前部署声明的模型目录。
|
|
148
155
|
*
|
package/src/pi/tool/core-host.ts
CHANGED
|
@@ -18,6 +18,10 @@ import type {
|
|
|
18
18
|
// 本文件沿用 `../../index.ts` 入口定义的 Workspace、Port 和 Tool Candidate 术语。
|
|
19
19
|
|
|
20
20
|
const CODEMODE_SANDBOX_TIMEOUT_MS = 55_000;
|
|
21
|
+
const CODEMODE_TOOL_SURFACE_GUIDANCE =
|
|
22
|
+
"The `tools.*` Available list below is exhaustive, not examples. Inside execute, call only methods in that list; " +
|
|
23
|
+
"never guess or construct a `tools.*` method name. If a required Tool is absent, leave execute and call it at the top level, " +
|
|
24
|
+
"using top-level Tool Search first when it is deferred. `codemode.search` cannot add methods to `tools.*`.";
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
27
|
* 宿主的 Browser Rendering 绑定,只取本仓真正用到的那一面。
|
|
@@ -183,10 +187,10 @@ export function createWorkspaceCodeExecutionFactory(options: {
|
|
|
183
187
|
const port = toCodeExecutionPort(tool, "execute");
|
|
184
188
|
return {
|
|
185
189
|
...port,
|
|
186
|
-
description: port.description.replace(
|
|
190
|
+
description: `${CODEMODE_TOOL_SURFACE_GUIDANCE}\n\n${port.description.replace(
|
|
187
191
|
"- Do not use `fetch` — use connector SDKs.",
|
|
188
192
|
"- Raw `fetch` is available inside `codemode.step(...)`; prefer connector SDKs when one owns the target.",
|
|
189
|
-
)
|
|
193
|
+
)}`,
|
|
190
194
|
};
|
|
191
195
|
},
|
|
192
196
|
};
|
package/src/runtime.ts
CHANGED
|
@@ -360,7 +360,7 @@ function requestedCapabilitiesOf(metadata: unknown): RequestedCapability[] {
|
|
|
360
360
|
}
|
|
361
361
|
const capability = value as Record<string, unknown>;
|
|
362
362
|
if (
|
|
363
|
-
(capability.kind !== "skill" && capability.kind !== "plan") ||
|
|
363
|
+
(capability.kind !== "skill" && capability.kind !== "tool" && capability.kind !== "plan") ||
|
|
364
364
|
typeof capability.name !== "string" ||
|
|
365
365
|
!capability.name.trim() ||
|
|
366
366
|
typeof capability.label !== "string" ||
|
|
@@ -1352,6 +1352,16 @@ export abstract class AgentRuntimeKernel<
|
|
|
1352
1352
|
);
|
|
1353
1353
|
continue;
|
|
1354
1354
|
}
|
|
1355
|
+
if (capability.kind === "tool") {
|
|
1356
|
+
if (!this.pi.hasTool(this.preparedPi(), capability.name)) {
|
|
1357
|
+
throw new Error(`Requested Tool is not installed: ${capability.name}`);
|
|
1358
|
+
}
|
|
1359
|
+
context.push(
|
|
1360
|
+
`requested capability: tool/${capability.name}`,
|
|
1361
|
+
`required action: call tool "${capability.name}" when handling the task`,
|
|
1362
|
+
);
|
|
1363
|
+
continue;
|
|
1364
|
+
}
|
|
1355
1365
|
if (capability.name !== "plan") {
|
|
1356
1366
|
throw new Error(`Unknown plan capability: ${capability.name}`);
|
|
1357
1367
|
}
|