Skip to content

Commit 93d9ef8

Browse files
committed
Add skill tool to base2, update tools definitions
1 parent a9ffa4d commit 93d9ef8

File tree

5 files changed

+102
-49
lines changed

5 files changed

+102
-49
lines changed

agents/base2/base2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export function createBase2(
6262
'propose_str_replace',
6363
'propose_write_file',
6464
!noAskUser && 'ask_user',
65+
'skill',
6566
'set_output',
6667
),
6768
spawnableAgents: buildArray(

agents/types/tools.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type ToolName =
1919
| 'run_terminal_command'
2020
| 'set_messages'
2121
| 'set_output'
22+
| 'skill'
2223
| 'spawn_agents'
2324
| 'str_replace'
2425
| 'suggest_followups'
@@ -49,6 +50,7 @@ export interface ToolParamsMap {
4950
run_terminal_command: RunTerminalCommandParams
5051
set_messages: SetMessagesParams
5152
set_output: SetOutputParams
53+
skill: SkillParams
5254
spawn_agents: SpawnAgentsParams
5355
str_replace: StrReplaceParams
5456
suggest_followups: SuggestFollowupsParams
@@ -246,6 +248,14 @@ export interface SetMessagesParams {
246248
*/
247249
export interface SetOutputParams {}
248250

251+
/**
252+
* Load a skill's full instructions when relevant to the current task. Skills are loaded on-demand - only load them when you need their specific guidance.
253+
*/
254+
export interface SkillParams {
255+
/** The name of the skill to load */
256+
name: string
257+
}
258+
249259
/**
250260
* Spawn multiple agents and send a prompt and/or parameters to each of them. These agents will run in parallel. Note that that means they will run independently. If you need to run agents sequentially, use spawn_agents with one agent at a time instead.
251261
*/

common/src/templates/initial-agents-dir/types/tools.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ export type ToolName =
1010
| 'glob'
1111
| 'list_directory'
1212
| 'lookup_agent_info'
13+
| 'propose_str_replace'
14+
| 'propose_write_file'
1315
| 'read_docs'
1416
| 'read_files'
1517
| 'read_subtree'
1618
| 'run_file_change_hooks'
1719
| 'run_terminal_command'
1820
| 'set_messages'
1921
| 'set_output'
22+
| 'skill'
2023
| 'spawn_agents'
2124
| 'str_replace'
2225
| 'suggest_followups'
@@ -38,13 +41,16 @@ export interface ToolParamsMap {
3841
glob: GlobParams
3942
list_directory: ListDirectoryParams
4043
lookup_agent_info: LookupAgentInfoParams
44+
propose_str_replace: ProposeStrReplaceParams
45+
propose_write_file: ProposeWriteFileParams
4146
read_docs: ReadDocsParams
4247
read_files: ReadFilesParams
4348
read_subtree: ReadSubtreeParams
4449
run_file_change_hooks: RunFileChangeHooksParams
4550
run_terminal_command: RunTerminalCommandParams
4651
set_messages: SetMessagesParams
4752
set_output: SetOutputParams
53+
skill: SkillParams
4854
spawn_agents: SpawnAgentsParams
4955
str_replace: StrReplaceParams
5056
suggest_followups: SuggestFollowupsParams
@@ -149,6 +155,35 @@ export interface LookupAgentInfoParams {
149155
agentId: string
150156
}
151157

158+
/**
159+
* Propose string replacements in a file without actually applying them.
160+
*/
161+
export interface ProposeStrReplaceParams {
162+
/** The path to the file to edit. */
163+
path: string
164+
/** Array of replacements to make. */
165+
replacements: {
166+
/** The string to replace. This must be an *exact match* of the string you want to replace, including whitespace and punctuation. */
167+
old: string
168+
/** The string to replace the corresponding old string with. Can be empty to delete. */
169+
new: string
170+
/** Whether to allow multiple replacements of old string. */
171+
allowMultiple?: boolean
172+
}[]
173+
}
174+
175+
/**
176+
* Propose creating or editing a file without actually applying the changes.
177+
*/
178+
export interface ProposeWriteFileParams {
179+
/** Path to the file relative to the **project root** */
180+
path: string
181+
/** What the change is intended to do in only one sentence. */
182+
instructions: string
183+
/** Edit snippet to apply to the file. */
184+
content: string
185+
}
186+
152187
/**
153188
* Fetch up-to-date documentation for libraries and frameworks using Context7 API.
154189
*/
@@ -213,6 +248,14 @@ export interface SetMessagesParams {
213248
*/
214249
export interface SetOutputParams {}
215250

251+
/**
252+
* Load a skill's full instructions when relevant to the current task. Skills are loaded on-demand - only load them when you need their specific guidance.
253+
*/
254+
export interface SkillParams {
255+
/** The name of the skill to load */
256+
name: string
257+
}
258+
216259
/**
217260
* Spawn multiple agents and send a prompt and/or parameters to each of them. These agents will run in parallel. Note that that means they will run independently. If you need to run agents sequentially, use spawn_agents with one agent at a time instead.
218261
*/

packages/agent-runtime/src/run-agent-step.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ export async function loopAgentSteps(
627627
const tools = useParentTools
628628
? parentTools
629629
: await getToolSet({
630-
toolNames: agentTemplate.toolNames,
630+
toolNames: agentTemplate.toolNames,
631631
additionalToolDefinitions: async () => {
632632
if (!cachedAdditionalToolDefinitions) {
633633
cachedAdditionalToolDefinitions = await additionalToolDefinitions({
@@ -638,7 +638,7 @@ export async function loopAgentSteps(
638638
return cachedAdditionalToolDefinitions
639639
},
640640
agentTools,
641-
skills: fileContext.skills,
641+
skills: fileContext.skills ?? {},
642642
})
643643

644644
const hasUserMessage = Boolean(

packages/agent-runtime/src/tools/prompts.ts

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ function paramsSection(params: { schema: z.ZodType; endsAgentStep: boolean }) {
5858
const safeSchema = ensureJsonSchemaCompatible(schema)
5959
const schemaWithEndsAgentStepParam = endsAgentStep
6060
? safeSchema.and(
61-
z.object({
62-
[endsAgentStepParam]: z
63-
.literal(endsAgentStep)
64-
.describe('Easp flag must be set to true'),
65-
}),
66-
)
61+
z.object({
62+
[endsAgentStepParam]: z
63+
.literal(endsAgentStep)
64+
.describe('Easp flag must be set to true'),
65+
}),
66+
)
6767
: safeSchema
6868
const jsonSchema = toJsonSchemaSafe(schemaWithEndsAgentStepParam)
6969
delete jsonSchema.description
@@ -158,13 +158,13 @@ You (Buffy) have access to the following tools. Call them when needed.
158158
Tool calls use a specific XML and JSON-like format. Adhere *precisely* to this nested element structure:
159159
160160
${getToolCallString(
161-
'tool_name',
162-
{
163-
parameter1: 'value1',
164-
parameter2: 123,
165-
},
166-
false,
167-
)}
161+
'tool_name',
162+
{
163+
parameter1: 'value1',
164+
parameter2: 123,
165+
},
166+
false,
167+
)}
168168
169169
### Commentary
170170
@@ -178,20 +178,20 @@ User: can you update the console logs in example/file.ts?
178178
Assistant: Sure thing! Let's update that file!
179179
180180
${getToolCallString(
181-
'example_editing_tool',
182-
{
183-
example_file_path: 'path/to/example/file.ts',
184-
example_array: [
185-
{
186-
old_content_with_newlines:
187-
"// some context\nconsole.log('Hello world!');\n",
188-
new_content_with_newlines:
189-
"// some context\nconsole.log('Hello from Buffy!');\n",
190-
},
191-
],
192-
},
193-
false,
194-
)}
181+
'example_editing_tool',
182+
{
183+
example_file_path: 'path/to/example/file.ts',
184+
example_array: [
185+
{
186+
old_content_with_newlines:
187+
"// some context\nconsole.log('Hello world!');\n",
188+
new_content_with_newlines:
189+
"// some context\nconsole.log('Hello from Buffy!');\n",
190+
},
191+
],
192+
},
193+
false,
194+
)}
195195
196196
All done with the update!
197197
User: thanks it worked! :)
@@ -251,16 +251,16 @@ export const fullToolList = (
251251
}
252252
return desc
253253
}),
254-
...Object.keys(additionalToolDefinitions).map((toolName) => {
255-
const toolDef = additionalToolDefinitions[toolName]
256-
return buildToolDescription({
257-
toolName,
258-
schema: ensureZodSchema(toolDef.inputSchema),
259-
description: toolDef.description,
260-
endsAgentStep: toolDef.endsAgentStep ?? true,
261-
exampleInputs: toolDef.exampleInputs,
262-
})
263-
}), ]
254+
...Object.keys(additionalToolDefinitions).map((toolName) => {
255+
const toolDef = additionalToolDefinitions[toolName]
256+
return buildToolDescription({
257+
toolName,
258+
schema: ensureZodSchema(toolDef.inputSchema),
259+
description: toolDef.description,
260+
endsAgentStep: toolDef.endsAgentStep ?? true,
261+
exampleInputs: toolDef.exampleInputs,
262+
})
263+
}),]
264264

265265
return `## List of Tools
266266
@@ -309,13 +309,13 @@ Use the tools below to complete the user request, if applicable.
309309
Tool calls use a specific XML and JSON-like format. Adhere *precisely* to this nested element structure:
310310
311311
${getToolCallString(
312-
'tool_name',
313-
{
314-
parameter1: 'value1',
315-
parameter2: 123,
316-
},
317-
false,
318-
)}
312+
'tool_name',
313+
{
314+
parameter1: 'value1',
315+
parameter2: 123,
316+
},
317+
false,
318+
)}
319319
320320
Important: You only have access to the tools below. Do not use any other tools -- they are not available to you, instead they may have been previously used by other agents.
321321
@@ -327,13 +327,12 @@ export async function getToolSet(params: {
327327
toolNames: string[]
328328
additionalToolDefinitions: () => Promise<CustomToolDefinitions>
329329
agentTools: ToolSet
330-
skills?: SkillsMap
330+
skills: SkillsMap
331331
}): Promise<ToolSet> {
332332
const { toolNames, additionalToolDefinitions, agentTools, skills } = params
333333

334334
// Generate available skills XML for the skill tool description
335-
const availableSkillsXml = skills ? formatAvailableSkillsXml(skills) : ''
336-
335+
const availableSkillsXml = formatAvailableSkillsXml(skills)
337336
const toolSet: ToolSet = {}
338337
for (const toolName of toolNames) {
339338
if (toolName in toolParams) {

0 commit comments

Comments
 (0)