Skip to content

Commit 5f417d2

Browse files
authored
fix: support byteplus viking memory and tool filtering (#842)
1 parent cd2ba02 commit 5f417d2

19 files changed

Lines changed: 535 additions & 265 deletions

frontend/src/create/CustomCreate.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {
4444
A2A_REGISTRY_DEFAULTS,
4545
A2A_REGISTRY_ENV,
4646
BUILTIN_TOOLS,
47-
CREATE_BUILTIN_TOOLS,
47+
createBuiltinToolsForProvider,
4848
STM_BACKENDS,
4949
LTM_BACKENDS,
5050
KB_BACKENDS,
@@ -2928,14 +2928,24 @@ export function CustomCreate({
29282928

29292929
// Root-only rich sections read these off the root draft directly.
29302930
const builtinTools = node.builtinTools ?? [];
2931+
const createBuiltinTools = useMemo(
2932+
() => createBuiltinToolsForProvider(cloudProvider),
2933+
[cloudProvider],
2934+
);
2935+
const createBuiltinToolIds = useMemo(
2936+
() => new Set(createBuiltinTools.map((tool) => tool.id)),
2937+
[createBuiltinTools],
2938+
);
29312939
const mcpTools = node.mcpTools ?? [];
29322940
const selectedSkills = node.selectedSkills ?? [];
2933-
const toggleBuiltin = (id: string) =>
2941+
const toggleBuiltin = (id: string) => {
2942+
if (!createBuiltinToolIds.has(id)) return;
29342943
patch({
29352944
builtinTools: builtinTools.includes(id)
29362945
? builtinTools.filter((x) => x !== id)
29372946
: [...builtinTools, id],
29382947
});
2948+
};
29392949

29402950
// Detail-pane branching is driven by the SELECTED node's type.
29412951
const orchestrator = isOrchestratorType(node.agentType);
@@ -3923,7 +3933,7 @@ export function CustomCreate({
39233933
</span>
39243934
<div className="cw-tools-list-shell">
39253935
<Checklist
3926-
items={CREATE_BUILTIN_TOOLS}
3936+
items={createBuiltinTools}
39273937
selected={builtinTools}
39283938
onToggle={toggleBuiltin}
39293939
scrollRows={6}

frontend/src/create/normalizeDraft.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
type CustomTool,
66
type SelectedSkill,
77
} from "./types";
8-
import { CREATE_BUILTIN_TOOLS, DEFAULT_KB_BACKEND } from "./veadkCatalog";
8+
import { createBuiltinToolsForProvider, DEFAULT_KB_BACKEND } from "./veadkCatalog";
9+
import type { CloudProvider } from "../adk/cloudProvider";
910

1011
const STM_IDS = new Set(["local", "sqlite", "mysql", "postgresql"]);
1112
const LTM_IDS = new Set([
@@ -30,7 +31,6 @@ const TOOL_IDS = new Set([
3031
"run_code",
3132
"vesearch",
3233
]);
33-
const GENERATED_TOOL_IDS = new Set(CREATE_BUILTIN_TOOLS.map((tool) => tool.id));
3434
const AGENT_TYPES = new Set(["llm", "sequential", "parallel", "loop", "a2a"]);
3535

3636
function asString(v: unknown, fallback = ""): string {
@@ -283,11 +283,18 @@ export function normalizeDraft(raw: unknown): AgentDraft {
283283
};
284284
}
285285

286-
export function sanitizeGeneratedDraftCapabilities(draft: AgentDraft): AgentDraft {
286+
export function sanitizeGeneratedDraftCapabilities(
287+
draft: AgentDraft,
288+
inheritedCloudProvider: CloudProvider = draft.cloudProvider ?? "volcengine",
289+
): AgentDraft {
290+
const cloudProvider = draft.cloudProvider ?? inheritedCloudProvider;
291+
const generatedToolIds = new Set(
292+
createBuiltinToolsForProvider(cloudProvider).map((tool) => tool.id),
293+
);
287294
return {
288295
...draft,
289296
builtinTools: (draft.builtinTools ?? []).filter((toolId) =>
290-
GENERATED_TOOL_IDS.has(toolId),
297+
generatedToolIds.has(toolId),
291298
),
292299
tracing: false,
293300
tracingExporters: [],
@@ -298,6 +305,8 @@ export function sanitizeGeneratedDraftCapabilities(draft: AgentDraft): AgentDraf
298305
knowledgebase: false,
299306
knowledgebaseBackend: DEFAULT_KB_BACKEND,
300307
knowledgebaseIndex: "",
301-
subAgents: draft.subAgents.map(sanitizeGeneratedDraftCapabilities),
308+
subAgents: draft.subAgents.map((child) =>
309+
sanitizeGeneratedDraftCapabilities(child, cloudProvider),
310+
),
302311
};
303312
}

frontend/src/create/veadkCatalog.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Each option carries enough metadata to (a) render a picker and (b) emit
66
// runnable Python + a complete .env.example.
77

8+
import type { CloudProvider } from "../adk/cloudProvider";
9+
810
export interface EnvVar {
911
key: string;
1012
/** Whether the feature is non-functional without it (still emitted, but flagged). */
@@ -250,10 +252,26 @@ const HIDDEN_CREATE_TOOL_IDS = new Set([
250252
"text_to_speech",
251253
"vesearch",
252254
]);
255+
256+
const BYTEPLUS_HIDDEN_CREATE_TOOL_IDS = new Set([
257+
"web_search",
258+
"parallel_web_search",
259+
]);
260+
253261
export const CREATE_BUILTIN_TOOLS = BUILTIN_TOOLS.filter(
254262
(tool) => !HIDDEN_CREATE_TOOL_IDS.has(tool.id),
255263
);
256264

265+
export function createBuiltinToolsForProvider(
266+
cloudProvider: CloudProvider = "volcengine",
267+
): ToolOption[] {
268+
const hidden =
269+
cloudProvider === "byteplus"
270+
? BYTEPLUS_HIDDEN_CREATE_TOOL_IDS
271+
: new Set<string>();
272+
return CREATE_BUILTIN_TOOLS.filter((tool) => !hidden.has(tool.id));
273+
}
274+
257275
/* ------------------------------------------------------------------ *
258276
* Short-term memory backends.
259277
* ------------------------------------------------------------------ */

frontend/tests/generatedAgentPlanner.test.mjs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ test("removes hidden capabilities from every generated Agent", () => {
2525
);
2626
const sanitizer = normalizeSource.slice(start);
2727

28-
assert.match(sanitizer, /GENERATED_TOOL_IDS\.has\(toolId\)/);
28+
assert.match(
29+
sanitizer,
30+
/createBuiltinToolsForProvider\(cloudProvider\)\.map\(\(tool\) => tool\.id\)/,
31+
);
32+
assert.match(sanitizer, /generatedToolIds\.has\(toolId\)/);
2933
assert.match(sanitizer, /tracing: false/);
3034
assert.match(sanitizer, /tracingExporters: \[\]/);
3135
assert.match(sanitizer, /memory: \{ shortTerm: false, longTerm: false \}/);
@@ -37,7 +41,7 @@ test("removes hidden capabilities from every generated Agent", () => {
3741
assert.match(sanitizer, /knowledgebaseIndex: ""/);
3842
assert.match(
3943
sanitizer,
40-
/subAgents: draft\.subAgents\.map\(sanitizeGeneratedDraftCapabilities\)/,
44+
/subAgents: draft\.subAgents\.map\(\(child\) =>[\s\S]*?sanitizeGeneratedDraftCapabilities\(child, cloudProvider\)/,
4145
);
4246
assert.match(
4347
createSource,
@@ -49,8 +53,14 @@ test("keeps OpenViking long-term memory when normalizing imported drafts", () =>
4953
assert.match(normalizeSource, /"openviking"/);
5054
});
5155

52-
test("feeds supported generated tool ids into the checklist selection", () => {
53-
assert.match(createSource, /items=\{CREATE_BUILTIN_TOOLS\}/);
56+
test("feeds provider-supported generated tool ids into the checklist selection", () => {
57+
assert.match(
58+
createSource,
59+
/createBuiltinToolsForProvider\(cloudProvider\)/,
60+
);
61+
assert.match(createSource, /new Set\(createBuiltinTools\.map\(\(tool\) => tool\.id\)\)/);
62+
assert.match(createSource, /if \(!createBuiltinToolIds\.has\(id\)\) return/);
63+
assert.match(createSource, /items=\{createBuiltinTools\}/);
5464
assert.match(createSource, /selected=\{builtinTools\}/);
5565
});
5666

frontend/tests/markdownPromptEditor.test.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,19 @@ test("advanced model connection settings use an accessible disclosure", () => {
581581
});
582582

583583
test("built-in tools adapt columns and scroll after six rows", () => {
584-
assert.match(createSource, /items=\{CREATE_BUILTIN_TOOLS\}[\s\S]*?scrollRows=\{6\}/);
584+
assert.match(createSource, /items=\{createBuiltinTools\}[\s\S]*?scrollRows=\{6\}/);
585585
assert.match(
586586
catalogSource,
587587
/HIDDEN_CREATE_TOOL_IDS = new Set\(\[[\s\S]*?"web_scraper"[\s\S]*?"text_to_speech"[\s\S]*?"vesearch"/,
588588
);
589+
assert.match(
590+
catalogSource,
591+
/BYTEPLUS_HIDDEN_CREATE_TOOL_IDS = new Set\(\[[\s\S]*?"web_search"[\s\S]*?"parallel_web_search"/,
592+
);
593+
assert.match(
594+
catalogSource,
595+
/cloudProvider === "byteplus"[\s\S]*?BYTEPLUS_HIDDEN_CREATE_TOOL_IDS[\s\S]*?return CREATE_BUILTIN_TOOLS\.filter\(\(tool\) => !hidden\.has\(tool\.id\)\)/,
596+
);
589597
assert.match(
590598
createStyles,
591599
/\.cw-tools-list-shell\s*\{[\s\S]*?container-type:\s*inline-size;/,

tests/cli/test_studio_rbac.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ async def initialize_evaluation_sets(**_kwargs: Any) -> list[str]:
436436
runtime_envs = cloud["runtime_envs"]
437437
assert runtime_envs["CLOUD_PROVIDER"] == "byteplus"
438438
assert runtime_envs["AGENTKIT_CLOUD_PROVIDER"] == "byteplus"
439-
assert runtime_envs["DATABASE_VIKING_REGION"] == "ap-southeast-1"
439+
assert runtime_envs["DATABASE_VIKING_REGION"] == "cn-hongkong"
440440
assert "BYTEPLUS_ACCESS_KEY" not in runtime_envs
441441
assert "BYTEPLUS_SECRET_KEY" not in runtime_envs
442442
assert "BYTEPLUS_SESSION_TOKEN" not in runtime_envs

tests/cli/test_studio_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def update_application_code_bundle(self, **kwargs: object) -> str:
451451
"CLOUD_PROVIDER": "byteplus",
452452
"AGENTKIT_CLOUD_PROVIDER": "byteplus",
453453
"BYTEPLUS_REGION": "ap-southeast-1",
454-
"DATABASE_VIKING_REGION": "ap-southeast-1",
454+
"DATABASE_VIKING_REGION": "cn-hongkong",
455455
}
456456

457457

tests/test_vikingdb_knowledge_backend.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_viking_knowledgebase_reads_byteplus_credentials(
8787
assert backend.session_token == "bp-token"
8888

8989

90-
def test_byteplus_viking_knowledgebase_uses_byteplus_region(
90+
def test_byteplus_viking_knowledgebase_uses_hong_kong_fallback(
9191
monkeypatch: pytest.MonkeyPatch,
9292
) -> None:
9393
from veadk.knowledgebase.backends.vikingdb_knowledge_backend import (
@@ -107,9 +107,35 @@ def test_byteplus_viking_knowledgebase_uses_byteplus_region(
107107

108108
backend = VikingDBKnowledgeBackend(index="vikingkl_we4191n")
109109

110-
assert backend.region == "ap-southeast-1"
111-
assert backend.host == "api-knowledgebase.mlp.ap-southeast-1.bytepluses.com"
110+
assert backend.region == "cn-hongkong"
111+
assert backend.host == "api-knowledgebase.mlp.cn-hongkong.bytepluses.com"
112112
assert (
113-
backend.base_url
114-
== "https://api-knowledgebase.mlp.ap-southeast-1.bytepluses.com"
113+
backend.base_url == "https://api-knowledgebase.mlp.cn-hongkong.bytepluses.com"
114+
)
115+
116+
117+
def test_byteplus_viking_knowledgebase_keeps_hong_kong_region(
118+
monkeypatch: pytest.MonkeyPatch,
119+
) -> None:
120+
from veadk.knowledgebase.backends.vikingdb_knowledge_backend import (
121+
VikingDBKnowledgeBackend,
122+
)
123+
124+
monkeypatch.setenv("CLOUD_PROVIDER", "byteplus")
125+
monkeypatch.setenv("AGENTKIT_CLOUD_PROVIDER", "byteplus")
126+
monkeypatch.setenv("DATABASE_VIKING_REGION", "cn-hongkong")
127+
monkeypatch.setenv("BYTEPLUS_ACCESS_KEY", "bp-ak")
128+
monkeypatch.setenv("BYTEPLUS_SECRET_KEY", "bp-sk")
129+
monkeypatch.setattr(
130+
VikingDBKnowledgeBackend,
131+
"collection_status",
132+
lambda self: {"existed": True},
133+
)
134+
135+
backend = VikingDBKnowledgeBackend(index="vikingkl_we4191n")
136+
137+
assert backend.region == "cn-hongkong"
138+
assert backend.host == "api-knowledgebase.mlp.cn-hongkong.bytepluses.com"
139+
assert (
140+
backend.base_url == "https://api-knowledgebase.mlp.cn-hongkong.bytepluses.com"
115141
)

0 commit comments

Comments
 (0)