Skip to content

Commit e066dd5

Browse files
committed
refactor agent and shell tools into their own respective directories.
1 parent c31546e commit e066dd5

30 files changed

+90
-81
lines changed

docs/tools/agent-tools.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
The agent tools provide ways to create and interact with sub-agents. There are two approaches available:
44

5-
1. The original `subAgent` tool (synchronous, blocking)
5+
1. The original `agentExecute` tool (synchronous, blocking)
66
2. The new `agentStart` and `agentMessage` tools (asynchronous, non-blocking)
77

8-
## subAgent Tool
8+
## agentExecute Tool
99

10-
The `subAgent` tool creates a sub-agent that runs synchronously until completion. The parent agent waits for the sub-agent to complete before continuing.
10+
The `agentExecute` tool creates a sub-agent that runs synchronously until completion. The parent agent waits for the sub-agent to complete before continuing.
1111

1212
```typescript
13-
subAgent({
13+
agentExecute({
1414
description: "A brief description of the sub-agent's purpose",
1515
goal: 'The main objective that the sub-agent needs to achieve',
1616
projectContext: 'Context about the problem or environment',
@@ -123,7 +123,7 @@ while (!agent1Completed || !agent2Completed) {
123123

124124
## Choosing Between Approaches
125125

126-
- Use `subAgent` for simpler tasks where blocking execution is acceptable
126+
- Use `agentExecute` for simpler tasks where blocking execution is acceptable
127127
- Use `agentStart` and `agentMessage` for:
128128
- Parallel execution of multiple sub-agents
129129
- Tasks where you need to monitor progress

packages/agent/src/core/toolAgent/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export function getDefaultSystemPrompt(toolContext: ToolContext): string {
146146
githubModeInstructions,
147147
'',
148148
'You prefer to call tools in parallel when possible because it leads to faster execution and less resource usage.',
149-
'When done, call the sequenceComplete tool with your results to indicate that the sequence has completed.',
149+
'When done, call the agentDone tool with your results to indicate that the sequence has completed.',
150150
'',
151151
'For coding tasks:',
152152
'0. Try to break large tasks into smaller sub-tasks that can be completed and verified sequentially.',

packages/agent/src/core/toolAgent/toolAgentCore.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('toolAgentCore empty response detection', () => {
1313
content: [
1414
{
1515
type: 'text',
16-
text: 'I notice you sent an empty response. If you are done with your tasks, please call the sequenceComplete tool with your results. If you are waiting for other tools to complete, you can use the sleep tool to wait before checking again.',
16+
text: 'I notice you sent an empty response. If you are done with your tasks, please call the agentDone tool with your results. If you are waiting for other tools to complete, you can use the sleep tool to wait before checking again.',
1717
},
1818
],
1919
});

packages/agent/src/core/toolAgent/toolAgentCore.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const toolAgent = async (
100100
messages.push({
101101
role: 'user',
102102
content:
103-
'I notice you sent an empty response. If you are done with your tasks, please call the sequenceComplete tool with your results. If you are waiting for other tools to complete, you can use the sleep tool to wait before checking again.',
103+
'I notice you sent an empty response. If you are done with your tasks, please call the agentDone tool with your results. If you are waiting for other tools to complete, you can use the sleep tool to wait before checking again.',
104104
});
105105
continue;
106106
}
@@ -129,8 +129,12 @@ export const toolAgent = async (
129129
);
130130

131131
// Execute the tools and get results
132-
const { sequenceCompleted, completionResult, respawn } =
133-
await executeTools(toolCalls, tools, messages, localContext);
132+
const { agentDoned, completionResult, respawn } = await executeTools(
133+
toolCalls,
134+
tools,
135+
messages,
136+
localContext,
137+
);
134138

135139
if (respawn) {
136140
logger.info('Respawning agent with new context');
@@ -143,7 +147,7 @@ export const toolAgent = async (
143147
continue;
144148
}
145149

146-
if (sequenceCompleted) {
150+
if (agentDoned) {
147151
const result: ToolAgentResult = {
148152
result: completionResult ?? 'Sequence explicitly completed',
149153
interactions,

packages/agent/src/core/toolAgent/toolExecutor.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function executeTools(
3232
context: ToolContext,
3333
): Promise<ToolCallResult> {
3434
if (toolCalls.length === 0) {
35-
return { sequenceCompleted: false, toolResults: [] };
35+
return { agentDoned: false, toolResults: [] };
3636
}
3737

3838
const { logger } = context;
@@ -46,7 +46,7 @@ export async function executeTools(
4646
addToolResultToMessages(messages, respawnCall.id, { success: true }, false);
4747

4848
return {
49-
sequenceCompleted: false,
49+
agentDoned: false,
5050
toolResults: [
5151
{
5252
toolCallId: respawnCall.id,
@@ -97,19 +97,17 @@ export async function executeTools(
9797
}),
9898
);
9999

100-
const sequenceCompletedTool = toolResults.find(
101-
(r) => r.toolName === 'sequenceComplete',
102-
);
103-
const completionResult = sequenceCompletedTool
104-
? (sequenceCompletedTool.result as { result: string }).result
100+
const agentDonedTool = toolResults.find((r) => r.toolName === 'agentDone');
101+
const completionResult = agentDonedTool
102+
? (agentDonedTool.result as { result: string }).result
105103
: undefined;
106104

107-
if (sequenceCompletedTool) {
105+
if (agentDonedTool) {
108106
logger.verbose('Sequence completed', { completionResult });
109107
}
110108

111109
return {
112-
sequenceCompleted: sequenceCompletedTool !== undefined,
110+
agentDoned: agentDonedTool !== undefined,
113111
completionResult,
114112
toolResults,
115113
};

packages/agent/src/core/toolAgent/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface ToolAgentResult {
77
}
88

99
export interface ToolCallResult {
10-
sequenceCompleted: boolean;
10+
agentDoned: boolean;
1111
completionResult?: string;
1212
toolResults: unknown[];
1313
respawn?: { context: string };

packages/agent/src/core/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { z } from 'zod';
22
import { JsonSchema7Type } from 'zod-to-json-schema';
33

4+
import { AgentTracker } from '../tools/agent/AgentTracker.js';
45
import { BrowserTracker } from '../tools/browser/browserTracker.js';
5-
import { AgentTracker } from '../tools/interaction/agentTracker.js';
6-
import { ShellTracker } from '../tools/system/shellTracker.js';
6+
import { ShellTracker } from '../tools/shell/ShellTracker.js';
77
import { Logger } from '../utils/logger.js';
88

99
import { TokenTracker } from './tokens.js';

packages/agent/src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
export * from './tools/io/fetch.js';
44

55
// Tools - System
6-
export * from './tools/system/shellStart.js';
6+
export * from './tools/shell/shellStart.js';
77
export * from './tools/system/sleep.js';
88
export * from './tools/system/respawn.js';
9-
export * from './tools/system/sequenceComplete.js';
10-
export * from './tools/system/shellMessage.js';
11-
export * from './tools/system/shellExecute.js';
12-
export * from './tools/system/listShells.js';
13-
export * from './tools/system/shellTracker.js';
9+
export * from './tools/agent/agentDone.js';
10+
export * from './tools/shell/shellMessage.js';
11+
export * from './tools/shell/shellExecute.js';
12+
export * from './tools/shell/listShells.js';
13+
export * from './tools/shell/ShellTracker.js';
1414

1515
// Tools - Browser
1616
export * from './tools/browser/BrowserManager.js';
@@ -22,9 +22,9 @@ export * from './tools/browser/BrowserAutomation.js';
2222
export * from './tools/browser/listBrowsers.js';
2323
export * from './tools/browser/browserTracker.js';
2424

25-
export * from './tools/interaction/agentTracker.js';
25+
export * from './tools/agent/AgentTracker.js';
2626
// Tools - Interaction
27-
export * from './tools/interaction/subAgent.js';
27+
export * from './tools/agent/agentExecute.js';
2828
export * from './tools/interaction/userPrompt.js';
2929

3030
// Core
File renamed without changes.

packages/agent/src/tools/system/sequenceComplete.ts renamed to packages/agent/src/tools/agent/agentDone.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const returnSchema = z.object({
1616
type Parameters = z.infer<typeof parameterSchema>;
1717
type ReturnType = z.infer<typeof returnSchema>;
1818

19-
export const sequenceCompleteTool: Tool<Parameters, ReturnType> = {
20-
name: 'sequenceComplete',
19+
export const agentDoneTool: Tool<Parameters, ReturnType> = {
20+
name: 'agentDone',
2121
description: 'Completes the tool use sequence and returns the final result',
2222
logPrefix: '✅',
2323
parameters: parameterSchema,

0 commit comments

Comments
 (0)