Skip to content

Commit 3c9dac1

Browse files
committed
Merge branch 'v2-develop' into v2-agent-cli
2 parents 25bca09 + c970fb5 commit 3c9dac1

File tree

9 files changed

+111
-34
lines changed

9 files changed

+111
-34
lines changed

bun.lockb

5.44 KB
Binary file not shown.

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

+13
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,
@@ -807,6 +811,15 @@ export class AgentRuntime implements IAgentRuntime {
807811
]);
808812
}
809813

814+
/**
815+
* Get a world by ID.
816+
* @param worldId - The ID of the world to get.
817+
* @returns The world.
818+
*/
819+
async getWorld(worldId: UUID) {
820+
return await this.databaseAdapter.getWorld(worldId);
821+
}
822+
810823
/**
811824
* Ensure the existence of a world.
812825
*/

packages/core/src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,8 @@ export interface IAgentRuntime {
10851085

10861086
getUserProfile(userId: UUID): Promise<Account | null>;
10871087

1088+
getWorld(worldId: UUID): Promise<WorldData | null>;
1089+
10881090
ensureWorldExists({
10891091
id,
10901092
name,

packages/plugin-discord/src/actions/voiceJoin.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,14 @@ export default {
125125
});
126126
return true;
127127
}
128-
const member = (discordMessage as DiscordMessage)
129-
.member as GuildMember;
128+
const guild = client.guilds.cache.get(serverId);
129+
const members = guild?.members.cache;
130+
131+
// get the member who's stringTouuid(id) === message userId
132+
const member = members?.find((member) => stringToUuid(member.id) === message.userId);
133+
134+
console.log("member", member);
135+
130136
if (member?.voice?.channel) {
131137
joinVoiceChannel({
132138
channelId: member.voice.channel.id,

packages/plugin-discord/src/providers/voiceState.ts

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { getVoiceConnection } from "@discordjs/voice";
2-
import { type Message as DiscordMessage, ChannelType as DiscordChannelType } from "discord.js";
32
import type { IAgentRuntime, Memory, Provider, State } from "@elizaos/core";
43
import { ChannelType } from "@elizaos/core";
54
const voiceStateProvider: Provider = {
@@ -27,17 +26,28 @@ const voiceStateProvider: Provider = {
2726
return `${agentName} is not currently in a voice channel`;
2827
}
2928

30-
const channel = (
31-
state?.discordMessage as DiscordMessage
32-
)?.guild?.channels?.cache?.get(
33-
connection.joinConfig.channelId as string
34-
);
29+
const worldId = room.worldId;
3530

36-
if (!channel || channel.type !== DiscordChannelType.GuildVoice) {
31+
// get the world from the runtime.getWorld
32+
const world = await runtime.getWorld(worldId);
33+
34+
if (!world) {
35+
throw new Error("No world found");
36+
}
37+
38+
const worldName = world.name;
39+
40+
const roomType = room.type;
41+
42+
const channelId = room.channelId
43+
44+
const channelName = room.name;
45+
46+
if (!channelId) {
3747
return `${agentName} is in an invalid voice channel`;
3848
}
3949

40-
return `${agentName} is currently in the voice channel: ${channel.name} (ID: ${channel.id})`;
50+
return `${agentName} is currently in the voice channel: ${channelName} (ID: ${channelId})`;
4151
},
4252
};
4353

packages/plugin-twitter/src/post.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ export class TwitterPostClient {
304304
"twitter"
305305
);
306306

307-
const topics = this.runtime.character.topics.join(", ");
307+
const topics = this.runtime.character.topics
308+
.sort(() => 0.5 - Math.random())
309+
.slice(0, 10)
310+
.join(", ")
308311
const state = await this.runtime.composeState(
309312
{
310313
userId: this.runtime.agentId,

0 commit comments

Comments
 (0)