From 40066517c43a467f7c87ee4362fb3e2954fb9cd7 Mon Sep 17 00:00:00 2001 From: Kristofer Jussmann Date: Mon, 18 May 2026 11:50:08 +0300 Subject: [PATCH] Prefer direct tools in live agent code guidance --- lib/ai/agents.ts | 7 +++--- .../test-live-agent-execute-code-guidance.ts | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 scripts/test/test-live-agent-execute-code-guidance.ts diff --git a/lib/ai/agents.ts b/lib/ai/agents.ts index 5e04290..af2f9ad 100644 --- a/lib/ai/agents.ts +++ b/lib/ai/agents.ts @@ -187,9 +187,10 @@ const executeCode = tool( { name: "execute_code", description: - "Execute a Blender Python script. Use this for geometry creation, material setup, " + - "animation, lighting, camera, and any Blender Python API operation. " + - "Break complex objects into SEPARATE calls — one component per call.", + "Execute a scoped Blender Python script. Use only when no direct MCP tool fits, " + + "such as one-off geometry, procedural effects, animation internals, or short API introspection. " + + "Prefer direct tools like create_mesh_from_data, create_material_preset, add_light, add_camera, " + + "set_render_settings, prepare_uv_layout, and validate_export_readiness whenever they cover the operation.", schema: z.object({ code: z.string().describe("The Blender Python script to execute"), }), diff --git a/scripts/test/test-live-agent-execute-code-guidance.ts b/scripts/test/test-live-agent-execute-code-guidance.ts new file mode 100644 index 0000000..0ee976b --- /dev/null +++ b/scripts/test/test-live-agent-execute-code-guidance.ts @@ -0,0 +1,24 @@ +import assert from "node:assert/strict" +import { readFileSync } from "node:fs" + +const agentSource = readFileSync("lib/ai/agents.ts", "utf8") + +const executeCodeBlock = agentSource.slice( + agentSource.indexOf("const executeCode = tool("), + agentSource.indexOf("const getSceneInfo = tool(") +) + +assert.match(executeCodeBlock, /Use only when no direct MCP tool fits/) +assert.match(executeCodeBlock, /one-off geometry/) +assert.match(executeCodeBlock, /short API introspection/) +assert.match(executeCodeBlock, /Prefer direct tools/) +assert.match(executeCodeBlock, /create_mesh_from_data/) +assert.match(executeCodeBlock, /create_material_preset/) +assert.match(executeCodeBlock, /add_light/) +assert.match(executeCodeBlock, /add_camera/) + +assert.doesNotMatch(executeCodeBlock, /Use this for geometry creation, material setup/) +assert.doesNotMatch(executeCodeBlock, /any Blender Python API operation/) +assert.doesNotMatch(executeCodeBlock, /Break complex objects into SEPARATE calls/) + +console.log("Live agent execute_code guidance tests passed")