Browse Source

feat: experimental.primary_tools, allow user to set the tools that should only be available to primary agents (#4913)

Co-authored-by: GitHub Action <[email protected]>
Spoon 2 months ago
parent
commit
0bccd1d578

+ 4 - 0
packages/opencode/src/config/config.ts

@@ -668,6 +668,10 @@ export namespace Config {
           chatMaxRetries: z.number().optional().describe("Number of retries for chat completions on failure"),
           disable_paste_summary: z.boolean().optional(),
           batch_tool: z.boolean().optional().describe("Enable the batch tool"),
+          primary_tools: z
+            .array(z.string())
+            .optional()
+            .describe("Tools that should only be available to primary agents."),
         })
         .optional(),
     })

+ 4 - 0
packages/opencode/src/tool/task.ts

@@ -9,6 +9,7 @@ import { Agent } from "../agent/agent"
 import { SessionPrompt } from "../session/prompt"
 import { iife } from "@/util/iife"
 import { defer } from "@/util/defer"
+import { Config } from "../config/config"
 
 export const TaskTool = Tool.define("task", async () => {
   const agents = await Agent.list().then((x) => x.filter((a) => a.mode !== "primary"))
@@ -77,6 +78,8 @@ export const TaskTool = Tool.define("task", async () => {
       ctx.abort.addEventListener("abort", cancel)
       using _ = defer(() => ctx.abort.removeEventListener("abort", cancel))
       const promptParts = await SessionPrompt.resolvePromptParts(params.prompt)
+
+      const config = await Config.get()
       const result = await SessionPrompt.prompt({
         messageID,
         sessionID: session.id,
@@ -89,6 +92,7 @@ export const TaskTool = Tool.define("task", async () => {
           todowrite: false,
           todoread: false,
           task: false,
+          ...Object.fromEntries((config.experimental?.primary_tools ?? []).map((t) => [t, false])),
           ...agent.tools,
         },
         parts: promptParts,

+ 4 - 0
packages/sdk/js/src/gen/types.gen.ts

@@ -1249,6 +1249,10 @@ export type Config = {
      * Enable the batch tool
      */
     batch_tool?: boolean
+    /**
+     * Tools that should only be available to primary agents.
+     */
+    primary_tools?: Array<string>
   }
 }