Skip to content

Commit 30052b2

Browse files
committed
Only add tools, spawnable agents description if it has tools or spawnable agents
1 parent b2a8c30 commit 30052b2

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

packages/agent-runtime/src/templates/strings.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import {
44
getSystemInfoPrompt,
55
} from '../system-prompt/prompts'
66
import { getAgentTemplate } from './agent-registry'
7-
import {
8-
PLACEHOLDER,
9-
placeholderValues,
10-
} from './types'
7+
import { PLACEHOLDER, placeholderValues } from './types'
118
import { parseUserMessage } from '../util/messages'
129
import { CodebuffConfigSchema } from '@codebuff/common/json-config/constants'
1310
import { escapeString } from '@codebuff/common/util/string'
@@ -21,10 +18,7 @@ import {
2118
getToolsInstructions,
2219
} from '../tools/prompts'
2320

24-
import type {
25-
AgentTemplate,
26-
PlaceholderValue,
27-
} from './types'
21+
import type { AgentTemplate, PlaceholderValue } from './types'
2822
import type { Logger } from '@codebuff/common/types/contracts/logger'
2923
import type { ParamsExcluding } from '@codebuff/common/types/function-params'
3024
import type {
@@ -229,21 +223,24 @@ export async function getAgentPrompt<T extends StringField>(
229223

230224
// Add tool instructions, spawnable agents, and output schema prompts to instructionsPrompt
231225
if (promptType.type === 'instructionsPrompt' && agentState.agentType) {
226+
const hasTools = agentTemplate.toolNames.length > 0
232227
const toolsInstructions = agentTemplate.inheritParentSystemPrompt
233228
? fullToolList(agentTemplate.toolNames, await additionalToolDefinitions())
234229
: getShortToolInstructions(
235230
agentTemplate.toolNames,
236231
await additionalToolDefinitions(),
237232
)
233+
const hasSpawnableAgents = agentTemplate.spawnableAgents.length > 0
238234
addendum +=
239-
'\n\n' +
240-
toolsInstructions +
241-
'\n\n' +
242-
(await buildSpawnableAgentsDescription({
243-
...params,
244-
spawnableAgents: agentTemplate.spawnableAgents,
245-
agentTemplates,
246-
}))
235+
(hasTools ? '\n\n' + toolsInstructions : '') +
236+
(hasSpawnableAgents
237+
? '\n\n' +
238+
(await buildSpawnableAgentsDescription({
239+
...params,
240+
spawnableAgents: agentTemplate.spawnableAgents,
241+
agentTemplates,
242+
}))
243+
: '')
247244

248245
const parentInstructions = await collectParentInstructions({
249246
agentType: agentState.agentType,

0 commit comments

Comments
 (0)