Skip to content

Commit 3c4ab38

Browse files
committed
better context for sub-agents
1 parent 7c019fc commit 3c4ab38

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

packages/agent/src/tools/interaction/subAgent.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ const parameterSchema = z.object({
1313
goal: z
1414
.string()
1515
.describe('The main objective that the sub-agent needs to achieve'),
16-
context: z
16+
projectContext: z
17+
.string()
18+
.optional()
19+
.describe('Additional context about the project or environment'),
20+
fileContext: z
1721
.object({
1822
workingDirectory: z
1923
.string()
@@ -25,11 +29,10 @@ const parameterSchema = z.object({
2529
.describe(
2630
'List of files or regular expressions that are relevant to the task',
2731
),
28-
projectContext: z
29-
.string()
30-
.optional()
31-
.describe('Additional context about the project or environment'),
3232
})
33+
.describe(
34+
'When working with files and directories, it is best to be very specific to avoid sub-agents making incorrect assumptions',
35+
)
3336
.optional(),
3437
});
3538

@@ -67,21 +70,22 @@ export const subAgentTool: Tool<Parameters, ReturnType> = {
6770
returns: zodToJsonSchema(returnSchema),
6871
execute: async (params, { logger }) => {
6972
// Validate parameters
70-
const { goal, context } = parameterSchema.parse(params);
73+
const { description, goal, projectContext, fileContext } =
74+
parameterSchema.parse(params);
7175

7276
// Construct a well-structured prompt
7377
const prompt = [
78+
`Description: ${description}`,
7479
`Goal: ${goal}`,
75-
context
80+
projectContext ? `- Project Context: ${projectContext}` : '',
81+
82+
fileContext
7683
? `\nContext:\n${[
77-
context.workingDirectory
78-
? `- Working Directory: ${context.workingDirectory}`
79-
: '',
80-
context.relevantFiles?.length
81-
? `- Relevant Files:\n ${context.relevantFiles.map((f) => `- ${f}`).join('\n ')}`
84+
fileContext.workingDirectory
85+
? `- Working Directory: ${fileContext.workingDirectory}`
8286
: '',
83-
context.projectContext
84-
? `- Project Context: ${context.projectContext}`
87+
fileContext.relevantFiles?.length
88+
? `- Relevant Files:\n ${fileContext.relevantFiles.map((f) => `- ${f}`).join('\n ')}`
8589
: '',
8690
]
8791
.filter(Boolean)

0 commit comments

Comments
 (0)