11/**
2- * The two model-facing knowledge tools (kb_search, kb_chat). agent_id stays optional in the schema
3- * regardless of deployment: the default services (patch config or credential)
4- * can change at runtime through the credentials domain, so the fallback runs
5- * per call and a missing default surfaces as an executable error instead of a
6- * load-time schema difference.
2+ * The two model-facing knowledge tools (kb_search, kb_chat). agent_id is REQUIRED in the schema:
3+ * a model cannot know from the tool spec whether this deployment configures a default service, and a
4+ * missing default previously only surfaced at call time, forcing a wasted round-trip. The per-call
5+ * fallback to a configured default (settings/config or credential) is retained as defense-in-depth,
6+ * but note defineTool validates args against the schema before execute, so through that entry point
7+ * the fallback is inert; the model-facing contract is explicit.
78 */
89
910import { defineTool } from '@deepseek-ai/dsh-tools'
@@ -45,21 +46,35 @@ export function createKbTools(deps: KbToolDeps) {
4546 const { client, resolveDefaultRetrieveAgentId, resolveDefaultChatAgentId } = deps
4647 const agentIdParam = {
4748 type : 'string' as const ,
48- description : 'Retrieval/Q&A service id; omit to use the default service when this deployment configures one (find ids via `kscli service list`).' ,
49+ required : true as const ,
50+ description : 'Retrieval/Q&A service id. REQUIRED: the schema cannot know whether this deployment '
51+ + 'configures a default service, so always pass one. Find ids via '
52+ + '`kscli service list --scene search --workspace-id <workspaceId>` (workspaceId resolves '
53+ + 'automatically from DSH settings: bailian-kb.workspaceId in ~/.dsh/settings.yaml).' ,
4954 }
5055 const resolveRetrieveAgentId = async ( supplied : string | undefined ) : Promise < string > => {
5156 if ( supplied !== undefined ) return supplied
5257 const defaultId = resolveDefaultRetrieveAgentId === undefined ? undefined : await resolveDefaultRetrieveAgentId ( )
5358 if ( defaultId === undefined ) {
54- throw new Error ( 'agent_id is required: no default retrieval service is configured; discover services with `kscli service list`' )
59+ throw new Error (
60+ 'agent_id is required: no default retrieval service is configured. Pass agent_id explicitly '
61+ + '(find ids: `kscli service list --scene search --workspace-id <workspaceId>`), or configure a '
62+ + 'default: bailian-kb.defaultRetrieveAgentId in ~/.dsh/settings.yaml or '
63+ + 'BAILIAN_DEFAULT_RETRIEVE_AGENT_ID in ~/.dsh/.credentials.yaml.' ,
64+ )
5565 }
5666 return defaultId
5767 }
5868 const resolveChatAgentId = async ( supplied : string | undefined ) : Promise < string > => {
5969 if ( supplied !== undefined ) return supplied
6070 const defaultId = resolveDefaultChatAgentId === undefined ? undefined : await resolveDefaultChatAgentId ( )
6171 if ( defaultId === undefined ) {
62- throw new Error ( 'agent_id is required: no default chat service is configured; discover services with `kscli service list`' )
72+ throw new Error (
73+ 'agent_id is required: no default chat service is configured. Pass agent_id explicitly '
74+ + '(find ids: `kscli service list --scene chat --workspace-id <workspaceId>`), or configure a '
75+ + 'default: bailian-kb.defaultChatAgentId in ~/.dsh/settings.yaml or '
76+ + 'BAILIAN_DEFAULT_CHAT_AGENT_ID in ~/.dsh/.credentials.yaml.' ,
77+ )
6378 }
6479 return defaultId
6580 }
@@ -71,7 +86,10 @@ export function createKbTools(deps: KbToolDeps) {
7186 + 'references for you to verify, cite, or combine with other context. Retrieval scope and strategy '
7287 + '(multi-KB weighting, routing, reranking) come from the service configuration. '
7388 + 'top_k caps how many chunks return (client-side cut of the score-ranked results). '
74- + 'Use kb_chat instead when the user question can be answered by the knowledge base alone.' ,
89+ + 'Use kb_chat instead when the user question can be answered by the knowledge base alone. '
90+ + 'Credentials and workspace resolve automatically from DSH config '
91+ + '(bailian-kb in ~/.dsh/settings.yaml, DASHSCOPE_API_KEY in ~/.dsh/.credentials.yaml) — '
92+ + 'never read or pass them yourself. agent_id is REQUIRED (see its parameter description).' ,
7593 parameters : {
7694 query : { type : 'string' , required : true , description : 'Search query text.' } ,
7795 agent_id : agentIdParam ,
@@ -139,7 +157,10 @@ export function createKbTools(deps: KbToolDeps) {
139157 + '(multi-round retrieval + reranking + grounded generation). For knowledge Q&A this typically outperforms '
140158 + 'searching and synthesizing yourself when the question can be answered by the knowledge base alone; '
141159 + 'use kb_search instead when you need raw chunks to verify, cite, or combine with other work. '
142- + 'The pipeline runs an internal analysis/retrieval loop and may take a few minutes.' ,
160+ + 'The pipeline runs an internal analysis/retrieval loop and may take a few minutes. '
161+ + 'Credentials and workspace resolve automatically from DSH config '
162+ + '(bailian-kb in ~/.dsh/settings.yaml, DASHSCOPE_API_KEY in ~/.dsh/.credentials.yaml) — '
163+ + 'never read or pass them yourself. agent_id is REQUIRED (see its parameter description).' ,
143164 parameters : {
144165 message : { type : 'string' , required : true , description : 'The question to ask.' } ,
145166 agent_id : agentIdParam ,
0 commit comments