Skip to content

Commit ad8f54f

Browse files
committed
Add "tags" to user message auxiliary schema. Deprecate timeToLive, keepDuringTruncation, keepLastTags
1 parent d2d0049 commit ad8f54f

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

common/src/types/messages/codebuff-message.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ import { providerMetadataSchema } from './provider-metadata'
1212

1313
const auxiliaryDataSchema = z.object({
1414
providerOptions: providerMetadataSchema.optional(),
15+
16+
tags: z.string().array().optional(),
17+
18+
// James: All the below is overly prescriptive for the framework.
19+
// Instead, let's tag what the message is, and let the user decide time to live, keep during truncation, etc.
20+
/** @deprecated Use tags instead. */
1521
timeToLive: z
1622
.union([z.literal('agentStep'), z.literal('userPrompt')])
1723
.optional(),
24+
/** @deprecated Use tags instead. */
1825
keepDuringTruncation: z.boolean().optional(),
26+
/** @deprecated Use tags instead. */
1927
keepLastTags: z.string().array().optional(),
2028
})
2129

common/src/util/messages.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ export function convertCbToModelMessages({
202202
const lastMessage = aggregated[aggregated.length - 1]
203203
if (
204204
lastMessage.timeToLive !== message.timeToLive ||
205-
!isEqual(lastMessage.providerOptions, message.providerOptions)
205+
!isEqual(lastMessage.providerOptions, message.providerOptions) ||
206+
!isEqual(lastMessage.tags, message.tags)
206207
) {
207208
aggregated.push(message)
208209
continue
@@ -227,9 +228,15 @@ export function convertCbToModelMessages({
227228
return aggregated
228229
}
229230

230-
// add cache control to specific messages
231-
for (const ttl of ['agentStep', 'userPrompt'] as const) {
232-
const index = aggregated.findIndex((m) => m.timeToLive === ttl)
231+
// Add cache control to specific messages (max of 4 can be marked for caching!):
232+
// - The message right before the three tagged messages
233+
// - Last message
234+
for (const tag of [
235+
'USER_PROMPT',
236+
'INSTRUCTIONS_PROMPT',
237+
'STEP_PROMPT',
238+
] as const) {
239+
const index = aggregated.findLastIndex((m) => m.tags?.includes(tag))
233240
if (index <= 0) {
234241
continue
235242
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ export const runAgentStep = async (
223223
stepPrompt && {
224224
role: 'user' as const,
225225
content: stepPrompt,
226+
tags: ['STEP_PROMPT'],
227+
228+
// James: Deprecate the below, only use tags, which are not prescriptive.
226229
timeToLive: 'agentStep' as const,
227230
keepDuringTruncation: true,
228231
},
@@ -567,6 +570,9 @@ export async function loopAgentSteps(
567570
// Actual user message!
568571
role: 'user' as const,
569572
content: buildUserMessageContent(prompt, spawnParams, content),
573+
tags: ['USER_PROMPT'],
574+
575+
// James: Deprecate the below, only use tags, which are not prescriptive.
570576
keepDuringTruncation: true,
571577
},
572578
prompt &&
@@ -583,6 +589,9 @@ export async function loopAgentSteps(
583589
instructionsPrompt && {
584590
role: 'user' as const,
585591
content: instructionsPrompt,
592+
tags: ['INSTRUCTIONS_PROMPT'],
593+
594+
// James: Deprecate the below, only use tags, which are not prescriptive.
586595
keepLastTags: ['INSTRUCTIONS_PROMPT'],
587596
},
588597
)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ export async function getAgentPrompt<T extends StringField>(
214214
spawnableAgents: agentTemplate.spawnableAgents,
215215
})
216216

217+
if (prompt.trim() === '') {
218+
return undefined
219+
}
220+
217221
let addendum = ''
218222

219223
if (promptType.type === 'stepPrompt' && agentState.agentType && prompt) {

0 commit comments

Comments
 (0)