Bläddra i källkod

refactor(agents): simplify task rejection contract

Alvin Unreal 2 veckor sedan
förälder
incheckning
95f2d77f00

+ 4 - 5
docs/background-orchestration.md

@@ -268,18 +268,17 @@ Include:
 
 ### Task-fit rejections
 
-A specialist may reject a task outside its role, permissions, or available
-context instead of attempting partial work. It returns:
+Specialists receive this instruction:
 
 ```text
+If an assignment is outside your role, permissions, or available context, reject it rather than partially attempting it. Respond exactly:
 <task_rejection>
 <reason>brief explanation for the orchestrator</reason>
-<recommended_agent>@agent-name when clear</recommended_agent>
 </task_rejection>
 ```
 
-`recommended_agent` is optional. The orchestrator uses the reason to reroute
-or clarify the task and must not retry the unchanged task with the same agent.
+The orchestrator inspects only the reason to reroute or clarify the task and
+must not retry the unchanged task with the same agent.
 
 Good background task prompt:
 

+ 2 - 2
src/agents/orchestrator.test.ts

@@ -16,8 +16,8 @@ describe('orchestrator prompt', () => {
     const prompt = buildOrchestratorPrompt();
 
     expect(prompt).toContain('Treat `<task_rejection>` as a routing signal');
-    expect(prompt).toContain('inspect its `<reason>`');
-    expect(prompt).toContain('optional `<recommended_agent>`');
+    expect(prompt).toContain('inspect only its `<reason>`');
+    expect(prompt).not.toContain('recommended_agent');
     expect(prompt).toContain(
       'Never reissue an unchanged task to the same agent',
     );

+ 1 - 1
src/agents/orchestrator.ts

@@ -201,7 +201,7 @@ Balance: respect dependencies, avoid parallelizing what must be sequential, and
 - Prefer \`task(..., background: true)\` for delegated work that can run independently.
 - For work already chosen for delegation, launch independent specialist lanes in the background so the orchestrator stays unblocked and can reconcile results when they return.
 - Track each task's specialist, objective, task/session ID, and file/topic ownership.
-- Treat \`<task_rejection>\` as a routing signal: inspect its \`<reason>\` and optional \`<recommended_agent>\`, then reroute or clarify.
+- Treat \`<task_rejection>\` as a routing signal: inspect only its \`<reason>\`, then reroute or clarify.
 - Never reissue an unchanged task to the same agent after a rejection; adjust its scope or context before retrying.
 - Continue orchestration only on non-overlapping work; otherwise briefly report what was launched and stop.
 - Before local edits or another writer task, compare against running task scopes.

+ 14 - 0
src/agents/task-rejection.test.ts

@@ -0,0 +1,14 @@
+import { describe, expect, test } from 'bun:test';
+import { TASK_REJECTION_INSTRUCTION } from './task-rejection';
+
+describe('task rejection instruction', () => {
+  test('requires only a reason in the rejection response', () => {
+    expect(
+      TASK_REJECTION_INSTRUCTION,
+    ).toBe(`If an assignment is outside your role, permissions, or available context, reject it rather than partially attempting it. Respond exactly:
+<task_rejection>
+<reason>brief explanation for the orchestrator</reason>
+</task_rejection>`);
+    expect(TASK_REJECTION_INSTRUCTION).not.toContain('recommended_agent');
+  });
+});

+ 2 - 5
src/agents/task-rejection.ts

@@ -1,10 +1,7 @@
-export const TASK_REJECTION_INSTRUCTION = `<TaskRejection>
-If the assignment is outside your role, permissions, or available context, reject it instead of attempting partial work. Respond exactly:
+export const TASK_REJECTION_INSTRUCTION = `If an assignment is outside your role, permissions, or available context, reject it rather than partially attempting it. Respond exactly:
 <task_rejection>
 <reason>brief explanation for the orchestrator</reason>
-<recommended_agent>@agent-name when clear, otherwise omit this tag</recommended_agent>
-</task_rejection>
-</TaskRejection>`;
+</task_rejection>`;
 
 export function appendTaskRejectionInstruction(prompt: string): string {
   return `${prompt}\n\n${TASK_REJECTION_INSTRUCTION}`;