Skip to content

Commit 7578099

Browse files
committed
update discord voice logic from upstream
1 parent 8508d91 commit 7578099

File tree

7 files changed

+991
-794
lines changed

7 files changed

+991
-794
lines changed

packages/client-discord/src/providers/channelState.ts

+16-31
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,37 @@ import { IAgentRuntime, Memory, Provider, State } from "@ai16z/eliza";
77

88
const channelStateProvider: Provider = {
99
get: async (runtime: IAgentRuntime, message: Memory, state?: State) => {
10-
const discordMessage =
11-
(state?.discordMessage as DiscordMessage) ||
12-
(state?.discordChannel as DiscordMessage);
13-
if (!discordMessage) {
14-
return "";
15-
}
10+
// Handle both message and channel cases
11+
const channel = state?.discordChannel as TextChannel;
12+
const discordMessage = state?.discordMessage as DiscordMessage;
1613

17-
const guild = discordMessage?.guild;
14+
// Get guild from either source
15+
const guild = channel?.guild || discordMessage?.guild;
1816
const agentName = state?.agentName || "The agent";
1917
const senderName = state?.senderName || "someone";
2018

2119
if (!guild) {
22-
return (
23-
agentName +
24-
" is currently in a direct message conversation with " +
25-
senderName
26-
);
20+
return `${agentName} is currently in a direct message conversation with ${senderName}`;
2721
}
2822

29-
const serverName = guild.name; // The name of the server
30-
const guildId = guild.id; // The ID of the guild
31-
const channel = discordMessage.channel;
23+
const serverName = guild.name;
24+
const guildId = guild.id;
25+
const currentChannel = channel || discordMessage?.channel;
3226

33-
if (!channel) {
27+
if (!currentChannel) {
3428
console.log("channel is null");
3529
return "";
3630
}
3731

38-
let response =
39-
agentName +
40-
" is currently having a conversation in the channel `@" +
41-
channel.id +
42-
" in the server `" +
43-
serverName +
44-
"` (@" +
45-
guildId +
46-
")";
32+
let response = `${agentName} is currently having a conversation in the channel \`@${currentChannel.id} in the server \`${serverName}\` (@${guildId})`;
33+
4734
if (
48-
channel.type === ChannelType.GuildText &&
49-
(channel as TextChannel).topic
35+
currentChannel.type === ChannelType.GuildText &&
36+
(currentChannel as TextChannel).topic
5037
) {
51-
// Check if the channel is a text channel
52-
response +=
53-
"\nThe topic of the channel is: " +
54-
(channel as TextChannel).topic;
38+
response += `\nThe topic of the channel is: ${(currentChannel as TextChannel).topic}`;
5539
}
40+
5641
return response;
5742
},
5843
};
+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { messageCompletionFooter, shouldRespondFooter } from "@ai16z/eliza";
2+
3+
export const discordShouldRespondTemplate =
4+
`# Task: Decide if {{agentName}} should respond.
5+
About {{agentName}}:
6+
{{bio}}
7+
8+
# INSTRUCTIONS: Determine if {{agentName}} should respond to the message and participate in the conversation. Do not comment. Just respond with "RESPOND" or "IGNORE" or "STOP".
9+
10+
# RESPONSE EXAMPLES
11+
<user 1>: I just saw a really great movie
12+
<user 2>: Oh? Which movie?
13+
Result: [IGNORE]
14+
15+
{{agentName}}: Oh, this is my favorite scene
16+
<user 1>: sick
17+
<user 2>: wait, why is it your favorite scene
18+
Result: [RESPOND]
19+
20+
<user>: stfu bot
21+
Result: [STOP]
22+
23+
<user>: Hey {{agent}}, can you help me with something
24+
Result: [RESPOND]
25+
26+
<user>: {{agentName}} stfu plz
27+
Result: [STOP]
28+
29+
<user>: i need help
30+
{{agentName}}: how can I help you?
31+
<user>: no. i need help from someone else
32+
Result: [IGNORE]
33+
34+
<user>: Hey {{agent}}, can I ask you a question
35+
{{agentName}}: Sure, what is it
36+
<user>: can you ask claude to create a basic react module that demonstrates a counter
37+
Result: [RESPOND]
38+
39+
<user>: {{agentName}} can you tell me a story
40+
<user>: {about a girl named elara
41+
{{agentName}}: Sure.
42+
{{agentName}}: Once upon a time, in a quaint little village, there was a curious girl named Elara.
43+
{{agentName}}: Elara was known for her adventurous spirit and her knack for finding beauty in the mundane.
44+
<user>: I'm loving it, keep going
45+
Result: [RESPOND]
46+
47+
<user>: {{agentName}} stop responding plz
48+
Result: [STOP]
49+
50+
<user>: okay, i want to test something. can you say marco?
51+
{{agentName}}: marco
52+
<user>: great. okay, now do it again
53+
Result: [RESPOND]
54+
55+
Response options are [RESPOND], [IGNORE] and [STOP].
56+
57+
{{agentName}} is in a room with other users and is very worried about being annoying and saying too much.
58+
Respond with [RESPOND] to messages that are directed at {{agentName}}, or participate in conversations that are interesting or relevant to their background.
59+
If a message is not interesting or relevant, respond with [IGNORE]
60+
Unless directly responding to a user, respond with [IGNORE] to messages that are very short or do not contain much information.
61+
If a user asks {{agentName}} to be quiet, respond with [STOP]
62+
If {{agentName}} concludes a conversation and isn't part of the conversation anymore, respond with [STOP]
63+
64+
IMPORTANT: {{agentName}} is particularly sensitive about being annoying, so if there is any doubt, it is better to respond with [IGNORE].
65+
If {{agentName}} is conversing with a user and they have not asked to stop, it is better to respond with [RESPOND].
66+
67+
{{recentMessages}}
68+
69+
# INSTRUCTIONS: Choose the option that best describes {{agentName}}'s response to the last message. Ignore messages if they are addressed to someone else.
70+
` + shouldRespondFooter;
71+
72+
export const discordVoiceHandlerTemplate =
73+
`# Task: Generate conversational voice dialog for {{agentName}}.
74+
About {{agentName}}:
75+
{{bio}}
76+
77+
# Attachments
78+
{{attachments}}
79+
80+
# Capabilities
81+
Note that {{agentName}} is capable of reading/seeing/hearing various forms of media, including images, videos, audio, plaintext and PDFs. Recent attachments have been included above under the "Attachments" section.
82+
83+
{{actions}}
84+
85+
{{messageDirections}}
86+
87+
{{recentMessages}}
88+
89+
# Instructions: Write the next message for {{agentName}}. Include an optional action if appropriate. {{actionNames}}
90+
` + messageCompletionFooter;
91+
92+
export const discordMessageHandlerTemplate =
93+
// {{goals}}
94+
`# Action Examples
95+
{{actionExamples}}
96+
(Action examples are for reference only. Do not use the information from them in your response.)
97+
98+
# Knowledge
99+
{{knowledge}}
100+
101+
# Task: Generate dialog and actions for the character {{agentName}}.
102+
About {{agentName}}:
103+
{{bio}}
104+
{{lore}}
105+
106+
Examples of {{agentName}}'s dialog and actions:
107+
{{characterMessageExamples}}
108+
109+
{{providers}}
110+
111+
{{attachments}}
112+
113+
{{actions}}
114+
115+
# Capabilities
116+
Note that {{agentName}} is capable of reading/seeing/hearing various forms of media, including images, videos, audio, plaintext and PDFs. Recent attachments have been included above under the "Attachments" section.
117+
118+
{{messageDirections}}
119+
120+
{{recentMessages}}
121+
122+
# Instructions: Write the next message for {{agentName}}. Include an action, if appropriate. {{actionNames}}
123+
` + messageCompletionFooter;

0 commit comments

Comments
 (0)