From ca109ba9b867fd48be3b2982d0ace639399072bd Mon Sep 17 00:00:00 2001 From: Rin Date: Sat, 7 Feb 2026 05:31:45 +0800 Subject: [PATCH] feat(minecraft): compact brain prompt tool descriptions to reduce token usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace verbose JSDoc-style tool formatting with pipe-delimited compact format (name|description|sig:positional|obj:object|args:params), abbreviate common words in descriptions (Automatically→Auto, approximately→approx, coordinate→coord, inventory→inv, nearest→near, number of→#, player→plyr, resource→res, position→pos, whether→if), flatten parameter descriptions from multi-line @param blocks to semic --- .../conscious/prompts/brain-prompt.ts | 51 ++++++++++++------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/services/minecraft/src/cognitive/conscious/prompts/brain-prompt.ts b/services/minecraft/src/cognitive/conscious/prompts/brain-prompt.ts index 986795a5f..b2c977acd 100644 --- a/services/minecraft/src/cognitive/conscious/prompts/brain-prompt.ts +++ b/services/minecraft/src/cognitive/conscious/prompts/brain-prompt.ts @@ -104,32 +104,45 @@ function getZodConstraintHint(def: any): string { return hints.length > 0 ? ` (${hints.join(', ')})` : '' } +function abbreviateToolDescription(input: string): string { + return input + .replace(/\bAutomatically\b/gi, 'Auto') + .replace(/\bapproximately\b/gi, 'approx') + .replace(/\bcoordinate(s)?\b/gi, 'coord$1') + .replace(/\bcoordinates\b/gi, 'coords') + .replace(/\binventory\b/gi, 'inv') + .replace(/\bnearest\b/gi, 'near') + .replace(/\bspecific\b/gi, 'spec') + .replace(/\bgiven\b/gi, '') + .replace(/\bnumber of\b/gi, '#') + .replace(/\bplayer\b/gi, 'plyr') + .replace(/\bplayers\b/gi, 'plyrs') + .replace(/\bresource(s)?\b/gi, 'res$1') + .replace(/\bposition\b/gi, 'pos') + .replace(/\bwhether\b/gi, 'if') + .replace(/\s+/g, ' ') + .trim() +} + export function generateBrainSystemPrompt(availableActions: Action[]): string { const toolsFormatted = availableActions.map((a) => { const paramKeys = Object.keys(a.schema.shape) const positionalSignature = paramKeys.length > 0 ? `${a.name}(${paramKeys.join(', ')})` : `${a.name}()` const objectSignature = paramKeys.length > 0 ? `${a.name}({ ${paramKeys.join(', ')} })` : `${a.name}()` - let params = '' - if (a.schema && 'shape' in a.schema) { - params = Object.entries(a.schema.shape).map(([key, val]: [string, any]) => { - const def = val._def - const type = getZodTypeName(def) - const constraints = getZodConstraintHint(def) - const desc = val.description ? ` - ${val.description}` : '' - return ` * @param {${type}${constraints}} ${key}${desc}` - }).join('\n') - } + const params = a.schema && 'shape' in a.schema + ? Object.entries(a.schema.shape).map(([key, val]: [string, any]) => { + const def = val._def + const type = getZodTypeName(def) + const constraints = getZodConstraintHint(def).replace(/^\s+/, '') + const desc = val.description ? ` ${String(val.description).trim()}` : '' + return `${key}:${type}${constraints}${desc}` + }).join('; ') + : '' - const body = params ? `\n${params}\n ` : '\n ' - return `/** - * ${a.description} - * @function ${a.name} - * @signature ${positionalSignature} - * @signature ${objectSignature}${body}*/ -${positionalSignature} -` - }).join('\n\n') + const compactDescription = abbreviateToolDescription(a.description) + return `${a.name}|${compactDescription}|sig:${positionalSignature}|obj:${objectSignature}${params ? `|args:${params}` : ''}` + }).join('\n') ensureWatcher() const template = ensureTemplateLoaded()