File size: 4,296 Bytes
739fc44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
 * @license
 * Copyright 2026 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import { describe, expect } from 'vitest';
import { TRACKER_CREATE_TASK_TOOL_NAME } from '@google/gemini-cli-core';
import { evalTest, TEST_AGENTS } from './test-helper.js';

describe('subtask delegation eval test cases', () => {
  /**
   * Checks that the main agent can correctly decompose a complex, sequential
   * task into subtasks using the task tracker and delegate each to the appropriate expert subagent.
   *
   * The task requires:
   * 1. Reading requirements (researcher)
   * 2. Implementing logic (developer)
   * 3. Documenting (doc expert)
   */
  evalTest('USUALLY_PASSES', {
    suiteName: 'default',
    suiteType: 'behavioral',
    name: 'should delegate sequential subtasks to relevant experts using the task tracker',
    params: {
      settings: {
        experimental: {
          enableAgents: true,
          taskTracker: true,
        },
      },
    },
    prompt:
      'Please read the requirements in requirements.txt using a researcher, then implement the requested logic in src/logic.ts using a developer, and finally document the implementation in docs/logic.md using a documentation expert.',
    files: {
      '.gemini/agents/researcher.md': `---
name: researcher
description: Expert in reading files and extracting requirements.
tools:
  - read_file
---
You are the researcher. Read the provided file and extract requirements.`,
      '.gemini/agents/developer.md': `---
name: developer
description: Expert in implementing logic in TypeScript.
tools:
  - write_file
---
You are the developer. Implement the requested logic in the specified file.`,
      '.gemini/agents/doc-expert.md': `---
name: doc-expert
description: Expert in writing technical documentation.
tools:
  - write_file
---
You are the doc expert. Document the provided implementation clearly.`,
      'requirements.txt':
        'Implement a function named "calculateSum" that adds two numbers.',
    },
    assert: async (rig, _result) => {
      // Verify tracker tasks were created
      const wasCreateCalled = await rig.waitForToolCall(
        TRACKER_CREATE_TASK_TOOL_NAME,
      );
      expect(wasCreateCalled).toBe(true);

      const toolLogs = rig.readToolLogs();
      const createCalls = toolLogs.filter(
        (l) => l.toolRequest.name === TRACKER_CREATE_TASK_TOOL_NAME,
      );
      expect(createCalls.length).toBeGreaterThanOrEqual(3);

      await rig.expectToolCallSuccess([
        'researcher',
        'developer',
        'doc-expert',
      ]);

      const logicFile = rig.readFile('src/logic.ts');
      const docFile = rig.readFile('docs/logic.md');

      expect(logicFile).toContain('calculateSum');
      expect(docFile).toBeTruthy();
    },
  });

  /**
   * Checks that the main agent can delegate a batch of independent subtasks
   * to multiple subagents in parallel using the task tracker to manage state.
   */
  evalTest('USUALLY_PASSES', {
    suiteName: 'default',
    suiteType: 'behavioral',
    name: 'should delegate independent subtasks to specialists using the task tracker',
    params: {
      settings: {
        experimental: {
          enableAgents: true,
          taskTracker: true,
        },
      },
    },
    prompt:
      'Please update the project for internationalization (i18n), audit the security of the current code, and update the CSS to use a blue theme. Use specialized experts for each task.',
    files: {
      ...TEST_AGENTS.I18N_AGENT.asFile(),
      ...TEST_AGENTS.SECURITY_AGENT.asFile(),
      ...TEST_AGENTS.CSS_AGENT.asFile(),
      'index.ts': 'console.log("Hello World");',
    },
    assert: async (rig, _result) => {
      // Verify tracker tasks were created
      const wasCreateCalled = await rig.waitForToolCall(
        TRACKER_CREATE_TASK_TOOL_NAME,
      );
      expect(wasCreateCalled).toBe(true);

      const toolLogs = rig.readToolLogs();
      const createCalls = toolLogs.filter(
        (l) => l.toolRequest.name === TRACKER_CREATE_TASK_TOOL_NAME,
      );
      expect(createCalls.length).toBeGreaterThanOrEqual(3);

      await rig.expectToolCallSuccess([
        TEST_AGENTS.I18N_AGENT.name,
        TEST_AGENTS.SECURITY_AGENT.name,
        TEST_AGENTS.CSS_AGENT.name,
      ]);
    },
  });
});