Skip to content

Commit 1fe0d76

Browse files
committed
fixed issue with actordata error in state
1 parent bceed3e commit 1fe0d76

File tree

1 file changed

+56
-20
lines changed

1 file changed

+56
-20
lines changed

packages/core/src/runtime.ts

+56-20
Original file line numberDiff line numberDiff line change
@@ -779,13 +779,37 @@ export class AgentRuntime implements IAgentRuntime {
779779
console.log("composing state, the user id is : ", userId)
780780
console.log("composing state, the room id is : ", roomId)
781781
const conversationLength = this.getConversationLength();
782-
782+
console.log("1")
783783
const [actorsData, recentMessagesData, goalsData]: [
784784
Actor[],
785785
Memory[],
786786
Goal[],
787787
] = await Promise.all([
788-
getActorDetails({ runtime: this, roomId }),
788+
getActorDetails({ runtime: this, roomId }).then(actors => {
789+
console.log("Actor details retrieved:", {
790+
roomId,
791+
actorCount: actors.length,
792+
actors: actors.map(a => ({id: a.id, username: a.username}))
793+
});
794+
if (!actors || actors.length === 0) {
795+
// This should never happen as we should at least have the message author
796+
console.error("No actors found for room:", roomId);
797+
console.error("Message details:", {
798+
messageId: message.id,
799+
userId: message.userId,
800+
roomId: message.roomId
801+
});
802+
803+
// Emergency fallback: Create an actor from the message
804+
return [{
805+
id: message.userId,
806+
name: "Unknown User",
807+
username: "unknown",
808+
details: { tagline: "", summary: "", quote: "" }
809+
}];
810+
}
811+
return actors;
812+
}),
789813
this.messageManager.getMemories({
790814
roomId,
791815
count: conversationLength,
@@ -798,9 +822,9 @@ export class AgentRuntime implements IAgentRuntime {
798822
roomId,
799823
}),
800824
]);
801-
825+
console.log("2")
802826
const goals = formatGoalsAsString({ goals: goalsData });
803-
827+
console.log("3")
804828
const actors = formatActors({ actors: actorsData ?? [] });
805829

806830
const recentMessages = formatMessages({
@@ -945,12 +969,13 @@ Text: ${attachment.text}
945969
: [];
946970

947971
// Get formatted conversation if conversationId is provided
972+
console.log("4")
948973
let recentUserConversations = "";
949974
if (additionalKeys.conversationId) {
950975
const currentConversationId = additionalKeys.conversationId as UUID;
951976
recentUserConversations = await this.databaseAdapter.getFormattedConversation(currentConversationId);
952977
}
953-
978+
console.log("5")
954979
const getRecentMessageInteractions = async (
955980
recentInteractionsData: Memory[]
956981
): Promise<string> => {
@@ -971,13 +996,13 @@ Text: ${attachment.text}
971996
return `${sender}: ${message.content.text}`;
972997
})
973998
);
974-
999+
console.log("6")
9751000
return formattedInteractions.join("\n");
9761001
};
9771002

9781003
const formattedMessageInteractions =
9791004
await getRecentMessageInteractions(recentInteractions);
980-
1005+
console.log("7")
9811006
const getRecentPostInteractions = async (
9821007
recentInteractionsData: Memory[],
9831008
actors: Actor[]
@@ -995,29 +1020,40 @@ Text: ${attachment.text}
9951020
recentInteractions,
9961021
actorsData
9971022
);
998-
1023+
console.log("8")
9991024
// Retrieve user rapport if message is from a user
1000-
const userRapportScore = await this.databaseAdapter.getUserRapport(actorsData[0].id, this.agentId) || 0;
1001-
const userRapportTier = getRapportTier(userRapportScore);
1025+
console.log("actorsData:", actorsData);
1026+
let userRapportScore = 0;
1027+
let userRapportTier = getRapportTier(0); // Default to neutral
1028+
1029+
if (actorsData && actorsData.length > 0 && actorsData[0]?.id) {
1030+
userRapportScore = await this.databaseAdapter.getUserRapport(actorsData[0].id, this.agentId) || 0;
1031+
userRapportTier = getRapportTier(userRapportScore);
1032+
console.log("Found user rapport for:", actorsData[0].id, "Score:", userRapportScore);
1033+
} else {
1034+
console.log("No valid actor data found for rapport calculation");
1035+
}
1036+
1037+
console.log("userRapportScore:", userRapportScore);
1038+
console.log("UserRapportTier:", userRapportTier);
10021039

10031040
const getUserRapportDescription = (tier: RapportTier): string => {
1004-
if(tier==RapportTier.NEUTRAL){
1041+
if(tier === RapportTier.NEUTRAL){
10051042
return '';
10061043
}
10071044
else{
10081045
return tier;
10091046
}
10101047
};
10111048

1012-
1013-
const userRapportDescription = getUserRapportDescription( userRapportTier);
1049+
const userRapportDescription = getUserRapportDescription(userRapportTier);
10141050
console.log("Building rapport context for user:", {
10151051
userId: message.userId,
10161052
score: userRapportScore,
10171053
tier: userRapportTier,
10181054
description: userRapportDescription,
10191055
});
1020-
1056+
console.log("11")
10211057
// if bio is a string, use it. if its an array, pick one at random
10221058
let bio = this.character.bio || "";
10231059
if (Array.isArray(bio)) {
@@ -1036,9 +1072,9 @@ Text: ${attachment.text}
10361072
.join(" ");
10371073
}
10381074
const knowledegeData = await knowledge.get(this, message);
1039-
1075+
console.log("12")
10401076
const formattedKnowledge = formatKnowledge(knowledegeData);
1041-
1077+
console.log("13")
10421078
const initialState = {
10431079
agentId: this.agentId,
10441080
agentName,
@@ -1187,15 +1223,15 @@ Text: ${attachment.text}
11871223
...additionalKeys,
11881224

11891225
} as State;
1190-
1226+
console.log("14")
11911227
const actionPromises = this.actions.map(async (action: Action) => {
11921228
const result = await action.validate(this, message, initialState);
11931229
if (result) {
11941230
return action;
11951231
}
11961232
return null;
11971233
});
1198-
1234+
console.log("15")
11991235
const evaluatorPromises = this.evaluators.map(async (evaluator) => {
12001236
const result = await evaluator.validate(
12011237
this,
@@ -1207,7 +1243,7 @@ Text: ${attachment.text}
12071243
}
12081244
return null;
12091245
});
1210-
1246+
console.log("16")
12111247
const [resolvedEvaluators, resolvedActions, providers] =
12121248
await Promise.all([
12131249
Promise.all(evaluatorPromises),
@@ -1255,7 +1291,7 @@ Text: ${attachment.text}
12551291
providers
12561292
),
12571293
};
1258-
1294+
console.log("17")
12591295
return { ...initialState, ...actionState } as State;
12601296
}
12611297

0 commit comments

Comments
 (0)