Skip to content

Commit 250b070

Browse files
committedNov 2, 2024
Merge branch 'main' of https://github.com/ai16z/eliza
2 parents 1417f0b + 95a87f0 commit 250b070

30 files changed

+424
-418
lines changed
 

‎.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
cache: "pnpm"
2121

2222
- name: Install dependencies
23-
run: pnpm i
23+
run: pnpm install --no-frozen-lockfile
2424

2525
- name: Run Prettier
2626
run: pnpm run prettier --check .

‎core/eslint.config.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export default [
3737

3838
// Disable no-undef as TypeScript handles this better
3939
"no-undef": "off",
40-
40+
"@typescript-eslint/no-unsafe-function-type": "off",
4141
// Customize TypeScript rules
42-
"@typescript-eslint/no-explicit-any": "warn", // Changed from error to warn
42+
"@typescript-eslint/no-explicit-any": "off",
4343
"@typescript-eslint/no-unused-vars": [
4444
"error",
4545
{

‎core/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99
"build": "tsc",
1010
"lint": "eslint . --fix",
1111
"start": "node --loader ts-node/esm src/index.ts",
12-
"start:arok": "node --loader ts-node/esm src/index.ts --characters=\"characters/arok.character.json\"",
12+
"start:arok": "node --loader ts-node/esm src/index.ts --characters=\"../characters/arok.character.json\"",
1313
"start:service:ruby": "pm2 start npm --name=\"ruby\" --restart-delay=3000 --max-restarts=10 -- run start:ruby",
1414
"stop:service:ruby": "pm2 stop ruby",
15-
"start:ruby": "node --loader ts-node/esm src/index.ts --characters=\"characters/ruby.character.json\"",
15+
"start:ruby": "node --loader ts-node/esm src/index.ts --characters=\"../characters/ruby.character.json\"",
1616
"start:service:trump": "pm2 start npm --name=\"trump\" --restart-delay=3000 --max-restarts=10 -- run start:trump",
1717
"stop:service:trump": "pm2 stop trump",
1818
"start:service:degen": "pm2 start npm --name=\"degen\" --restart-delay=3000 --max-restarts=10 -- run start:degen",
1919
"stop:service:degen": "pm2 stop degen",
20-
"start:degen": "node --loader ts-node/esm src/index.ts --characters=\"characters/degenspartan.json\"",
20+
"start:degen": "node --loader ts-node/esm src/index.ts --characters=\"../characters/degenspartan.json\"",
2121
"start:service:all": "pm2 start npm --name=\"all\" --restart-delay=3000 --max-restarts=10 -- run start:degen",
2222
"stop:service:all": "pm2 stop all",
23-
"start:all": "node --loader ts-node/esm src/index.ts --characters=\"characters/degenspartan.json\",\"characters/ruby.character.json\"",
24-
"start:trump": "node --loader ts-node/esm src/index.ts --characters=\"characters/trump.character.json\"",
23+
"start:all": "node --loader ts-node/esm src/index.ts --characters=\"../characters/degenspartan.json\",\"../characters/ruby.character.json\"",
24+
"start:trump": "node --loader ts-node/esm src/index.ts --characters=\"../characters/trump.character.json\"",
2525
"start:service:tate": "pm2 start npm --name=\"tate\" --restart-delay=3000 --max-restarts=10 -- run start:tate",
2626
"stop:service:tate": "pm2 stop tate",
27-
"start:tate": "node --loader ts-node/esm src/index.ts --characters=\"characters/tate.character.json\"",
27+
"start:tate": "node --loader ts-node/esm src/index.ts --characters=\"../characters/tate.character.json\"",
2828
"watch": "tsc --watch",
2929
"dev": "tsc && nodemon",
3030
"build:docs": "cd docs && npm run build",
@@ -93,6 +93,7 @@
9393
"@types/body-parser": "1.19.5",
9494
"@types/cors": "2.8.17",
9595
"@types/express": "5.0.0",
96+
"@types/uuid": "^10.0.0",
9697
"agent-twitter-client": "0.0.13",
9798
"ai": "^3.4.23",
9899
"alawmulaw": "6.0.0",
@@ -158,7 +159,6 @@
158159
"together-ai": "^0.7.0",
159160
"unique-names-generator": "4.7.1",
160161
"uuid": "11.0.2",
161-
"uuidv4": "6.2.13",
162162
"wav": "1.0.2",
163163
"wav-encoder": "1.3.0",
164164
"wavefile": "11.0.0",

‎core/src/actions/continue.ts

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const continueAction: Action = {
3838
validate: async (runtime: IAgentRuntime, message: Memory) => {
3939
const recentMessagesData = await runtime.messageManager.getMemories({
4040
roomId: message.roomId,
41+
agentId: runtime.agentId,
4142
count: 10,
4243
unique: false,
4344
});

‎core/src/adapters/postgres.ts

+23-14
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,24 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
102102

103103
async getMemoriesByRoomIds(params: {
104104
roomIds: UUID[];
105+
agentId?: UUID;
105106
tableName: string;
106107
}): Promise<Memory[]> {
107108
const client = await this.pool.connect();
108109
try {
109110
const placeholders = params.roomIds
110111
.map((_, i) => `$${i + 2}`)
111112
.join(", ");
112-
const { rows } = await client.query(
113-
`SELECT * FROM memories
114-
WHERE type = $1 AND "roomId" IN (${placeholders})`,
115-
[params.tableName, ...params.roomIds]
116-
);
113+
114+
let query = `SELECT * FROM memories WHERE type = $1 AND "roomId" IN (${placeholders})`;
115+
let queryParams = [params.tableName, ...params.roomIds];
116+
117+
if (params.agentId) {
118+
query += ` AND "userId" = $${params.roomIds.length + 2}`;
119+
queryParams = [...queryParams, params.agentId];
120+
}
121+
122+
const { rows } = await client.query(query, queryParams);
117123
return rows.map((row) => ({
118124
...row,
119125
content: JSON.parse(row.content),
@@ -271,7 +277,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
271277
`[${memory.embedding.join(",")}]`,
272278
memory.userId,
273279
memory.roomId,
274-
memory.unique ?? true,
280+
memory.unique ?? isUnique,
275281
Date.now(),
276282
]
277283
);
@@ -328,7 +334,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
328334
count?: number;
329335
unique?: boolean;
330336
tableName: string;
331-
userIds?: UUID[];
337+
agentId?: UUID;
332338
start?: number;
333339
end?: number;
334340
}): Promise<Memory[]> {
@@ -357,13 +363,9 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
357363
sql += " AND unique = true";
358364
}
359365

360-
if (params.userIds?.length) {
361-
const userPlaceholders = params.userIds
362-
.map((_, i) => `$${paramCount + 1 + i}`)
363-
.join(",");
364-
sql += ` AND "userId" IN (${userPlaceholders})`;
365-
values.push(...params.userIds);
366-
paramCount += params.userIds.length;
366+
if (params.agentId) {
367+
sql += " AND userId = $3";
368+
values.push(params.agentId);
367369
}
368370

369371
sql += ' ORDER BY "createdAt" DESC';
@@ -610,6 +612,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
610612
params: {
611613
match_threshold?: number;
612614
count?: number;
615+
agentId?: UUID;
613616
roomId?: UUID;
614617
unique?: boolean;
615618
tableName: string;
@@ -632,6 +635,12 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
632635

633636
if (params.unique) {
634637
sql += ` AND "unique" = true`;
638+
}
639+
640+
// TODO: Test this
641+
if (params.agentId) {
642+
sql += " AND userId = $3";
643+
values.push(params.agentId);
635644
}
636645

637646
if (params.roomId) {

‎core/src/adapters/sqlite.ts

+25-15
Original file line numberDiff line numberDiff line change
@@ -150,28 +150,31 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
150150
async getMemoriesByRoomIds(params: {
151151
roomIds: UUID[];
152152
tableName: string;
153+
agentId?: UUID;
153154
}): Promise<Memory[]> {
155+
console.log("getMemoriesByRoomIds", params);
154156
if (!params.tableName) {
155157
// default to messages
156158
params.tableName = "messages";
157159
}
158160
const placeholders = params.roomIds.map(() => "?").join(", ");
159-
const sql = `SELECT * FROM memories WHERE type = ? AND roomId IN (${placeholders})`;
160-
const stmt = this.db.prepare(sql);
161-
const queryParams = [params.tableName, ...params.roomIds];
161+
let sql = `SELECT * FROM memories WHERE type = ? AND roomId IN (${placeholders})`;
162+
let queryParams = [params.tableName, ...params.roomIds];
163+
164+
if (params.agentId) {
165+
sql += ` AND userId = ?`;
166+
queryParams.push(params.agentId);
167+
}
162168

163-
const memories: Memory[] = [];
169+
const stmt = this.db.prepare(sql);
164170
const rows = stmt.all(...queryParams) as (Memory & {
165171
content: string;
166172
})[];
167-
rows.forEach((row) => {
168-
memories.push({
169-
...row,
170-
content: JSON.parse(row.content),
171-
});
172-
});
173173

174-
return memories;
174+
return rows.map(row => ({
175+
...row,
176+
content: JSON.parse(row.content)
177+
}));
175178
}
176179

177180
async getMemoryById(memoryId: UUID): Promise<Memory | null> {
@@ -275,6 +278,7 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
275278
match_threshold?: number;
276279
count?: number;
277280
roomId?: UUID;
281+
agentId?: UUID;
278282
unique?: boolean;
279283
tableName: string;
280284
}
@@ -293,6 +297,12 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
293297
if (params.unique) {
294298
sql += " AND `unique` = 1";
295299
}
300+
// TODO: Test this
301+
if (params.agentId) {
302+
sql += " AND userId = ?";
303+
queryParams.push(params.agentId);
304+
}
305+
296306
if (params.roomId) {
297307
sql += " AND roomId = ?";
298308
queryParams.push(params.roomId);
@@ -384,7 +394,7 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
384394
count?: number;
385395
unique?: boolean;
386396
tableName: string;
387-
userIds?: UUID[];
397+
agentId?: UUID;
388398
start?: number;
389399
end?: number;
390400
}): Promise<Memory[]> {
@@ -402,9 +412,9 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
402412
sql += " AND `unique` = 1";
403413
}
404414

405-
if (params.userIds && params.userIds.length > 0) {
406-
sql += ` AND userId IN (${params.userIds.map(() => "?").join(",")})`;
407-
queryParams.push(...params.userIds);
415+
if (params.agentId) {
416+
sql += " AND userId = ?";
417+
queryParams.push(params.agentId);
408418
}
409419

410420
if (params.start) {

‎core/src/adapters/sqlite/sqliteTables.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ CREATE TABLE IF NOT EXISTS "memories" (
2222
"embedding" BLOB NOT NULL, -- TODO: EMBEDDING ARRAY, CONVERT TO BEST FORMAT FOR SQLITE-VSS (JSON?)
2323
"userId" TEXT,
2424
"roomId" TEXT,
25+
"agentId" TEXT,
2526
"unique" INTEGER DEFAULT 1 NOT NULL,
2627
FOREIGN KEY ("userId") REFERENCES "accounts"("id"),
27-
FOREIGN KEY ("roomId") REFERENCES "rooms"("id")
28+
FOREIGN KEY ("roomId") REFERENCES "rooms"("id"),
29+
FOREIGN KEY ("agentId") REFERENCES "accounts"("id")
2830
);
2931
3032
-- Table: goals

‎core/src/adapters/sqljs.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,16 @@ export class SqlJsDatabaseAdapter extends DatabaseAdapter {
5959
async getMemoriesByRoomIds(params: {
6060
roomIds: UUID[];
6161
tableName: string;
62+
agentId?: UUID;
6263
}): Promise<Memory[]> {
6364
const placeholders = params.roomIds.map(() => "?").join(", ");
64-
const sql = `SELECT * FROM memories WHERE type = ? AND roomId IN (${placeholders})`;
65+
let sql = `SELECT * FROM memories WHERE type = ? AND roomId IN (${placeholders})`;
6566
const stmt = this.db.prepare(sql);
6667
const queryParams = [params.tableName, ...params.roomIds];
68+
if (params.agentId) {
69+
sql += " AND userId = ?";
70+
queryParams.push(params.agentId);
71+
}
6772
stmt.bind(queryParams);
6873

6974
const memories: Memory[] = [];
@@ -298,6 +303,7 @@ export class SqlJsDatabaseAdapter extends DatabaseAdapter {
298303
match_threshold?: number;
299304
count?: number;
300305
roomId?: UUID;
306+
agentId?: UUID;
301307
unique?: boolean;
302308
tableName: string;
303309
}
@@ -315,6 +321,10 @@ export class SqlJsDatabaseAdapter extends DatabaseAdapter {
315321
if (params.roomId) {
316322
sql += " AND roomId = ?";
317323
}
324+
// TODO: Test this
325+
if (params.agentId) {
326+
sql += " AND userId = ?";
327+
}
318328
// TODO: Uncomment when we compile sql.js with vss
319329
// sql += ` ORDER BY similarity DESC`;
320330

@@ -426,7 +436,7 @@ export class SqlJsDatabaseAdapter extends DatabaseAdapter {
426436
count?: number;
427437
unique?: boolean;
428438
tableName: string;
429-
userIds?: UUID[];
439+
agentId?: UUID;
430440
start?: number;
431441
end?: number;
432442
}): Promise<Memory[]> {
@@ -450,8 +460,8 @@ export class SqlJsDatabaseAdapter extends DatabaseAdapter {
450460
sql += " AND `unique` = 1";
451461
}
452462

453-
if (params.userIds && params.userIds.length > 0) {
454-
sql += ` AND userId IN (${params.userIds.map(() => "?").join(",")})`;
463+
if (params.agentId) {
464+
sql += " AND userId = ?";
455465
}
456466

457467
sql += " ORDER BY createdAt DESC";
@@ -466,7 +476,7 @@ export class SqlJsDatabaseAdapter extends DatabaseAdapter {
466476
params.roomId,
467477
...(params.start ? [params.start] : []),
468478
...(params.end ? [params.end] : []),
469-
...(params.userIds || []),
479+
...(params.agentId ? [params.agentId] : []),
470480
...(params.count ? [params.count] : []),
471481
]);
472482
const memories: Memory[] = [];

‎core/src/adapters/supabase.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,20 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter {
102102

103103
async getMemoriesByRoomIds(params: {
104104
roomIds: UUID[];
105+
agentId?: UUID;
105106
tableName: string;
106107
}): Promise<Memory[]> {
107-
const { data, error } = await this.supabase
108+
let query = this.supabase
108109
.from(params.tableName)
109110
.select("*")
110111
.in("roomId", params.roomIds);
111112

113+
if (params.agentId) {
114+
query = query.eq("agentId", params.agentId);
115+
}
116+
117+
const { data, error } = await query;
118+
112119
if (error) {
113120
console.error("Error retrieving memories by room IDs:", error);
114121
return [];
@@ -260,7 +267,7 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter {
260267
count?: number;
261268
unique?: boolean;
262269
tableName: string;
263-
userIds?: UUID[];
270+
agentId?: UUID;
264271
start?: number;
265272
end?: number;
266273
}): Promise<Memory[]> {
@@ -281,8 +288,8 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter {
281288
query.eq("unique", true);
282289
}
283290

284-
if (params.userIds && params.userIds.length > 0) {
285-
query.in("userId", params.userIds);
291+
if (params.agentId) {
292+
query.eq("agentId", params.agentId);
286293
}
287294

288295
query.order("createdAt", { ascending: false });
@@ -306,18 +313,25 @@ export class SupabaseDatabaseAdapter extends DatabaseAdapter {
306313
match_threshold?: number;
307314
count?: number;
308315
roomId?: UUID;
316+
agentId?: UUID;
309317
unique?: boolean;
310318
tableName: string;
311319
}
312320
): Promise<Memory[]> {
313-
const result = await this.supabase.rpc("search_memories", {
321+
322+
const queryParams = {
314323
query_table_name: params.tableName,
315324
query_roomId: params.roomId,
316325
query_embedding: embedding,
317326
query_match_threshold: params.match_threshold,
318327
query_match_count: params.count,
319328
query_unique: !!params.unique,
320-
});
329+
}
330+
if (params.agentId) {
331+
(queryParams as any).query_agentId = params.agentId;
332+
}
333+
334+
const result = await this.supabase.rpc("search_memories", queryParams);
321335
if (result.error) {
322336
throw new Error(JSON.stringify(result.error));
323337
}

‎core/src/clients/discord/actions/summarize_conversation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const summarizeAction = {
145145
"CONVERSATION_SUMMARY",
146146
],
147147
description: "Summarizes the conversation and attachments.",
148-
validate: async (runtime: IAgentRuntime, message: Memory, state: State) => {
148+
validate: async (runtime: IAgentRuntime, message: Memory, _state: State) => {
149149
if (message.content.source !== "discord") {
150150
return false;
151151
}
@@ -199,7 +199,6 @@ const summarizeAction = {
199199
callback: HandlerCallback
200200
) => {
201201
state = (await runtime.composeState(message)) as State;
202-
const userId = runtime.agentId;
203202

204203
const callbackData: Content = {
205204
text: "", // fill in later
@@ -223,6 +222,7 @@ const summarizeAction = {
223222
// 2. get these memories from the database
224223
const memories = await runtime.messageManager.getMemories({
225224
roomId,
225+
agentId: runtime.agentId,
226226
// subtract start from current time
227227
start: parseInt(start as string),
228228
end: parseInt(end as string),

‎core/src/clients/discord/index.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,20 @@ import {
1010
User,
1111
} from "discord.js";
1212
import { EventEmitter } from "events";
13-
import { stringToUuid } from "../../core/uuid.ts";
14-
import { commands } from "./commands.ts";
15-
1613
import { embeddingZeroVector } from "../../core/memory.ts";
17-
import { MessageManager } from "./messages.ts";
18-
import { VoiceManager } from "./voice.ts";
19-
2014
import { Character, IAgentRuntime } from "../../core/types.ts";
15+
import { stringToUuid } from "../../core/uuid.ts";
2116
import chat_with_attachments from "./actions/chat_with_attachments.ts";
17+
import download_media from "./actions/download_media.ts";
2218
import joinvoice from "./actions/joinvoice.ts";
2319
import leavevoice from "./actions/leavevoice.ts";
2420
import summarize from "./actions/summarize_conversation.ts";
2521
import transcribe_media from "./actions/transcribe_media.ts";
26-
import download_media from "./actions/download_media.ts";
22+
import { commands } from "./commands.ts";
23+
import { MessageManager } from "./messages.ts";
2724
import channelStateProvider from "./providers/channelState.ts";
2825
import voiceStateProvider from "./providers/voiceState.ts";
26+
import { VoiceManager } from "./voice.ts";
2927

3028
export class DiscordClient extends EventEmitter {
3129
apiToken: string;

‎core/src/clients/discord/messages.ts

+9-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { ChannelType, Client, Message as DiscordMessage } from "discord.js";
1+
import { ChannelType, Client, Message as DiscordMessage, TextChannel } from "discord.js";
22
import { composeContext } from "../../core/context.ts";
3+
import {
4+
generateMessageResponse,
5+
generateShouldRespond,
6+
} from "../../core/generation.ts";
37
import { log_to_file } from "../../core/logger.ts";
48
import { embeddingZeroVector } from "../../core/memory.ts";
59
import {
@@ -12,19 +16,12 @@ import {
1216
State,
1317
UUID,
1418
} from "../../core/types.ts";
19+
import { stringToUuid } from "../../core/uuid.ts";
1520
import { generateSummary } from "../../services/summary.ts";
1621
import { AttachmentManager } from "./attachments.ts";
1722
import { messageHandlerTemplate, shouldRespondTemplate } from "./templates.ts";
1823
import { InterestChannels } from "./types.ts";
19-
20-
import { TextChannel } from "discord.js";
21-
import { stringToUuid } from "../../core/uuid.ts";
22-
import { SpeechService } from "../../services/speech.ts";
2324
import { VoiceManager } from "./voice.ts";
24-
import {
25-
generateMessageResponse,
26-
generateShouldRespond,
27-
} from "../../core/generation.ts";
2825

2926
const MAX_MESSAGE_LENGTH = 1900;
3027

@@ -123,7 +120,6 @@ export class MessageManager {
123120
this.client.user?.id /* || message.author?.bot*/
124121
)
125122
return;
126-
console.log("handling message");
127123
const userId = message.author.id as UUID;
128124
const userName = message.author.username;
129125
const name = message.author.displayName;
@@ -210,8 +206,6 @@ export class MessageManager {
210206
if (!shouldIgnore) {
211207
shouldIgnore = await this._shouldIgnore(message);
212208
}
213-
console.log("Received a message from ", message.author.username);
214-
console.log(message.content);
215209

216210
if (shouldIgnore) {
217211
return;
@@ -235,7 +229,6 @@ export class MessageManager {
235229
}
236230

237231
if (agentUserState === "FOLLOWED") {
238-
console.log("Always responding in followed room");
239232
shouldRespond = true; // Always respond in followed rooms
240233
} else if (
241234
(!shouldRespond && hasInterest) ||
@@ -262,8 +255,6 @@ export class MessageManager {
262255
context
263256
);
264257

265-
console.log("Response\n", responseContent);
266-
267258
responseContent.text = responseContent.text?.trim();
268259
responseContent.inReplyTo = stringToUuid(message.id);
269260

@@ -278,11 +269,9 @@ export class MessageManager {
278269
if (message.id && !content.inReplyTo) {
279270
content.inReplyTo = stringToUuid(message.id);
280271
}
281-
console.log("received callback", message.channel.type);
282272
if (message.channel.type === ChannelType.GuildVoice) {
283-
console.log("generating voice");
284273
// For voice channels, use text-to-speech
285-
const audioStream = await SpeechService.generate(
274+
const audioStream = await this.runtime.speechService.generate(
286275
this.runtime,
287276
content.text
288277
);
@@ -306,7 +295,7 @@ export class MessageManager {
306295
message.id,
307296
files
308297
);
309-
let notFirstMessage = false;
298+
310299
const memories: Memory[] = [];
311300
for (const m of messages) {
312301
let action = content.action;
@@ -319,7 +308,6 @@ export class MessageManager {
319308
action = "CONTINUE";
320309
}
321310

322-
notFirstMessage = true;
323311
const memory: Memory = {
324312
id: stringToUuid(m.id),
325313
userId: this.runtime.agentId,
@@ -359,7 +347,7 @@ export class MessageManager {
359347
if (message.channel.type === ChannelType.GuildVoice) {
360348
// For voice channels, use text-to-speech for the error message
361349
const errorMessage = "Sorry, I had a glitch. What was that?";
362-
const audioStream = await SpeechService.generate(
350+
const audioStream = await this.runtime.speechService.generate(
363351
this.runtime,
364352
errorMessage
365353
);
@@ -572,7 +560,6 @@ export class MessageManager {
572560
) {
573561
return true;
574562
}
575-
console.log("Not ignoring message:", message.content);
576563
return false;
577564
}
578565

‎core/src/clients/discord/voice.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import path from "path";
2222
import prism from "prism-media";
2323
import { Readable, pipeline } from "stream";
2424
import { composeContext } from "../../core/context.ts";
25+
import { generateMessageResponse } from "../../core/generation.ts";
2526
import { log_to_file } from "../../core/logger.ts";
2627
import { embeddingZeroVector } from "../../core/memory.ts";
2728
import {
@@ -35,10 +36,8 @@ import {
3536
} from "../../core/types.ts";
3637
import { stringToUuid } from "../../core/uuid.ts";
3738
import { getWavHeader } from "../../services/audioUtils.ts";
38-
import { SpeechService } from "../../services/speech.ts";
3939
import { AudioMonitor } from "./audioMonitor.ts";
4040
import { voiceHandlerTemplate } from "./templates.ts";
41-
import { generateMessageResponse } from "../../core/generation.ts";
4241

4342
const __dirname = path.dirname(new URL(import.meta.url).pathname);
4443

@@ -403,7 +402,7 @@ export class VoiceManager extends EventEmitter {
403402
state
404403
);
405404
const responseStream =
406-
await SpeechService.generate(
405+
await this.runtime.speechService.generate(
407406
this.runtime,
408407
content.text
409408
);

‎core/src/clients/telegram/src/messageManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class MessageManager {
108108
("document" in message &&
109109
message.document?.mime_type?.startsWith("image/"))
110110
) {
111-
return true;
111+
return false;
112112
}
113113

114114
// Use AI to decide for text or captions

‎core/src/clients/twitter/base.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ export class ClientBase extends EventEmitter {
379379
// Get the existing memories from the database
380380
const existingMemories =
381381
await this.runtime.messageManager.getMemoriesByRoomIds({
382+
agentId: this.runtime.agentId,
382383
roomIds: cachedResults.map((tweet) =>
383384
stringToUuid(tweet.conversationId)
384385
),
@@ -402,7 +403,9 @@ export class ClientBase extends EventEmitter {
402403

403404
// Save the missing tweets as memories
404405
for (const tweet of tweetsToSave) {
405-
const roomId = stringToUuid(tweet.conversationId);
406+
const roomId = stringToUuid(
407+
tweet.conversationId ?? "default-room-" + this.runtime.agentId
408+
);
406409
const tweetuserId =
407410
tweet.userId === this.twitterUserId
408411
? this.runtime.agentId
@@ -482,6 +485,7 @@ export class ClientBase extends EventEmitter {
482485
// Check the existing memories in the database
483486
const existingMemories =
484487
await this.runtime.messageManager.getMemoriesByRoomIds({
488+
agentId: this.runtime.agentId,
485489
roomIds: tweetUuids,
486490
});
487491

@@ -504,7 +508,7 @@ export class ClientBase extends EventEmitter {
504508

505509
// Save the new tweets as memories
506510
for (const tweet of tweetsToSave) {
507-
const roomId = stringToUuid(tweet.conversationId);
511+
const roomId = stringToUuid(tweet.conversationId ?? "default-room-" + this.runtime.agentId);
508512
const tweetuserId =
509513
tweet.userId === this.twitterUserId
510514
? this.runtime.agentId
@@ -558,6 +562,7 @@ export class ClientBase extends EventEmitter {
558562
const recentMessage = await this.runtime.messageManager.getMemories(
559563
{
560564
roomId: message.roomId,
565+
agentId: this.runtime.agentId,
561566
count: 1,
562567
unique: false,
563568
}

‎core/src/clients/twitter/utils.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Scraper, SearchMode, Tweet } from "agent-twitter-client";
2-
import { addHeader } from "../../core/context.ts";
3-
import { Content, IAgentRuntime, Memory, UUID } from "../../core/types.ts";
4-
import { ClientBase } from "./base.ts";
1+
import { Tweet } from "agent-twitter-client";
52
import { embeddingZeroVector } from "../../core/memory.ts";
3+
import { Content, Memory, UUID } from "../../core/types.ts";
64
import { stringToUuid } from "../../core/uuid.ts";
5+
import { ClientBase } from "./base.ts";
76

87
const MAX_TWEET_LENGTH = 280;
98

‎core/src/core/database.ts

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export abstract class DatabaseAdapter implements IDatabaseAdapter {
4646
}): Promise<Memory[]>;
4747

4848
abstract getMemoriesByRoomIds(params: {
49+
agentId?: UUID;
4950
roomIds: UUID[];
5051
tableName: string;
5152
}): Promise<Memory[]>;
@@ -133,6 +134,7 @@ export abstract class DatabaseAdapter implements IDatabaseAdapter {
133134
match_threshold?: number;
134135
count?: number;
135136
roomId?: UUID;
137+
agentId?: UUID;
136138
unique?: boolean;
137139
tableName: string;
138140
}

‎core/src/core/generation.ts

+58-50
Original file line numberDiff line numberDiff line change
@@ -69,57 +69,63 @@ export async function generateText({
6969
switch (provider) {
7070
case ModelProvider.OPENAI:
7171
case ModelProvider.LLAMACLOUD:
72-
console.log("Initializing OpenAI model.");
73-
const openai = createOpenAI({ apiKey });
74-
75-
const { text: openaiResponse } = await aiGenerateText({
76-
model: openai.languageModel(model),
77-
prompt: context,
78-
temperature: temperature,
79-
maxTokens: max_response_length,
80-
frequencyPenalty: frequency_penalty,
81-
presencePenalty: presence_penalty,
82-
});
83-
84-
response = openaiResponse;
85-
console.log("Received response from OpenAI model.");
86-
break;
72+
{
73+
console.log("Initializing OpenAI model.");
74+
const openai = createOpenAI({ apiKey });
75+
76+
const { text: openaiResponse } = await aiGenerateText({
77+
model: openai.languageModel(model),
78+
prompt: context,
79+
temperature: temperature,
80+
maxTokens: max_response_length,
81+
frequencyPenalty: frequency_penalty,
82+
presencePenalty: presence_penalty,
83+
});
84+
85+
response = openaiResponse;
86+
console.log("Received response from OpenAI model.");
87+
break;
88+
}
8789

8890
case ModelProvider.ANTHROPIC:
89-
console.log("Initializing Anthropic model.");
90-
const anthropicVertex = createAnthropicVertex();
91-
92-
const { text: anthropicResponse } = await aiGenerateText({
93-
model: anthropicVertex(model),
94-
prompt: context,
95-
temperature: temperature,
96-
maxTokens: max_response_length,
97-
frequencyPenalty: frequency_penalty,
98-
presencePenalty: presence_penalty,
99-
});
100-
101-
response = anthropicResponse;
102-
console.log("Received response from Anthropic model.");
103-
break;
91+
{
92+
console.log("Initializing Anthropic model.");
93+
const anthropicVertex = createAnthropicVertex();
94+
95+
const { text: anthropicResponse } = await aiGenerateText({
96+
model: anthropicVertex(model),
97+
prompt: context,
98+
temperature: temperature,
99+
maxTokens: max_response_length,
100+
frequencyPenalty: frequency_penalty,
101+
presencePenalty: presence_penalty,
102+
});
103+
104+
response = anthropicResponse;
105+
console.log("Received response from Anthropic model.");
106+
break;
107+
}
104108

105109
case ModelProvider.GROK:
106-
console.log("Initializing Grok model.");
107-
const grok = createGroq({ apiKey });
108-
109-
const { text: grokResponse } = await aiGenerateText({
110-
model: grok.languageModel(model, {
111-
parallelToolCalls: false,
112-
}),
113-
prompt: context,
114-
temperature: temperature,
115-
maxTokens: max_response_length,
116-
frequencyPenalty: frequency_penalty,
117-
presencePenalty: presence_penalty,
118-
});
119-
120-
response = grokResponse;
121-
console.log("Received response from Grok model.");
122-
break;
110+
{
111+
console.log("Initializing Grok model.");
112+
const grok = createGroq({ apiKey });
113+
114+
const { text: grokResponse } = await aiGenerateText({
115+
model: grok.languageModel(model, {
116+
parallelToolCalls: false,
117+
}),
118+
prompt: context,
119+
temperature: temperature,
120+
maxTokens: max_response_length,
121+
frequencyPenalty: frequency_penalty,
122+
presencePenalty: presence_penalty,
123+
});
124+
125+
response = grokResponse;
126+
console.log("Received response from Grok model.");
127+
break;
128+
}
123129

124130
case ModelProvider.LLAMALOCAL:
125131
console.log("Using local Llama model for text completion.");
@@ -135,9 +141,11 @@ export async function generateText({
135141
break;
136142

137143
default:
138-
const errorMessage = `Unsupported provider: ${provider}`;
139-
console.error(errorMessage);
140-
throw new Error(errorMessage);
144+
{
145+
const errorMessage = `Unsupported provider: ${provider}`;
146+
console.error(errorMessage);
147+
throw new Error(errorMessage);
148+
}
141149
}
142150

143151
return response;

‎core/src/core/memory.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ export class MemoryManager implements IMemoryManager {
6767
roomId,
6868
count = 10,
6969
unique = true,
70-
userIds,
70+
agentId,
7171
start,
7272
end,
7373
}: {
7474
roomId: UUID;
7575
count?: number;
7676
unique?: boolean;
77-
userIds?: UUID[];
77+
agentId?: UUID;
7878
start?: number;
7979
end?: number;
8080
}): Promise<Memory[]> {
@@ -83,7 +83,7 @@ export class MemoryManager implements IMemoryManager {
8383
count,
8484
unique,
8585
tableName: this.tableName,
86-
userIds,
86+
agentId,
8787
start,
8888
end,
8989
});
@@ -121,6 +121,7 @@ export class MemoryManager implements IMemoryManager {
121121
embedding: number[],
122122
opts: {
123123
match_threshold?: number;
124+
agentId?: UUID;
124125
count?: number;
125126
roomId: UUID;
126127
unique?: boolean;
@@ -168,8 +169,12 @@ export class MemoryManager implements IMemoryManager {
168169
);
169170
}
170171

171-
async getMemoriesByRoomIds(params: { roomIds: UUID[] }): Promise<Memory[]> {
172+
async getMemoriesByRoomIds(params: {
173+
agentId?: UUID;
174+
roomIds: UUID[];
175+
}): Promise<Memory[]> {
172176
const result = await this.runtime.databaseAdapter.getMemoriesByRoomIds({
177+
agentId: params.agentId,
173178
roomIds: params.roomIds,
174179
});
175180
return result;

‎core/src/core/runtime.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
IImageRecognitionService,
1919
IMemoryManager,
2020
IPdfService,
21+
ISpeechService,
2122
ITranscriptionService,
2223
IVideoService,
2324
ModelClass,
@@ -115,7 +116,7 @@ export class AgentRuntime implements IAgentRuntime {
115116
llamaService: LlamaService | null = null;
116117

117118
// services
118-
speechService: typeof SpeechService;
119+
speechService: ISpeechService;
119120

120121
transcriptionService: ITranscriptionService;
121122

@@ -207,6 +208,9 @@ export class AgentRuntime implements IAgentRuntime {
207208
opts.character.id ??
208209
opts.agentId ??
209210
stringToUuid(opts.character.name);
211+
212+
console.log("Agent ID", this.agentId);
213+
210214
this.fetch = (opts.fetch as typeof fetch) ?? this.fetch;
211215
this.character = opts.character || defaultCharacter;
212216
if (!opts.databaseAdapter) {
@@ -290,7 +294,7 @@ export class AgentRuntime implements IAgentRuntime {
290294
this.pdfService = new PdfService();
291295

292296
// static class, no need to instantiate but we can access it like a class instance
293-
this.speechService = SpeechService;
297+
this.speechService = new SpeechService();
294298

295299
if (
296300
opts.character &&
@@ -318,6 +322,7 @@ export class AgentRuntime implements IAgentRuntime {
318322
this.ensureParticipantExists(this.agentId, this.agentId);
319323

320324
for (const knowledgeItem of knowledge) {
325+
// TODO: Fix the knowledge???
321326
continue;
322327
const knowledgeId = stringToUuid(knowledgeItem);
323328
const existingDocument =
@@ -661,10 +666,12 @@ export class AgentRuntime implements IAgentRuntime {
661666
getActorDetails({ runtime: this, roomId }),
662667
this.messageManager.getMemories({
663668
roomId,
669+
agentId: this.agentId,
664670
count: conversationLength,
665671
unique: false,
666672
}),
667673
this.factManager.getMemories({
674+
agentId: this.agentId,
668675
roomId,
669676
count: recentFactsCount,
670677
}),
@@ -686,6 +693,7 @@ export class AgentRuntime implements IAgentRuntime {
686693
recentFactsData[0].embedding!,
687694
{
688695
roomId,
696+
agentId: this.agentId,
689697
count: relevantFactsCount,
690698
}
691699
)
@@ -825,6 +833,7 @@ Text: ${attachment.text}
825833
// Check the existing memories in the database
826834
const existingMemories =
827835
await this.messageManager.getMemoriesByRoomIds({
836+
agentId: this.agentId,
828837
// filter out the current room id from rooms
829838
roomIds: rooms.filter((room) => room !== roomId),
830839
});
@@ -1115,6 +1124,7 @@ Text: ${attachment.text}
11151124
const conversationLength = this.getConversationLength();
11161125
const recentMessagesData = await this.messageManager.getMemories({
11171126
roomId: state.roomId,
1127+
agentId: this.agentId,
11181128
count: conversationLength,
11191129
unique: false,
11201130
});

‎core/src/core/types.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Keypair } from "@solana/web3.js";
1+
import { Readable } from "stream";
22
import { ImageGenModel } from "./imageGenModels";
33

44
/**
@@ -148,6 +148,7 @@ export interface State {
148148
export interface Memory {
149149
id?: UUID; // An optional unique identifier for the memory.
150150
userId: UUID; // The user ID associated with the memory.
151+
agentId?: UUID; // The agent ID associated with the memory.
151152
createdAt?: number; // An optional timestamp indicating when the memory was created.
152153
content: Content; // The content of the memory, which can be a structured object or a plain string.
153154
embedding?: number[]; // An optional embedding vector representing the semantic content of the memory.
@@ -324,12 +325,15 @@ export interface IDatabaseAdapter {
324325
count?: number;
325326
unique?: boolean;
326327
tableName: string;
327-
userIds?: UUID[];
328+
agentId?: UUID;
328329
start?: number;
329330
end?: number;
330331
}): Promise<Memory[]>;
331332
getMemoryById(id: UUID): Promise<Memory | null>;
332-
getMemoriesByRoomIds(params: { roomIds: UUID[] }): Promise<Memory[]>;
333+
getMemoriesByRoomIds(params: {
334+
agentId?: UUID;
335+
roomIds: UUID[];
336+
}): Promise<Memory[]>;
333337
getCachedEmbeddings(params: {
334338
query_table_name: string;
335339
query_threshold: number;
@@ -363,6 +367,7 @@ export interface IDatabaseAdapter {
363367
match_threshold?: number;
364368
count?: number;
365369
roomId?: UUID;
370+
agentId?: UUID;
366371
unique?: boolean;
367372
tableName: string;
368373
}
@@ -426,22 +431,26 @@ export interface IMemoryManager {
426431
roomId: UUID;
427432
count?: number;
428433
unique?: boolean;
429-
userIds?: UUID[];
434+
agentId?: UUID;
430435
start?: number;
431436
end?: number;
432437
}): Promise<Memory[]>;
433438
getCachedEmbeddings(
434439
content: string
435440
): Promise<{ embedding: number[]; levenshtein_score: number }[]>;
436441
getMemoryById(id: UUID): Promise<Memory | null>;
437-
getMemoriesByRoomIds(params: { roomIds: UUID[] }): Promise<Memory[]>;
442+
getMemoriesByRoomIds(params: {
443+
roomIds: UUID[];
444+
agentId?: UUID;
445+
}): Promise<Memory[]>;
438446
searchMemoriesByEmbedding(
439447
embedding: number[],
440448
opts: {
441449
match_threshold?: number;
442450
count?: number;
443451
roomId: UUID;
444452
unique?: boolean;
453+
agentId?: UUID;
445454
}
446455
): Promise<Memory[]>;
447456
createMemory(memory: Memory, unique?: boolean): Promise<void>;
@@ -559,7 +568,9 @@ export interface IBrowserService {
559568
): Promise<{ title: string; description: string; bodyContent: string }>;
560569
}
561570

562-
export interface ISpeechService {}
571+
export interface ISpeechService {
572+
generate(runtime: IAgentRuntime, text: string): Promise<Readable>;
573+
}
563574

564575
export interface IPdfService {
565576
convertPdfToText(pdfBuffer: Buffer): Promise<string>;

‎core/src/providers/boredom.ts

+1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ const boredomProvider: Provider = {
282282

283283
const recentMessages = await runtime.messageManager.getMemories({
284284
roomId: message.roomId,
285+
agentId: runtime.agentId,
285286
start: fifteenMinutesAgo,
286287
end: now,
287288
count: 20,

‎core/src/providers/token.ts

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class TokenProvider {
4040
private tokenAddress: string
4141
) {
4242
this.cache = new NodeCache({ stdTTL: 300 }); // 5 minutes cache
43+
const __dirname = path.resolve();
4344
this.cacheDir = path.join(__dirname, "cache");
4445
if (!fs.existsSync(this.cacheDir)) {
4546
fs.mkdirSync(this.cacheDir);

‎core/src/services/speech.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async function textToSpeech(runtime: IAgentRuntime, text: string) {
107107
}
108108

109109
export class SpeechService implements ISpeechService {
110-
static async generate(
110+
async generate(
111111
runtime: IAgentRuntime,
112112
text: string
113113
): Promise<Readable> {

‎core/tests/continue.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ describe("User Profile", () => {
157157

158158
const agentMessages = await runtime.messageManager.getMemories({
159159
roomId,
160+
agentId: runtime.agentId,
160161
count: finalMessageCount - initialMessageCount,
161162
unique: false,
162163
});

‎core/tests/memory.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ describe("Memory - Basic tests", () => {
259259

260260
const createdMemories = await memoryManager.getMemories({
261261
roomId,
262+
agentId: runtime.agentId,
262263
count: 100,
263264
});
264265

‎package.json

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"preinstall": "npx only-allow pnpm",
55
"build": "pnpm --dir core build",
66
"build-docs": "pnpm --dir docs build",
7+
"start:all": "pnpm --dir core start:all",
8+
"stop:all": "pnpm --dir core stop:all",
9+
"start:service:all": "pnpm --dir core start:service:all",
10+
"stop:service:all": "pnpm --dir core stop:service:all",
711
"start": "pnpm --dir core start",
812
"dev": "pnpm --dir core dev",
913
"lint": "pnpm --dir core lint",

‎pnpm-lock.yaml

+188-201
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎supabase/migrations/20240318103238_remote_schema.sql

-61
Original file line numberDiff line numberDiff line change
@@ -344,57 +344,6 @@ $$;
344344

345345
ALTER FUNCTION "public"."get_goals"("query_roomId" "uuid", "query_userId" "uuid", "only_in_progress" boolean, "row_count" integer) OWNER TO "postgres";
346346

347-
CREATE OR REPLACE FUNCTION "public"."get_memories"("query_table_name" "text", "query_roomId" "uuid", "query_count" integer, "query_unique" boolean DEFAULT false, "query_userIds" "uuid"[] DEFAULT NULL)
348-
RETURNS TABLE("id" "uuid", "userId" "uuid", "content" "jsonb", "createdAt" timestamp with time zone, "roomId" "uuid", "embedding" "extensions"."vector")
349-
LANGUAGE "plpgsql"
350-
AS $_$
351-
DECLARE
352-
query TEXT;
353-
BEGIN
354-
query := format($fmt$
355-
SELECT
356-
id,
357-
userId,
358-
content,
359-
createdAt,
360-
roomId,
361-
embedding
362-
FROM memories
363-
WHERE TRUE
364-
AND type = %L
365-
%s -- Additional condition for 'unique' column based on query_unique
366-
%s -- Additional condition for roomId based on query_roomId
367-
%s -- Additional condition for userId based on query_userIds
368-
ORDER BY createdAt DESC
369-
LIMIT %L
370-
$fmt$,
371-
query_table_name,
372-
CASE WHEN query_unique THEN ' AND "unique" IS TRUE' ELSE '' END,
373-
CASE WHEN query_roomId IS NOT NULL THEN format(' AND roomId = %L', query_roomId) ELSE '' END,
374-
CASE WHEN query_userIds IS NOT NULL THEN format(' AND userId = ANY(ARRAY[%s])', array_to_string(query_userIds, ',')) ELSE '' END,
375-
query_count
376-
);
377-
378-
RETURN QUERY EXECUTE query;
379-
END;
380-
$_$;
381-
382-
ALTER FUNCTION "public"."get_memories"("query_table_name" "text", "query_roomId" "uuid", "query_count" integer, "query_unique" boolean, "query_userIds" "uuid"[]) OWNER TO "postgres";
383-
384-
CREATE OR REPLACE FUNCTION "public"."get_message_count"("p_userId" "uuid") RETURNS TABLE("roomId" "uuid", "unread_messages_count" integer)
385-
LANGUAGE "plpgsql"
386-
AS $$BEGIN
387-
RETURN QUERY
388-
SELECT p.roomId, COALESCE(COUNT(m.id)::integer, 0) AS unread_messages_count
389-
FROM participants p
390-
LEFT JOIN memories m ON p.roomId = m.roomId AND m.type = "messages"
391-
WHERE p.userId = p_userId
392-
GROUP BY p.roomId;
393-
END;
394-
$$;
395-
396-
ALTER FUNCTION "public"."get_message_count"("p_userId" "uuid") OWNER TO "postgres";
397-
398347
CREATE TABLE IF NOT EXISTS "public"."relationships" (
399348
"createdAt" timestamp with time zone DEFAULT ("now"() AT TIME ZONE 'utc'::"text") NOT NULL,
400349
"userA" "uuid",
@@ -708,16 +657,6 @@ GRANT ALL ON FUNCTION "public"."get_goals"("query_roomId" "uuid", "query_userId"
708657
GRANT ALL ON FUNCTION "public"."get_goals"("query_roomId" "uuid", "query_userId" "uuid", "only_in_progress" boolean, "row_count" integer) TO "supabase_admin";
709658
GRANT ALL ON FUNCTION "public"."get_goals"("query_roomId" "uuid", "query_userId" "uuid", "only_in_progress" boolean, "row_count" integer) TO "supabase_auth_admin";
710659

711-
GRANT ALL ON FUNCTION "public"."get_memories"("query_table_name" "text", "query_roomId" "uuid", "query_count" integer, "query_unique" boolean) TO "authenticated";
712-
GRANT ALL ON FUNCTION "public"."get_memories"("query_table_name" "text", "query_roomId" "uuid", "query_count" integer, "query_unique" boolean) TO "service_role";
713-
GRANT ALL ON FUNCTION "public"."get_memories"("query_table_name" "text", "query_roomId" "uuid", "query_count" integer, "query_unique" boolean) TO "supabase_admin";
714-
GRANT ALL ON FUNCTION "public"."get_memories"("query_table_name" "text", "query_roomId" "uuid", "query_count" integer, "query_unique" boolean) TO "supabase_auth_admin";
715-
716-
GRANT ALL ON FUNCTION "public"."get_message_count"("p_userId" "uuid") TO "authenticated";
717-
GRANT ALL ON FUNCTION "public"."get_message_count"("p_userId" "uuid") TO "service_role";
718-
GRANT ALL ON FUNCTION "public"."get_message_count"("p_userId" "uuid") TO "supabase_admin";
719-
GRANT ALL ON FUNCTION "public"."get_message_count"("p_userId" "uuid") TO "supabase_auth_admin";
720-
721660
GRANT ALL ON TABLE "public"."relationships" TO "authenticated";
722661
GRANT ALL ON TABLE "public"."relationships" TO "service_role";
723662
GRANT ALL ON TABLE "public"."relationships" TO "supabase_admin";

‎supabase/postgres-schema.sql

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ CREATE TABLE memories (
3737
"content" JSONB NOT NULL,
3838
"embedding" vector(1536),
3939
"userId" UUID REFERENCES accounts("id"),
40+
"agentId" UUID REFERENCES accounts("id"),
4041
"roomId" UUID REFERENCES rooms("id"),
4142
"unique" BOOLEAN DEFAULT true NOT NULL,
4243
CONSTRAINT fk_room FOREIGN KEY ("roomId") REFERENCES rooms("id") ON DELETE CASCADE,
43-
CONSTRAINT fk_user FOREIGN KEY ("userId") REFERENCES accounts("id") ON DELETE CASCADE
44+
CONSTRAINT fk_user FOREIGN KEY ("userId") REFERENCES accounts("id") ON DELETE CASCADE,
45+
CONSTRAINT fk_agent FOREIGN KEY ("agentId") REFERENCES accounts("id") ON DELETE CASCADE
4446
);
4547

4648
CREATE TABLE goals (

0 commit comments

Comments
 (0)
Please sign in to comment.