|
1 |
| -import { ChannelType, type IAgentRuntime, stringToUuid, type UUID } from "@elizaos/core"; |
| 1 | +import { ChannelType, type IAgentRuntime, Memory, stringToUuid, type UUID } from "@elizaos/core"; |
2 | 2 | import { v4 as uuidv4 } from 'uuid';
|
3 | 3 |
|
4 |
| -// |
| 4 | +async function sayMessage(participant: IAgentRuntime, roomMap, participants: IAgentRuntime[], message: string) { |
| 5 | + const participantId = participant.agentId; |
5 | 6 |
|
6 |
| -const scenarios = [ |
7 |
| - async function scenario1(members: IAgentRuntime[]) { |
8 |
| - const participant1 = members[0]; |
9 |
| - const participant2 = members[1]; |
| 7 | + // for each participant, create the memory |
| 8 | + for (const participant of [participants[0]]) { |
| 9 | + console.log("participant"); |
| 10 | + console.log(participant.agentId, participantId); |
| 11 | + if(participant.agentId === participantId) { |
| 12 | + continue; |
| 13 | + } |
10 | 14 |
|
11 |
| - const roomId = uuidv4() as UUID; |
12 |
| - |
13 |
| - await participant1.ensureConnection({ |
14 |
| - userId: participant1.agentId, |
| 15 | + const roomId = roomMap.get(participant.agentId); |
| 16 | + await participant.ensureConnection({ |
| 17 | + userId: participantId, |
15 | 18 | roomId,
|
16 |
| - userName: participant1.character.name, |
17 |
| - userScreenName: participant1.character.name, |
| 19 | + userName: participant.character.name, |
| 20 | + userScreenName: participant.character.name, |
18 | 21 | source: "scenario",
|
19 | 22 | type: ChannelType.GROUP,
|
20 | 23 | });
|
21 |
| - |
22 |
| - await participant2.ensureConnection({ |
23 |
| - userId: participant2.agentId, |
| 24 | + const memoryManager = participant.messageManager; |
| 25 | + const memory: Memory = { |
| 26 | + userId: participantId, |
| 27 | + agentId: participant.agentId, |
24 | 28 | roomId,
|
25 |
| - userName: participant2.character.name, |
26 |
| - userScreenName: participant2.character.name, |
27 |
| - source: "scenario", |
28 |
| - type: ChannelType.GROUP, |
29 |
| - }); |
| 29 | + content: { |
| 30 | + text: message, |
| 31 | + } |
| 32 | + } |
| 33 | + await memoryManager.createMemory(memory); |
| 34 | + |
| 35 | + // participant.emitEvent("MESSAGE_RECEIVED", { |
| 36 | + // runtime: participant, |
| 37 | + // message: memory, |
| 38 | + // roomId: roomId, |
| 39 | + // userId: participantId, |
| 40 | + // serverId: roomId, |
| 41 | + // channelId: roomId, |
| 42 | + // source: "scenario", |
| 43 | + // type: ChannelType.GROUP, |
| 44 | + // }); |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +const scenarios = [ |
| 49 | + async function scenario1(members: IAgentRuntime[]) { |
| 50 | + // create a map of member agentId to room UUID |
| 51 | + const roomMap = new Map<string, UUID>(); |
| 52 | + for (const member of members) { |
| 53 | + const roomId = uuidv4() as UUID; |
| 54 | + roomMap.set(member.agentId, roomId); |
| 55 | + } |
| 56 | + |
| 57 | + await sayMessage(members[0], roomMap, members, "Hello bob!"); |
| 58 | + await sayMessage(members[1], roomMap, members, "Hello alice!"); |
| 59 | + await sayMessage(members[0], roomMap, members, "Hello bob again!"); |
| 60 | + await sayMessage(members[1], roomMap, members, "Hello alice again!"); |
| 61 | + await sayMessage(members[2], roomMap, members, "I'm charlie!"); |
| 62 | + await sayMessage(members[0], roomMap, members, "Hello bob, how are you?"); |
| 63 | + await sayMessage(members[1], roomMap, members, "Hello alice, I'm good!"); |
| 64 | + await sayMessage(members[2], roomMap, members, "I'm good too!"); |
| 65 | + |
| 66 | + const conversations = await Promise.all(members.map(async (member) => { |
| 67 | + return member.messageManager.getMemories({ |
| 68 | + roomId: roomMap.get(member.agentId), |
| 69 | + }); |
| 70 | + })); |
| 71 | + console.log(conversations); |
30 | 72 | },
|
31 | 73 | ];
|
32 | 74 |
|
|
0 commit comments