Skip to content

Commit 5794367

Browse files
authored
Merge pull request #347 from drivecore/feature/sub-agent-modes-344
feat: implement sub-agent workflow modes (disabled, sync, async)
2 parents f0437be + a295455 commit 5794367

File tree

8 files changed

+166
-15
lines changed

8 files changed

+166
-15
lines changed

mycoder.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export default {
2020
// executablePath: null, // e.g., '/path/to/chrome'
2121
},
2222

23+
// Sub-agent workflow mode: 'disabled' (default), 'sync' (experimental), or 'async' (experimental)
24+
subAgentMode: 'disabled',
25+
2326
// Model settings
2427
//provider: 'anthropic',
2528
//model: 'claude-3-7-sonnet-20250219',

packages/agent/src/tools/getTools.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Tool } from '../core/types.js';
33

44
// Import tools
55
import { agentDoneTool } from './agent/agentDone.js';
6+
import { agentExecuteTool } from './agent/agentExecute.js';
67
import { agentMessageTool } from './agent/agentMessage.js';
78
import { agentStartTool } from './agent/agentStart.js';
89
import { listAgentsTool } from './agent/listAgents.js';
@@ -21,38 +22,52 @@ import { textEditorTool } from './textEditor/textEditor.js';
2122

2223
// Import these separately to avoid circular dependencies
2324

25+
/**
26+
* Sub-agent workflow modes
27+
* - disabled: No sub-agent tools are available
28+
* - sync: Parent agent waits for sub-agent completion before continuing
29+
* - async: Sub-agents run in the background, parent can check status and provide guidance
30+
*/
31+
export type SubAgentMode = 'disabled' | 'sync' | 'async';
32+
2433
interface GetToolsOptions {
2534
userPrompt?: boolean;
2635
mcpConfig?: McpConfig;
36+
subAgentMode?: SubAgentMode;
2737
}
2838

