Skip to content

Commit d018e2c

Browse files
committed
add keepLastTags
1 parent 2b1a39a commit d018e2c

File tree

9 files changed

+35
-64
lines changed

9 files changed

+35
-64
lines changed

.agents/types/agent-definition.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ export interface AgentDefinition {
9292
params?: JsonObjectSchema
9393
}
9494

95-
/** Whether to include conversation history from the parent agent in context.
96-
*
97-
* Defaults to false.
98-
* Use this when the agent needs to know all the previous messages in the conversation.
99-
*/
100-
includeMessageHistory?: boolean
101-
10295
/** How the agent should output a response to its parent (defaults to 'last_message')
10396
*
10497
* last_message: The last message from the agent, typically after using tools.
@@ -121,6 +114,13 @@ export interface AgentDefinition {
121114
* This field is key if the agent is intended to be spawned by other agents. */
122115
spawnerPrompt?: string
123116

117+
/** Whether to include conversation history from the parent agent in context.
118+
*
119+
* Defaults to false.
120+
* Use this when the agent needs to know all the previous messages in the conversation.
121+
*/
122+
includeMessageHistory?: boolean
123+
124124
/** Whether to inherit the parent agent's system prompt instead of using this agent's own systemPrompt.
125125
*
126126
* Defaults to false.

.agents/types/util-types.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ const auxiliaryDataSchema = z.object({
142142
.union([z.literal('agentStep'), z.literal('userPrompt')])
143143
.optional(),
144144
keepDuringTruncation: z.boolean().optional(),
145+
keepLastTags: z.string().array().optional(),
145146
})
146147

147148
export const systemMessageSchema = z
@@ -184,22 +185,12 @@ export const toolMessageSchema = z
184185
.and(auxiliaryDataSchema)
185186
export type ToolMessage = z.infer<typeof toolMessageSchema>
186187

187-
export const messageSchema = z
188-
.union([
189-
systemMessageSchema,
190-
userMessageSchema,
191-
assistantMessageSchema,
192-
toolMessageSchema,
193-
])
194-
.and(
195-
z.object({
196-
providerOptions: providerMetadataSchema.optional(),
197-
timeToLive: z
198-
.union([z.literal('agentStep'), z.literal('userPrompt')])
199-
.optional(),
200-
keepDuringTruncation: z.boolean().optional(),
201-
}),
202-
)
188+
export const messageSchema = z.union([
189+
systemMessageSchema,
190+
userMessageSchema,
191+
assistantMessageSchema,
192+
toolMessageSchema,
193+
])
203194
export type Message = z.infer<typeof messageSchema>
204195

205196
// ===== MCP Server Types =====
@@ -227,7 +218,6 @@ export const mcpConfigSchema = z.union([
227218
])
228219
export type MCPConfig = z.input<typeof mcpConfigSchema>
229220

230-
231221
// ============================================================================
232222
// Logger Interface
233223
// ============================================================================

backend/src/llm-apis/vercel-ai-sdk/ai-sdk.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { google } from '@ai-sdk/google'
21
import { openai } from '@ai-sdk/openai'
32
import {
43
finetunedVertexModels,
@@ -97,6 +96,10 @@ export const promptAiSdkStream = async function* (
9796

9897
let aiSDKModel = modelToAiSDKModel(options.model)
9998

99+
console.log('\n\n\n\n\n\n\n\n\nasdf')
100+
console.dir({ messages: convertCbToModelMessages(options) }, { depth: null })
101+
console.log('qwer')
102+
100103
const response = streamText({
101104
...options,
102105
model: aiSDKModel,

backend/src/main-prompt.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ export const mainPrompt = async (
203203
clientSessionId,
204204
onResponseChunk,
205205
localAgentTemplates,
206-
clearUserPromptMessagesAfterResponse: false,
207206
})
208207

209208
logger.debug({ agentState, output }, 'Main prompt finished')

backend/src/run-agent-step.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ export const loopAgentSteps = async (
407407
userId,
408408
clientSessionId,
409409
onResponseChunk,
410-
clearUserPromptMessagesAfterResponse = false,
410+
clearUserPromptMessagesAfterResponse = true,
411411
parentSystemPrompt,
412412
}: {
413413
userInputId: string
@@ -528,8 +528,7 @@ export const loopAgentSteps = async (
528528
instructionsPrompt && {
529529
role: 'user' as const,
530530
content: instructionsPrompt,
531-
timeToLive: 'userPrompt' as const,
532-
keepDuringTruncation: true,
531+
keepLastTags: ['INSTRUCTIONS_PROMPT'],
533532
},
534533
)
535534

backend/src/tools/handlers/tool/spawn-agent-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export async function executeSubagent({
306306
clientSessionId,
307307
onResponseChunk,
308308
isOnlyChild = false,
309-
clearUserPromptMessagesAfterResponse = false,
309+
clearUserPromptMessagesAfterResponse = true,
310310
parentSystemPrompt,
311311
}: {
312312
ws: WebSocket

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ const auxiliaryDataSchema = z.object({
142142
.union([z.literal('agentStep'), z.literal('userPrompt')])
143143
.optional(),
144144
keepDuringTruncation: z.boolean().optional(),
145+
keepLastTags: z.string().array().optional(),
145146
})
146147

147148
export const systemMessageSchema = z
@@ -184,22 +185,12 @@ export const toolMessageSchema = z
184185
.and(auxiliaryDataSchema)
185186
export type ToolMessage = z.infer<typeof toolMessageSchema>
186187

187-
export const messageSchema = z
188-
.union([
189-
systemMessageSchema,
190-
userMessageSchema,
191-
assistantMessageSchema,
192-
toolMessageSchema,
193-
])
194-
.and(
195-
z.object({
196-
providerOptions: providerMetadataSchema.optional(),
197-
timeToLive: z
198-
.union([z.literal('agentStep'), z.literal('userPrompt')])
199-
.optional(),
200-
keepDuringTruncation: z.boolean().optional(),
201-
}),
202-
)
188+
export const messageSchema = z.union([
189+
systemMessageSchema,
190+
userMessageSchema,
191+
assistantMessageSchema,
192+
toolMessageSchema,
193+
])
203194
export type Message = z.infer<typeof messageSchema>
204195

205196
// ===== MCP Server Types =====
@@ -227,7 +218,6 @@ export const mcpConfigSchema = z.union([
227218
])
228219
export type MCPConfig = z.input<typeof mcpConfigSchema>
229220

230-
231221
// ============================================================================
232222
// Logger Interface
233223
// ============================================================================

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const auxiliaryDataSchema = z.object({
1616
.union([z.literal('agentStep'), z.literal('userPrompt')])
1717
.optional(),
1818
keepDuringTruncation: z.boolean().optional(),
19+
keepLastTags: z.string().array().optional(),
1920
})
2021

2122
export const systemMessageSchema = z
@@ -68,20 +69,10 @@ export const toolMessageSchema = z
6869
.and(auxiliaryDataSchema)
6970
export type ToolMessage = z.infer<typeof toolMessageSchema>
7071

71-
export const messageSchema = z
72-
.union([
73-
systemMessageSchema,
74-
userMessageSchema,
75-
assistantMessageSchema,
76-
toolMessageSchema,
77-
])
78-
.and(
79-
z.object({
80-
providerOptions: providerMetadataSchema.optional(),
81-
timeToLive: z
82-
.union([z.literal('agentStep'), z.literal('userPrompt')])
83-
.optional(),
84-
keepDuringTruncation: z.boolean().optional(),
85-
}),
86-
)
72+
export const messageSchema = z.union([
73+
systemMessageSchema,
74+
userMessageSchema,
75+
assistantMessageSchema,
76+
toolMessageSchema,
77+
])
8778
export type Message = z.infer<typeof messageSchema>

common/src/util/messages.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ export function convertCbToModelMessages({
211211

212212
const lastMessage = aggregated[aggregated.length - 1]
213213
if (
214-
lastMessage.keepDuringTruncation !== message.keepDuringTruncation ||
215214
lastMessage.timeToLive !== message.timeToLive ||
216215
!isEqual(lastMessage.providerOptions, message.providerOptions)
217216
) {

0 commit comments

Comments
 (0)