Skip to content

Commit c970fb5

Browse files
committed
basic hello world scenario does a thing
1 parent a5b1006 commit c970fb5

File tree

4 files changed

+70
-23
lines changed

4 files changed

+70
-23
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"check": "biome check --write .",
88
"preinstall": "npx only-allow bun",
99
"swarm": "turbo run build --filter=./packages/core && concurrently \"turbo run start --filter=@elizaos/agent -- --swarm \" \"turbo run start --filter=!@elizaos/agent --filter=!@elizaos/docs --filter=!@elizaos/core\"",
10+
"swarm:scenario": "turbo run build --filter=./packages/core && concurrently \"turbo run start --filter=@elizaos/agent -- --swarm --scenario \" \"turbo run start --filter=!@elizaos/agent --filter=!@elizaos/docs --filter=!@elizaos/core\"",
1011
"build": "turbo run build --filter=./packages/core && turbo run build --filter=./packages/*",
1112
"build:core": "turbo run build --filter=./packages/core",
1213
"build:cli": "turbo run build --filter=./packages/cli && cd packages/cli && bun link",

packages/agent/src/swarm/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import counselor from "./counselor";
1010

1111
export const swarm: {character: Character, init: (runtime: IAgentRuntime) => Promise<void>}[] = [
1212
complianceOfficer,
13-
// communityManager,
14-
// socialMediaManager,
15-
// counselor,
13+
communityManager,
14+
socialMediaManager,
15+
counselor,
1616
];
1717

1818
export default swarm;

packages/agent/src/swarm/scenario.ts

+62-20
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,74 @@
1-
import { ChannelType, type IAgentRuntime, stringToUuid, type UUID } from "@elizaos/core";
1+
import { ChannelType, type IAgentRuntime, Memory, stringToUuid, type UUID } from "@elizaos/core";
22
import { v4 as uuidv4 } from 'uuid';
33

4-
//
4+
async function sayMessage(participant: IAgentRuntime, roomMap, participants: IAgentRuntime[], message: string) {
5+
const participantId = participant.agentId;
56

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+
}
1014

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,
1518
roomId,
16-
userName: participant1.character.name,
17-
userScreenName: participant1.character.name,
19+
userName: participant.character.name,
20+
userScreenName: participant.character.name,
1821
source: "scenario",
1922
type: ChannelType.GROUP,
2023
});
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,
2428
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);
3072
},
3173
];
3274

packages/core/src/runtime.ts

+4
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,10 @@ export class AgentRuntime implements IAgentRuntime {
785785
channelId?: string,
786786
serverId?: string,
787787
}) {
788+
if(userId === this.agentId) {
789+
throw new Error("Agent should not connect to itself");
790+
}
791+
788792
await Promise.all([
789793
this.ensureUserExists(
790794
this.agentId,

0 commit comments

Comments
 (0)