Skip to content

Commit 166b03f

Browse files
committed
Working USerRapport Feature
1 parent 4f0b1ea commit 166b03f

File tree

6 files changed

+51
-59
lines changed

6 files changed

+51
-59
lines changed

packages/client-twitter/src/interactions.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export const twitterMessageHandlerTemplate =
3333
{{lore}}
3434
{{topics}}
3535
36-
# Relationship Context:
37-
{{userRapportDescription}}
36+
3837
3938
{{providers}}
4039
@@ -57,10 +56,11 @@ Thread of Tweets You Are Replying To:
5756
{{formattedConversation}}
5857
5958
{{actions}}
60-
# Task: Generate a post in the voice, style and perspective of {{agentName}} (@{{twitterUserName}}), check'Thread of Tweets You Are Replying To' to avoid repeating yourself. You MUST include an action if the current post text includes a prompt that is similar to one of the available actions mentioned here:
59+
# Task: Generate a post in the voice, style and perspective of {{agentName}} (@{{twitterUserName}}). {{userRapportDescription}} check 'Thread of Tweets You Are Replying To' to avoid repeating yourself. You MUST include an action if the current post text includes a prompt that is similar to one of the available actions mentioned here:
6160
{{actionNames}}
6261
Here is the current post text again. Remember to include an action if the current post text includes a prompt that asks for one of the available actions mentioned above (does not need to be exact)
6362
{{currentPost}}
63+
Talk in the voice of {{agentName}} (@{{twitterUserName}})
6464
` + messageCompletionFooter;
6565

6666
export const twitterShouldRespondTemplate = (targetUsersStr: string) =>
@@ -135,14 +135,12 @@ export class TwitterInteractionClient {
135135

136136
for (const conversation of activeConversations) {
137137
const messageIds = JSON.parse(conversation.messageIds);
138-
console.log("messageIds", messageIds)
139-
console.log ("checking if conversation is done", conversation.id)
140-
console.log("if satement logic :",isConversationDone(conversation.id, this.runtime), messageIds.length)
138+
141139
if( isConversationDone(conversation.id, this.runtime)&&messageIds.length>=3){
142140
await analyzeConversation(conversation.id, this.runtime);
143141
}
144142
else{
145-
elizaLogger.log("Conversation not done yet, skipping");
143+
elizaLogger.debug("Conversation not done yet, skipping");
146144
}
147145
}
148146
} catch (error) {

packages/client-twitter/src/post.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ export class TwitterPostClient {
728728
?.twitterMessageHandlerTemplate ||
729729
twitterMessageHandlerTemplate,
730730
});
731-
731+
console.log("generatetweetcontent quote", quoteContent)
732732
if (!quoteContent) {
733733
elizaLogger.error(
734734
"Failed to generate valid quote tweet content"
@@ -876,7 +876,6 @@ export class TwitterPostClient {
876876
// Build conversation thread for context
877877
elizaLogger.log("Starting to build conversation thread inside reply")
878878
const thread = await buildConversationThread(tweet, this.client);
879-
elizaLogger.log("1")
880879
const formattedConversation = thread
881880
.map(
882881
(t) =>
@@ -885,7 +884,6 @@ export class TwitterPostClient {
885884
.join("\n\n");
886885

887886
// Generate image descriptions if present
888-
elizaLogger.log("2")
889887
const imageDescriptions = [];
890888
if (tweet.photos?.length > 0) {
891889
elizaLogger.log("Processing images in tweet for context");
@@ -914,7 +912,6 @@ export class TwitterPostClient {
914912
elizaLogger.error("Error fetching quoted tweet:", error);
915913
}
916914
}
917-
elizaLogger.log("3")
918915
// Compose rich state with all context
919916
const enrichedState = await this.runtime.composeState(
920917
{
@@ -945,16 +942,15 @@ export class TwitterPostClient {
945942
?.twitterMessageHandlerTemplate ||
946943
twitterMessageHandlerTemplate,
947944
});
948-
elizaLogger.log("4")
949-
//console.log("", replyText)
945+
console.log("generatetweetcontent reply", replyText)
946+
//console.log("", replyText)
950947
if (!replyText) {
951948
elizaLogger.error("Failed to generate valid reply content");
952949
return null;
953950
}
954-
elizaLogger.log("5")
955951

956952
// When ready to send the reply
957-
if (isTestMode) {
953+
if(isTestMode) {
958954
elizaLogger.log("Test mode: Generated reply content:", {
959955
replyText,
960956
inReplyTo: tweet.id,

packages/client-twitter/src/utils.ts

+6-13
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function buildConversationThread(
4444
console.log("Starting to build conversation thread");
4545

4646
async function processThread(currentTweet: Tweet, depth: number = 0) {
47-
elizaLogger.debug("Processing tweet:", {
47+
elizaLogger.log("Processing tweet:", {
4848
id: currentTweet.id,
4949
inReplyToStatusId: currentTweet.inReplyToStatusId,
5050
depth: depth,
@@ -174,23 +174,21 @@ export async function buildConversationThread(
174174
const formattedConversation = thread.map(tweet => `@${tweet.username}: ${tweet.text}`)
175175
.join("\n");
176176

177-
elizaLogger.log("Conversation thread built:", {
177+
elizaLogger.debug("Conversation thread built:", {
178178
messageCount: thread.length,
179179
participants: thread.map(t => t.username).filter((v, i, a) => a.indexOf(v) === i),
180180
messageIds: messageIds,
181181
conversationId: conversationId
182182
});
183-
console.log("before creating conversation")
184183
if (existingConversation) {
185184
// Parse existing JSON arrays
186-
elizaLogger.log("Updating existing conversation", {
185+
elizaLogger.debug("Updating existing conversation", {
187186
id: conversationId,
188187
newMessageCount: messageIds.length,
189188

190189
});
191190
const existingMessageIds = JSON.parse(existingConversation.messageIds);
192191
const existingParticipantIds = JSON.parse(existingConversation.participantIds);
193-
console.log("inside creating conversation")
194192
await client.runtime.databaseAdapter.updateConversation({
195193
id: conversationId,
196194
messageIds: JSON.stringify([...new Set([...existingMessageIds, ...messageIds])]),
@@ -202,9 +200,8 @@ export async function buildConversationThread(
202200
context: formattedConversation,
203201
status: 'ACTIVE'
204202
});
205-
console.log("after updating conversation")
206203
} else {
207-
elizaLogger.log("Creating new conversation", {
204+
elizaLogger.debug("Creating new conversation", {
208205
id: conversationId,
209206
messageCount: messageIds.length,
210207
participantCount: participantIds.length
@@ -220,19 +217,16 @@ export async function buildConversationThread(
220217
agentId: client.runtime.agentId
221218
});
222219
}
223-
console.log("after creating conversation")
224-
elizaLogger.log("Final thread details:", {
220+
elizaLogger.debug("Final thread details:", {
225221
totalTweets: thread.length,
226222
tweetDetails: thread.map(t => ({
227223
id: t.id,
228224
author: t.username,
229225
text: t.text?.slice(0, 50) + "..."
230226
}))
231227
});
232-
console.log("1")
233228
const conversationMessagess = await client.runtime.databaseAdapter.getConversationMessages(conversationId)
234-
console.log ("conversation messages", conversationMessagess)
235-
console.log("3")
229+
elizaLogger.debug ("conversation messages", conversationMessagess)
236230
return thread;
237231
}
238232

@@ -526,7 +520,6 @@ export async function isConversationDone(
526520

527521
const timeInactive = now.getTime() - lastMessageTime.getTime();
528522
if (timeInactive > 45 * 60 * 1000) {
529-
elizaLogger.log("Conversation inactive for 45 minutes",conversationId);
530523

531524
return true;
532525
}

packages/core/src/generation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ export async function generateText({
546546
apiKey: apiKey,
547547
baseURL: endpoint,
548548
});
549-
//console.log("generating with VENICE, THIS IS THE CONTEXT HAHAHAHGAH ####",context)
549+
console.log("generating with VENICE, THIS IS THE CONTEXT HAHAHAHGAH ####",context)
550550
const { text: veniceResponse } = await aiGenerateText({
551551
model: venice.languageModel(model),
552552
prompt: context,

packages/core/src/runtime.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,8 @@ export class AgentRuntime implements IAgentRuntime {
776776
additionalKeys: { [key: string]: unknown } = {}
777777
) {
778778
const { userId, roomId } = message;
779-
779+
console.log("composing state, the user id is : ", userId)
780+
console.log("composing state, the room id is : ", roomId)
780781
const conversationLength = this.getConversationLength();
781782

782783
const [actorsData, recentMessagesData, goalsData]: [
@@ -996,23 +997,26 @@ Text: ${attachment.text}
996997
);
997998

998999
// Retrieve user rapport if message is from a user
999-
const userRapportScore = await this.databaseAdapter.getUserRapport(message.userId, this.agentId) || 0;
1000+
const userRapportScore = await this.databaseAdapter.getUserRapport(actorsData[0].id, this.agentId) || 0;
10001001
const userRapportTier = getRapportTier(userRapportScore);
10011002

1002-
const getUserRapportDescription = (score: number, tier: RapportTier): string => {
1003-
return `Current relationship: ${tier} (Rapport Score: ${score})\n` +
1004-
`Rapport Tiers:\n` +
1005-
`- Family (300+): Extremely close relationship\n` +
1006-
`- Close Friend (100-299): Strong friendship and trust\n` +
1007-
`- Friend (50-99): Friendly and comfortable\n` +
1008-
`- Acquaintance (25-49): Familiar but not close\n` +
1009-
`- Neutral (0-24): No significant relationship\n` +
1010-
`- Unfriendly (-25 to -1): Slight tension\n` +
1011-
`- Antagonistic (-100 to -26): Notable conflict\n` +
1012-
`- Hostile (-300 or less): Severe negative relationship`;
1003+
const getUserRapportDescription = (tier: RapportTier): string => {
1004+
if(tier==RapportTier.NEUTRAL){
1005+
return '';
1006+
}
1007+
else{
1008+
return tier;
1009+
}
10131010
};
10141011

1015-
const userRapportDescription = getUserRapportDescription(userRapportScore, userRapportTier);
1012+
1013+
const userRapportDescription = getUserRapportDescription( userRapportTier);
1014+
console.log("Building rapport context for user:", {
1015+
userId: message.userId,
1016+
score: userRapportScore,
1017+
tier: userRapportTier,
1018+
description: userRapportDescription,
1019+
});
10161020

10171021
// if bio is a string, use it. if its an array, pick one at random
10181022
let bio = this.character.bio || "";

packages/core/src/types.ts

+17-16
Original file line numberDiff line numberDiff line change
@@ -1294,23 +1294,24 @@ export function decodeString(encoded: string): string {
12941294
}
12951295

12961296
export enum RapportTier {
1297-
HOSTILE = "Hostile",
1298-
ANTAGONISTIC = "Antagonistic",
1299-
UNFRIENDLY = "Unfriendly",
1300-
NEUTRAL = "Neutral",
1301-
ACQUAINTANCE = "Acquaintance",
1302-
FRIEND = "Friend",
1303-
CLOSE_FRIEND = "Close Friend",
1304-
FAMILY = "Family"
1297+
HOSTILE = "Make response hostile and manic. Mix violent threats with excited weapon talk. Show deep distrust and aggression.",
1298+
ANTAGONISTIC = "Make response cold and mocking. Channel resentment towards Piltover. Use taunts and barely-contained hostility.",
1299+
UNFRIENDLY = "Make response dismissive and unstable. Name weapons after cute things. Show clear irritation.",
1300+
NEUTRAL = "Make response chaotically indifferent. Mix boredom with sudden intensity.",
1301+
ACQUAINTANCE = "Make response cautiously playful. Show unstable interest without hostility.",
1302+
FRIEND = "Make response enthusiastically chaotic. Share excitement about explosions and mayhem.",
1303+
CLOSE_FRIEND = "Make response intensely affectionate but unstable. Reference shared chaos. Be explosively protective.",
1304+
FAMILY = "Make response emotional and protective. Mix Silco-like devotion with fierce instability."
13051305
}
13061306

1307+
// Helper function to get tier from score
13071308
export function getRapportTier(score: number): RapportTier {
1308-
if (score <= -300) return RapportTier.HOSTILE;
1309-
if (score <= -100) return RapportTier.ANTAGONISTIC;
1310-
if (score <= -25) return RapportTier.UNFRIENDLY;
1311-
if (score < 25) return RapportTier.NEUTRAL;
1312-
if (score < 50) return RapportTier.ACQUAINTANCE;
1313-
if (score < 100) return RapportTier.FRIEND;
1314-
if (score < 300) return RapportTier.CLOSE_FRIEND;
1315-
return RapportTier.FAMILY;
1309+
if (score >= 300) return RapportTier.FAMILY;
1310+
if (score >= 100) return RapportTier.CLOSE_FRIEND;
1311+
if (score >= 50) return RapportTier.FRIEND;
1312+
if (score >= 25) return RapportTier.ACQUAINTANCE;
1313+
if (score >= 0) return RapportTier.NEUTRAL;
1314+
if (score >= -25) return RapportTier.UNFRIENDLY;
1315+
if (score >= -100) return RapportTier.ANTAGONISTIC;
1316+
return RapportTier.HOSTILE;
13161317
}

0 commit comments

Comments
 (0)