Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(agent-profiles): save task_tracker with delegation tools (workaround for SDK#5519) (#18001)

simonrosenberg4ba472d62a77
diff --git a/__tests__/constants/profile-tools.test.ts b/__tests__/constants/profile-tools.test.ts
index 2ea658b6b0..9391d34de9 100644
--- a/__tests__/constants/profile-tools.test.ts
+++ b/__tests__/constants/profile-tools.test.ts
@@ -87,4 +87,32 @@ describe("buildProfileToolsValue", () => {
const { mode, selected, params } = readProfileTools(stored);
expect(buildProfileToolsValue({ mode, selected, params })).toEqual(stored);
});
+
+ it.each(["task_tool_set", "workflow_tool_set"])(
+ "adds task_tracker when %s is selected without it",
+ (delegate) => {
+ expect(
+ buildProfileToolsValue({
+ mode: "custom",
+ selected: ["terminal", delegate],
+ }),
+ ).toEqual([
+ { name: "terminal", params: {} },
+ { name: delegate, params: {} },
+ { name: "task_tracker", params: {} },
+ ]);
+ },
+ );
+
+ it("does not duplicate task_tracker or add it without a delegation tool", () => {
+ expect(
+ buildProfileToolsValue({
+ mode: "custom",
+ selected: ["task_tool_set", "task_tracker"],
+ }),
+ ).toHaveLength(2);
+ expect(
+ buildProfileToolsValue({ mode: "custom", selected: ["terminal"] }),
+ ).toEqual([{ name: "terminal", params: {} }]);
+ });
});
diff --git a/src/constants/profile-tools.ts b/src/constants/profile-tools.ts
index 697bc40456..fd54cdac86 100644
--- a/src/constants/profile-tools.ts
+++ b/src/constants/profile-tools.ts
@@ -35,6 +35,16 @@ export function readProfileTools(value: unknown): {
};
}
+const DELEGATION_TOOLS = ["task_tool_set", "workflow_tool_set"];
+
+/** Scoped sub-agents need task_tracker on the parent (SDK#5519). */
+function withSubAgentTaskTracker(selected: string[]): string[] {
+ const delegates = selected.some((name) => DELEGATION_TOOLS.includes(name));
+ return delegates && !selected.includes("task_tracker")
+ ? [...selected, "task_tracker"]
+ : selected;
+}
+
/** Build the `tools` value to persist: `null` for standard, else the picks. */
export function buildProfileToolsValue({
mode,
@@ -46,7 +56,7 @@ export function buildProfileToolsValue({
params?: Record<string, Record<string, SettingsValue>>;
}): ProfileToolSpec[] | null {
if (mode === "standard") return null;
- return selected.map((name) => ({
+ return withSubAgentTaskTracker(selected).map((name) => ({
name,
params: Object.hasOwn(params, name) ? params[name] : {},
}));