Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/docs/content/docs/integrations/exa.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Search the web using Exa AI. Returns relevant search results with titles, URLs,

| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `query` | string | Yes | The search query to execute |
| `query` | string | Yes | The search query in plain words. Leave out any year or date unless the user asked about a specific time; to limit results by date, set startPublishedDate/endPublishedDate instead. |
| `numResults` | number | No | Number of results to return \(1-100\). Default: 10 |
| `type` | string | No | Search type: "auto", "lite", "deep-lite", or "deep" \("instant", "fast", and "deep-reasoning" are legacy\). Default: "auto" |
| `includeDomains` | string | No | Comma-separated list of domains to include in results \(e.g., "github.com, stackoverflow.com"\) |
Expand All @@ -51,8 +51,8 @@ Search the web using Exa AI. Returns relevant search results with titles, URLs,
| `maxAgeHours` | number | No | Cache freshness in hours \(-1 to 720\). 0 always crawls live, -1 uses cache only. Cannot be combined with livecrawl. |
| `livecrawlTimeout` | number | No | Live crawl timeout in milliseconds \(max 90000\). Default: 10000 |
| `livecrawl` | string | No | Deprecated: use maxAgeHours instead. Live crawling mode: never, fallback, always, or preferred |
| `startPublishedDate` | string | No | Only include results published on or after this ISO 8601 date \(e.g., "2024-01-01" or "2024-01-01T00:00:00.000Z"\) |
| `endPublishedDate` | string | No | Only include results published on or before this ISO 8601 date |
| `startPublishedDate` | string | No | Only include results published on or after this date, formatted YYYY-MM-DD \(or a full ISO 8601 timestamp\) |
| `endPublishedDate` | string | No | Only include results published on or before this date, formatted YYYY-MM-DD \(or a full ISO 8601 timestamp\) |
| `startCrawlDate` | string | No | Deprecated: use startPublishedDate. Only include results crawled on or after this ISO 8601 date |
| `endCrawlDate` | string | No | Deprecated: use endPublishedDate. Only include results crawled on or before this ISO 8601 date |
| `apiKey` | string | Yes | Exa AI API Key |
Expand Down
69 changes: 55 additions & 14 deletions apps/sim/executor/handlers/agent/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ mockExecuteProviderRequest.mockResolvedValue({
timing: { total: 100 },
})
const mockAgentLogger = getMockLogger('AgentBlockHandler')
const PINNED_NOW = new Date('2026-03-16T02:00:00.000Z')
const DATE_LINE = 'Current date: 2026-03-16.'