2939
export function getTools(options?: GetToolsOptions): Tool[] {
3040
const userPrompt = options?.userPrompt !== false; // Default to true if not specified
3141
const mcpConfig = options?.mcpConfig || { servers: [], defaultResources: [] };
42+
const subAgentMode = options?.subAgentMode || 'disabled'; // Default to disabled mode
3243

3344
// Force cast to Tool type to avoid TypeScript issues
3445
const tools: Tool[] = [
3546
textEditorTool as unknown as Tool,
36-
37-
//agentExecuteTool as unknown as Tool,
38-
agentStartTool as unknown as Tool,
39-
agentMessageTool as unknown as Tool,
40-
listAgentsTool as unknown as Tool,
41-
agentDoneTool as unknown as Tool,
42-
4347
fetchTool as unknown as Tool,
44-
4548
shellStartTool as unknown as Tool,
4649
shellMessageTool as unknown as Tool,
4750
listShellsTool as unknown as Tool,
48-
4951
sessionStartTool as unknown as Tool,
5052
sessionMessageTool as unknown as Tool,
5153
listSessionsTool as unknown as Tool,
52-
5354
waitTool as unknown as Tool,
5455
];
5556

57+
// Add agent tools based on the configured mode
58+
if (subAgentMode === 'sync') {
59+
// For sync mode, include only agentExecute and agentDone
60+
tools.push(agentExecuteTool as unknown as Tool);
61+
tools.push(agentDoneTool as unknown as Tool);
62+
} else if (subAgentMode === 'async') {
63+
// For async mode, include all async agent tools
64+
tools.push(agentStartTool as unknown as Tool);
65+
tools.push(agentMessageTool as unknown as Tool);
66+
tools.push(listAgentsTool as unknown as Tool);
67+
tools.push(agentDoneTool as unknown as Tool);
68+
}
69+
// For 'disabled' mode, no agent tools are added
70+
5671
// Only include user interaction tools if enabled
5772
if (userPrompt) {
5873
tools.push(userPromptTool as unknown as Tool);

packages/cli/src/commands/$default.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export async function executePrompt(
158158
const tools = getTools({
159159
userPrompt: config.userPrompt,
160160
mcpConfig: config.mcp,
161+
subAgentMode: config.subAgentMode,
161162
});
162163

163164
// Error handling

packages/cli/src/commands/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const command: CommandModule<object, ToolsArgs> = {
4141
describe: 'List all available tools and their capabilities',
4242
handler: () => {
4343
try {
44-
const tools = getTools();
44+
const tools = getTools({ subAgentMode: 'disabled' });
4545

4646
console.log('Available Tools:\n');
4747

packages/cli/src/options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type SharedOptions = {
1717
readonly githubMode?: boolean;
1818
readonly upgradeCheck?: boolean;
1919
readonly ollamaBaseUrl?: string;
20+
readonly subAgentMode?: 'disabled' | 'sync' | 'async';
2021
};
2122

2223
export const sharedOptions = {
@@ -100,4 +101,9 @@ export const sharedOptions = {
100101
type: 'string',
101102
description: 'Base URL for Ollama API (default: http://localhost:11434)',
102103
} as const,
104+
subAgentMode: {
105+
type: 'string',
106+
description: 'Sub-agent workflow mode (disabled, sync, or async)',
107+
choices: ['disabled', 'sync', 'async'],
108+
} as const,
103109
};

packages/cli/src/settings/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type Config = {
2020
upgradeCheck: boolean;
2121
tokenUsage: boolean;
2222
interactive: boolean;
23+
subAgentMode?: 'disabled' | 'sync' | 'async';
2324

2425
baseUrl?: string;
2526

@@ -77,6 +78,7 @@ const defaultConfig: Config = {
7778
upgradeCheck: true,
7879
tokenUsage: false,
7980
interactive: false,
81+
subAgentMode: 'disabled',
8082

8183
// MCP configuration
8284
mcp: {
@@ -103,6 +105,7 @@ export const getConfigFromArgv = (argv: ArgumentsCamelCase<SharedOptions>) => {
103105
upgradeCheck: argv.upgradeCheck,
104106
tokenUsage: argv.tokenUsage,
105107
interactive: argv.interactive,
108+
subAgentMode: argv.subAgentMode,
106109
};
107110
};
108111

packages/docs/docs/usage/configuration.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ export default {
118118

119119
### Behavior Customization
120120

121-
| Option | Description | Possible Values | Default |
122-
| -------------- | ------------------------------ | --------------- | ------- |
123-
| `customPrompt` | Custom instructions for the AI | Any string | `""` |
124-
| `githubMode` | Enable GitHub integration | `true`, `false` | `false` |
121+
| Option | Description | Possible Values | Default |
122+
| -------------- | ------------------------------ | --------------------------------- | --------- |
123+
| `customPrompt` | Custom instructions for the AI | Any string | `""` |
124+
| `githubMode` | Enable GitHub integration | `true`, `false` | `false` |
125+
| `subAgentMode` | Sub-agent workflow mode | `'disabled'`, `'sync'` (experimental), `'async'` (experimental) | `'disabled'` |
125126

126127
Example:
127128

@@ -209,5 +210,8 @@ export default {
209210
profile: true,
210211
tokenUsage: true,
211212
tokenCache: true,
213+
214+
// Sub-agent workflow mode
215+
subAgentMode: 'disabled', // Options: 'disabled', 'sync' (experimental), 'async' (experimental)
212216
};
213217
```
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
sidebar_position: 9
3+
---
4+
5+
# Sub-Agent Workflow Modes
6+
7+
MyCoder supports different modes for working with sub-agents, giving you flexibility in how tasks are distributed and executed. You can configure the sub-agent workflow mode based on your specific needs and resource constraints.
8+
9+
## Available Modes
10+
11+
MyCoder supports three distinct sub-agent workflow modes:
12+
13+
### 1. Disabled Mode (Default)
14+
15+
In this mode, sub-agent functionality is completely disabled:
16+
17+
- No sub-agent tools are available to the main agent
18+
- All tasks must be handled by the main agent directly
19+
- Useful for simpler tasks or when resource constraints are a concern
20+
- Reduces memory usage and API costs for straightforward tasks
21+
22+
### 2. Synchronous Mode ("sync") - Experimental
23+
24+
In synchronous mode, the parent agent waits for sub-agents to complete before continuing:
25+
26+
- Uses the `agentExecute` tool for synchronous execution
27+
- Parent agent waits for sub-agent completion before continuing its own workflow
28+
- Useful for tasks that require sequential execution
29+
- Simpler to reason about as there's no parallel execution
30+
- Good for tasks where later steps depend on the results of earlier steps
31+
32+
### 3. Asynchronous Mode ("async") - Experimental
33+
34+
In asynchronous mode, sub-agents run in parallel with the parent agent:
35+
36+
- Uses `agentStart`, `agentMessage`, and `listAgents` tools
37+
- Sub-agents run in the background while the parent agent continues its work
38+
- Parent agent can check status and provide guidance to sub-agents
39+
- Useful for complex tasks that can benefit from parallelization
40+
- More efficient for tasks that can be executed concurrently
41+
- Allows the parent agent to coordinate multiple sub-agents
42+
43+
## Configuration
44+
45+
You can set the sub-agent workflow mode in your `mycoder.config.js` file:
46+
47+
```javascript
48+
// mycoder.config.js
49+
export default {
50+
// Sub-agent workflow mode: 'disabled', 'sync' (experimental), or 'async' (experimental)
51+
subAgentMode: 'disabled', // Default value
52+
53+
// Other configuration options...
54+
};
55+
```
56+
57+
You can also specify the mode via the command line:
58+
59+
```bash
60+
mycoder --subAgentMode disabled "Implement a simple React component"
61+
```
62+
63+
## Choosing the Right Mode
64+
65+
Consider these factors when choosing a sub-agent workflow mode:
66+
67+
- **Task Complexity**: For complex tasks that can be broken down into independent parts, async mode is often best. For simpler tasks, disabled mode may be sufficient.
68+
69+
- **Resource Constraints**: Disabled mode uses fewer resources. Async mode can use more memory and API tokens but may complete complex tasks faster.
70+
71+
- **Task Dependencies**: If later steps depend heavily on the results of earlier steps, sync mode ensures proper sequencing.
72+
73+
- **Coordination Needs**: If you need to coordinate multiple parallel workflows, async mode gives you more control.
74+
75+
## Example: Using Different Modes
76+
77+
### Disabled Mode
78+
79+
Best for simple, focused tasks:
80+
81+
```javascript
82+
// mycoder.config.js
83+
export default {
84+
subAgentMode: 'disabled',
85+
// Other settings...
86+
};
87+
```
88+
89+
### Synchronous Mode
90+
91+
Good for sequential, dependent tasks:
92+
93+
```javascript
94+
// mycoder.config.js
95+
export default {
96+
subAgentMode: 'sync',
97+
// Other settings...
98+
};
99+
```
100+
101+
### Asynchronous Mode
102+
103+
Ideal for complex projects with independent components:
104+
105+
```javascript
106+
// mycoder.config.js
107+
export default {
108+
subAgentMode: 'async', // Experimental
109+
// Other settings...
110+
};
111+
```
112+
113+
## How It Works Internally
114+
115+
- In **disabled mode**, no agent tools are added to the available tools list.
116+
- In **sync mode**, only the `agentExecute` and `agentDone` tools are available, ensuring synchronous execution.
117+
- In **async mode**, the full suite of agent tools (`agentStart`, `agentMessage`, `listAgents`, and `agentDone`) is available, enabling parallel execution.
118+
119+
This implementation allows MyCoder to adapt to different task requirements while maintaining a consistent interface for users.

0 commit comments

Comments
 (0)