Преглед изворни кода

refactor(agents): use plain task rejection reasons

Alvin Unreal пре 1 месец
родитељ
комит
9c3c517d1d

+ 4 - 11
docs/background-orchestration.md

@@ -268,17 +268,10 @@ Include:
 
 ### Task-fit rejections
 
-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>
-</task_rejection>
-```
-
-The orchestrator inspects only the reason to reroute or clarify the task and
-must not retry the unchanged task with the same agent.
+If a task is outside a specialist's role, permissions, or available context, it
+must not attempt partial work. It returns a brief reason to the orchestrator.
+The orchestrator treats that reason as routing input to reroute or clarify the
+task and must not retry the unchanged task with the same specialist.
 
 Good background task prompt:
 

+ 9 - 5
src/agents/orchestrator.test.ts

@@ -12,14 +12,18 @@ describe('orchestrator prompt', () => {
     expect(prompt).toContain('ordinary dialogue that does not block work');
   });
 
-  test('treats task rejections as routing signals', () => {
+  test('treats specialist rejection reasons as routing input', () => {
     const prompt = buildOrchestratorPrompt();
 
-    expect(prompt).toContain('Treat `<task_rejection>` as a routing signal');
-    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',
+      "Treat a specialist's rejection reason as routing input",
+    );
+    expect(prompt).toContain('reroute or clarify');
+    expect(prompt).not.toContain('task_rejection');
+    expect(prompt).not.toContain('<reason>');
+    expect(prompt).not.toMatch(/recommended[_ -]?agent/i);
+    expect(prompt).toContain(
+      'Never reissue an unchanged task to the same specialist',
     );
   });
 });

+ 2 - 2
src/agents/orchestrator.ts

@@ -201,8 +201,8 @@ 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 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.
+- Treat a specialist's rejection reason as routing input: reroute or clarify.
+- Never reissue an unchanged task to the same specialist 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.
 - Parallel background tasks are allowed only when their write scopes do not conflict.

+ 7 - 8
src/agents/task-rejection.test.ts

@@ -2,13 +2,12 @@ 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');
+  test('requires a plain reason-only response', () => {
+    expect(TASK_REJECTION_INSTRUCTION).toBe(
+      'If a task is outside your role, permissions, or available context, do not attempt partial work. Return a brief reason to the orchestrator.',
+    );
+    expect(TASK_REJECTION_INSTRUCTION).not.toMatch(
+      /<|>|task_rejection|recommended[_ -]?agent/i,
+    );
   });
 });

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

@@ -1,7 +1,5 @@
-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>
-</task_rejection>`;
+export const TASK_REJECTION_INSTRUCTION =
+  'If a task is outside your role, permissions, or available context, do not attempt partial work. Return a brief reason to the orchestrator.';
 
 export function appendTaskRejectionInstruction(prompt: string): string {
   return `${prompt}\n\n${TASK_REJECTION_INSTRUCTION}`;