beforeAll(() => {
setEnvFlags({ isDev: true, isTest: false })
Expand All @@ -181,6 +183,8 @@ describe('AgentBlockHandler', () => {
let mockContext: ExecutionContext

beforeEach(() => {
vi.useFakeTimers({ toFake: ['Date'] })
vi.setSystemTime(PINNED_NOW)
handler = new AgentBlockHandler()
mockOpenAgentTurnSession.mockReset().mockResolvedValue(undefined)
mockValidateModelProvider.mockReset().mockResolvedValue(undefined)
Expand Down Expand Up @@ -299,6 +303,7 @@ describe('AgentBlockHandler', () => {
})

afterEach(() => {
vi.useRealTimers()
try {
Object.defineProperty(global, 'window', {
value: undefined,
Expand Down Expand Up @@ -448,8 +453,8 @@ describe('AgentBlockHandler', () => {
expect(mockExecuteProviderRequest).toHaveBeenCalledTimes(2)
for (const [, request, runtime] of mockExecuteProviderRequest.mock.calls) {
expect(runtime.agentConversation).toBe(session)
expect(request.messages[1]).toEqual(assistant)
expect(getEncryptedConversationMessage(request.messages[1])).toBe(
expect(request.messages[2]).toEqual(assistant)
expect(getEncryptedConversationMessage(request.messages[2])).toBe(
'encrypted-private-native-history'
)
}
Expand Down Expand Up @@ -515,8 +520,8 @@ describe('AgentBlockHandler', () => {
['turn-2', 'input'],
['turn-2', 'user-prompt'],
])
expect(mockExecuteProviderRequest.mock.calls[1][1].messages).toHaveLength(2)
expect(mockExecuteProviderRequest.mock.calls[2][1].messages).toHaveLength(4)
expect(mockExecuteProviderRequest.mock.calls[1][1].messages).toHaveLength(3)
expect(mockExecuteProviderRequest.mock.calls[2][1].messages).toHaveLength(5)
})

it('persists the complete captured answer when structured output removes its content field', async () => {
Expand Down Expand Up @@ -568,6 +573,41 @@ describe('AgentBlockHandler', () => {
})
})

it('tells the model the current date without writing it to memory', async () => {
dbChainMockFns.returning.mockResolvedValue([{ id: 'memory-1' }])
mockGetProviderFromModel.mockReturnValue('openai')

await handler.execute(mockContext, mockBlock, {
model: 'gpt-4o',
memoryType: 'conversation',
conversationId: 'conversation-1',
messages: [{ role: 'user', content: 'What happened in AI this week?' }],
})

const [, request] = mockExecuteProviderRequest.mock.calls[0]
expect(request.messages[0]).toEqual({ role: 'system', content: DATE_LINE })
const memoryWrites = dbChainMockFns.values.mock.calls
.map(([row]) => toRecord(row))
.filter((row) => Array.isArray(row.data))
expect(memoryWrites.length).toBeGreaterThan(0)
expect(JSON.stringify(memoryWrites)).not.toContain('Current date')
})

it('fills an empty system message with the date instead of the text "null"', async () => {
mockGetProviderFromModel.mockReturnValue('openai')

await handler.execute(mockContext, mockBlock, {
model: 'gpt-4o',
messages: [
{ role: 'system', content: null },
{ role: 'user', content: 'Summarize the news.' },
],
})

const [, request] = mockExecuteProviderRequest.mock.calls[0]
expect(request.messages[0]).toEqual({ role: 'system', content: DATE_LINE })
})

describe('conversation attachment replay', () => {
beforeEach(() => {
dbChainMockFns.returning.mockResolvedValue([{ id: 'memory-1' }])
Expand Down Expand Up @@ -648,7 +688,7 @@ describe('AgentBlockHandler', () => {
messages: [{ role: 'user', content: 'What is in that file?' }],
})
const request = mockExecuteProviderRequest.mock.calls.at(-1)?.[1]
expect(request.messages[0]).toMatchObject({
expect(request.messages[1]).toMatchObject({
role: 'user',
content: 'Analyze this file',
files: [{ key: file.key, base64: file.base64 }],
Expand Down Expand Up @@ -684,7 +724,7 @@ describe('AgentBlockHandler', () => {
messages: [{ role: 'user', content: 'Analyze this file' }],
files: [file],
})
expect(mockExecuteProviderRequest.mock.calls[0][1].messages[0].files).toHaveLength(1)
expect(mockExecuteProviderRequest.mock.calls[0][1].messages[1].files).toHaveLength(1)
expect(
dbChainMockFns.values.mock.calls.some(
([row]) => toRecord(toArray(toRecord(row).data)[0]).role === 'user'
Expand Down Expand Up @@ -964,7 +1004,7 @@ describe('AgentBlockHandler', () => {
executionId: ctx.executionId,
}
const expectedMessages = [
{ role: 'system', content: 'Use the conversation history.' },
{ role: 'system', content: `Use the conversation history.\n\n${DATE_LINE}` },
...(memoryType === 'sliding_window' ? history.slice(-2) : history),
{ role: 'user', content: 'What is my name?' },
]
Expand Down Expand Up @@ -1804,7 +1844,7 @@ describe('AgentBlockHandler', () => {
const rawInputs = structuredClone(inputs)
await handler.execute(mockContext, mockBlock, inputs)

expect(mockExecuteProviderRequest.mock.calls[0][1].messages[0].files).toEqual([
expect(mockExecuteProviderRequest.mock.calls[0][1].messages[1].files).toEqual([
expect.objectContaining({ name: '{{FILE_NAME}}.pdf', base64: 'JVBERi0=' }),
])
expect(inputs).toEqual(rawInputs)
Expand Down Expand Up @@ -1851,7 +1891,7 @@ describe('AgentBlockHandler', () => {
apiKey: 'test-api-key',
}
)
expect(mockExecuteProviderRequest.mock.calls[0][1].messages[0].files).toEqual([
expect(mockExecuteProviderRequest.mock.calls[0][1].messages[1].files).toEqual([
expect.objectContaining({ base64: 'aW1hZ2U=' }),
])
})
Expand Down Expand Up @@ -2274,7 +2314,7 @@ describe('AgentBlockHandler', () => {

const [, providerRequest, runtimeContext] = mockExecuteProviderRequest.mock.calls[0]
expect(providerRequest.messages).toEqual([
{ role: 'system', content: 'Box eSign stays public' },
{ role: 'system', content: `Box eSign stays public\n\n${DATE_LINE}` },
{ role: 'user', content: 'Box {{TOKEN}}' },
])
expect(runtimeContext.resolvedSecretTraceRegistry.getActiveMatches()).toEqual([])
Expand Down Expand Up @@ -2322,6 +2362,7 @@ describe('AgentBlockHandler', () => {
const [, providerRequest] = mockExecuteProviderRequest.mock.calls[0]
const modelInputRegistry = getProviderToolModelInputRegistry(providerRequest.tools[0])
expect(providerRequest.messages).toEqual([
{ role: 'system', content: DATE_LINE },
{ role: 'user', content: 'Use {{TEST_API_KEY_PERSONAL}}' },
])
expect(
Expand Down Expand Up @@ -2360,7 +2401,7 @@ describe('AgentBlockHandler', () => {

const [, providerRequest, runtimeContext] = mockExecuteProviderRequest.mock.calls[0]
expect(providerRequest.messages).toEqual([
{ role: 'system', content: 'Use {{TOKEN}}' },
{ role: 'system', content: `Use {{TOKEN}}\n\n${DATE_LINE}` },
{ role: 'user', content: 'Continue' },
])
expect(runtimeContext.resolvedSecretTraceRegistry.getActiveMatches()).toEqual([])
Expand Down Expand Up @@ -2415,7 +2456,7 @@ describe('AgentBlockHandler', () => {
const rawInputs = structuredClone(inputs)
await handler.execute(mockContext, mockBlock, inputs)

expect(mockExecuteProviderRequest.mock.calls[0][1].messages[0]).toEqual({
expect(mockExecuteProviderRequest.mock.calls[0][1].messages[1]).toEqual({
role: 'assistant',
content: 'Public x stays unchanged',
function_call: {
Expand Down Expand Up @@ -3051,7 +3092,7 @@ describe('AgentBlockHandler', () => {
// Check only one system message exists
const systemMessages = requestBody.messages.filter((msg: any) => msg.role === 'system')
expect(systemMessages.length).toBe(1)
expect(systemMessages[0].content).toBe('You are a helpful assistant.')
expect(systemMessages[0].content).toBe(`You are a helpful assistant.\n\n${DATE_LINE}`)
})

it('should prefix agent system message before legacy memories', async () => {
Expand Down Expand Up @@ -3083,7 +3124,7 @@ describe('AgentBlockHandler', () => {

// Agent's system message is prefixed first
expect(requestBody.messages[0].role).toBe('system')
expect(requestBody.messages[0].content).toBe('You are a helpful assistant.')
expect(requestBody.messages[0].content).toBe(`You are a helpful assistant.\n\n${DATE_LINE}`)
// Then legacy memories (with their system message preserved)
expect(requestBody.messages[1].role).toBe('system')
expect(requestBody.messages[1].content).toBe('Old system message from memories.')
Expand Down
30 changes: 20 additions & 10 deletions apps/sim/executor/handlers/agent/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ function persistsMemory(ctx: ExecutionContext, inputs: AgentInputs): boolean {
return Boolean(inputs.memoryType && inputs.memoryType !== 'none' && !ctx.sideEffects)
}

/** Appends a section to the first system message, or opens the conversation with it. */
function appendToSystemMessage(messages: Message[], section: string): void {
const systemIdx = messages.findIndex((m) => m.role === 'system')
if (systemIdx >= 0) {
const existing = messages[systemIdx].content
messages[systemIdx] = {
...messages[systemIdx],
content: existing ? existing + section : section.trim(),
}
} else {
messages.unshift({ role: 'system', content: section.trim() })
}
}

/** A stored conversation an Agent reads without opening a turn in it. */
type StoredAgentConversation = Awaited<ReturnType<typeof findStoredAgentConversation>>

Expand Down Expand Up @@ -1632,16 +1646,12 @@ export class AgentBlockHandler implements BlockHandler {

// 8. Inject skill metadata into the system message (progressive disclosure)
if (skillMetadata.length > 0) {
const skillSection = buildSkillsSystemPromptSection(skillMetadata)
const systemIdx = messages.findIndex((m) => m.role === 'system')
if (systemIdx >= 0) {
messages[systemIdx] = {
...messages[systemIdx],
content: messages[systemIdx].content + skillSection,
}
} else {
messages.unshift({ role: 'system', content: skillSection.trim() })
}
appendToSystemMessage(messages, buildSkillsSystemPromptSection(skillMetadata))
}

// 9. Tell the model today's date, which it otherwise takes to be its training cutoff
if (messages.length > 0) {
appendToSystemMessage(messages, `\n\nCurrent date: ${new Date().toISOString().slice(0, 10)}.`)
}

const messagesWithFiles = this.attachFilesToLastUserMessage(
Expand Down
8 changes: 5 additions & 3 deletions apps/sim/tools/exa/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export const searchTool: ToolConfig<ExaSearchParams, ExaSearchResponse> = {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The search query to execute',
description:
'The search query in plain words. Leave out any year or date unless the user asked about a specific time; to limit results by date, set startPublishedDate/endPublishedDate instead.',
},
numResults: {
type: 'number',
Expand Down Expand Up @@ -169,13 +170,14 @@ export const searchTool: ToolConfig<ExaSearchParams, ExaSearchResponse> = {
required: false,
visibility: 'user-or-llm',
description:
'Only include results published on or after this ISO 8601 date (e.g., "2024-01-01" or "2024-01-01T00:00:00.000Z")',
'Only include results published on or after this date, formatted YYYY-MM-DD (or a full ISO 8601 timestamp)',
},
endPublishedDate: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Only include results published on or before this ISO 8601 date',
description:
'Only include results published on or before this date, formatted YYYY-MM-DD (or a full ISO 8601 timestamp)',
},
startCrawlDate: {
type: 'string',
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/tools/generated/tool-metadata.ts

Large diffs are not rendered by default.

Loading