Skip to content

Commit 8c2c49e

Browse files
fix(models): memory fixes, provider code typing, cost calculation cleanup (#2515)
* improvement(memory): should not be block scoped * cleanup provider code * update other providers * cleanup fallback code * remove flaky test * fix memory * move streaming fix to right level * cleanup streaming server * make memories workspace scoped * update docs * fix dedup logic * fix streaming parsing issue for multiple onStream calls for same block * fix(provieders): support parallel agent tool calls, consolidate utils * address greptile comments * remove all comments * fixed openrouter response format handling, groq & cerebras response formats * removed duplicate type --------- Co-authored-by: waleed <[email protected]>
1 parent 086982c commit 8c2c49e

File tree

65 files changed

+12152
-4577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+12152
-4577
lines changed
Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Memory
3-
description: Add memory store
3+
description: Store and retrieve conversation history
44
---
55

66
import { BlockInfoCard } from "@/components/ui/block-info-card"
@@ -10,100 +10,94 @@ import { BlockInfoCard } from "@/components/ui/block-info-card"
1010
color="#F64F9E"
1111
/>
1212

13-
## Usage Instructions
14-
15-
Integrate Memory into the workflow. Can add, get a memory, get all memories, and delete memories.
13+
## Overview
1614

15+
The Memory block stores conversation history for agents. Each memory is identified by a `conversationId` that you provide. Multiple agents can share the same memory by using the same `conversationId`.
1716

17+
Memory stores only user and assistant messages. System messages are not stored—they are configured in the Agent block and prefixed at runtime.
1818

1919
## Tools
2020

2121
### `memory_add`
2222

23-
Add a new memory to the database or append to existing memory with the same ID.
23+
Add a message to memory. Creates a new memory if the `conversationId` doesn't exist, or appends to existing memory.
2424

2525
#### Input
2626

2727
| Parameter | Type | Required | Description |
2828
| --------- | ---- | -------- | ----------- |
29-
| `conversationId` | string | No | Conversation identifier \(e.g., user-123, session-abc\). If a memory with this conversationId already exists for this block, the new message will be appended to it. |
30-
| `id` | string | No | Legacy parameter for conversation identifier. Use conversationId instead. Provided for backwards compatibility. |
31-
| `role` | string | Yes | Role for agent memory \(user, assistant, or system\) |
32-
| `content` | string | Yes | Content for agent memory |
33-
| `blockId` | string | No | Optional block ID. If not provided, uses the current block ID from execution context, or defaults to "default". |
29+
| `conversationId` | string | Yes | Unique identifier for the conversation (e.g., `user-123`, `session-abc`) |
30+
| `role` | string | Yes | Message role: `user` or `assistant` |
31+
| `content` | string | Yes | Message content |
3432

3533
#### Output
3634

3735
| Parameter | Type | Description |
3836
| --------- | ---- | ----------- |
39-
| `success` | boolean | Whether the memory was added successfully |
40-
| `memories` | array | Array of memory objects including the new or updated memory |
41-
| `error` | string | Error message if operation failed |
37+
| `success` | boolean | Whether the operation succeeded |
38+
| `memories` | array | Updated memory array |
39+
| `error` | string | Error message if failed |
4240

4341
### `memory_get`
4442

45-
Retrieve memory by conversationId, blockId, blockName, or a combination. Returns all matching memories.
43+
Retrieve memory by conversation ID.
4644

4745
#### Input
4846

4947
| Parameter | Type | Required | Description |
5048
| --------- | ---- | -------- | ----------- |
51-
| `conversationId` | string | No | Conversation identifier \(e.g., user-123, session-abc\). If provided alone, returns all memories for this conversation across all blocks. |
52-
| `id` | string | No | Legacy parameter for conversation identifier. Use conversationId instead. Provided for backwards compatibility. |
53-
| `blockId` | string | No | Block identifier. If provided alone, returns all memories for this block across all conversations. If provided with conversationId, returns memories for that specific conversation in this block. |
54-
| `blockName` | string | No | Block name. Alternative to blockId. If provided alone, returns all memories for blocks with this name. If provided with conversationId, returns memories for that conversation in blocks with this name. |
49+
| `conversationId` | string | Yes | Conversation identifier |
5550

5651
#### Output
5752

5853
| Parameter | Type | Description |
5954
| --------- | ---- | ----------- |
60-
| `success` | boolean | Whether the memory was retrieved successfully |
61-
| `memories` | array | Array of memory objects with conversationId, blockId, blockName, and data fields |
62-
| `message` | string | Success or error message |
63-
| `error` | string | Error message if operation failed |
55+
| `success` | boolean | Whether the operation succeeded |
56+
| `memories` | array | Array of messages with `role` and `content` |
57+
| `error` | string | Error message if failed |
6458

6559
### `memory_get_all`
6660

67-
Retrieve all memories from the database
68-
69-
#### Input
70-
71-
| Parameter | Type | Required | Description |
72-
| --------- | ---- | -------- | ----------- |
61+
Retrieve all memories for the current workspace.
7362

7463
#### Output
7564

7665
| Parameter | Type | Description |
7766
| --------- | ---- | ----------- |
78-
| `success` | boolean | Whether all memories were retrieved successfully |
79-
| `memories` | array | Array of all memory objects with key, conversationId, blockId, blockName, and data fields |
80-
| `message` | string | Success or error message |
81-
| `error` | string | Error message if operation failed |
67+
| `success` | boolean | Whether the operation succeeded |
68+
| `memories` | array | All memory objects with `conversationId` and `data` fields |
69+
| `error` | string | Error message if failed |
8270

8371
### `memory_delete`
8472

85-
Delete memories by conversationId, blockId, blockName, or a combination. Supports bulk deletion.
73+
Delete memory by conversation ID.
8674

8775
#### Input
8876

8977
| Parameter | Type | Required | Description |
9078
| --------- | ---- | -------- | ----------- |
91-
| `conversationId` | string | No | Conversation identifier \(e.g., user-123, session-abc\). If provided alone, deletes all memories for this conversation across all blocks. |
92-
| `id` | string | No | Legacy parameter for conversation identifier. Use conversationId instead. Provided for backwards compatibility. |
93-
| `blockId` | string | No | Block identifier. If provided alone, deletes all memories for this block across all conversations. If provided with conversationId, deletes memories for that specific conversation in this block. |
94-
| `blockName` | string | No | Block name. Alternative to blockId. If provided alone, deletes all memories for blocks with this name. If provided with conversationId, deletes memories for that conversation in blocks with this name. |
79+
| `conversationId` | string | Yes | Conversation identifier to delete |
9580

9681
#### Output
9782

9883
| Parameter | Type | Description |
9984
| --------- | ---- | ----------- |
100-
| `success` | boolean | Whether the memory was deleted successfully |
101-
| `message` | string | Success or error message |
102-
| `error` | string | Error message if operation failed |
85+
| `success` | boolean | Whether the operation succeeded |
86+
| `message` | string | Confirmation message |
87+
| `error` | string | Error message if failed |
88+
89+
## Agent Memory Types
10390

91+
When using memory with an Agent block, you can configure how conversation history is managed:
10492

93+
| Type | Description |
94+
| ---- | ----------- |
95+
| **Full Conversation** | Stores all messages, limited by model's context window (uses 90% to leave room for response) |
96+
| **Sliding Window (Messages)** | Keeps the last N messages (default: 10) |
97+
| **Sliding Window (Tokens)** | Keeps messages that fit within a token limit (default: 4000) |
10598

10699
## Notes
107100

108-
- Category: `blocks`
109-
- Type: `memory`
101+
- Memory is scoped per workspace—workflows in the same workspace share the memory store
102+
- Use unique `conversationId` values to keep conversations separate (e.g., session IDs, user IDs, or UUIDs)
103+
- System messages belong in the Agent block configuration, not in memory

apps/sim/app/api/chat/[identifier]/route.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,6 @@ vi.mock('@/lib/core/utils/request', () => ({
7070
generateRequestId: vi.fn().mockReturnValue('test-request-id'),
7171
}))
7272

73-
vi.mock('@/app/api/workflows/[id]/execute/route', () => ({
74-
createFilteredResult: vi.fn().mockImplementation((result: any) => ({
75-
...result,
76-
logs: undefined,
77-
metadata: result.metadata
78-
? {
79-
...result.metadata,
80-
workflowConnections: undefined,
81-
}
82-
: undefined,
83-
})),
84-
}))
85-
8673
describe('Chat Identifier API Route', () => {
8774
const mockAddCorsHeaders = vi.fn().mockImplementation((response) => response)
8875
const mockValidateChatAuth = vi.fn().mockResolvedValue({ authorized: true })

apps/sim/app/api/chat/[identifier]/route.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ export async function POST(
206206

207207
const { createStreamingResponse } = await import('@/lib/workflows/streaming/streaming')
208208
const { SSE_HEADERS } = await import('@/lib/core/utils/sse')
209-
const { createFilteredResult } = await import('@/app/api/workflows/[id]/execute/route')
210209

211210
const workflowInput: any = { input, conversationId }
212211
if (files && Array.isArray(files) && files.length > 0) {
@@ -267,7 +266,6 @@ export async function POST(
267266
isSecureMode: true,
268267
workflowTriggerType: 'chat',
269268
},
270-
createFilteredResult,
271269
executionId,
272270
})
273271

0 commit comments

Comments
 (0)