1
1
import { Tweet } from "agent-twitter-client" ;
2
- import { getEmbeddingZeroVector , composeContext , elizaLogger } from "@elizaos/core" ;
2
+ import { getEmbeddingZeroVector , composeContext , elizaLogger , generateText , ModelClass
3
+ } from "@elizaos/core" ;
3
4
import type { Content , Memory , UUID , IAgentRuntime } from "@elizaos/core" ;
4
5
5
6
import { stringToUuid } from "@elizaos/core" ;
@@ -438,7 +439,9 @@ export async function analyzeConversation(
438
439
conversationId : UUID ,
439
440
runtime : IAgentRuntime
440
441
) : Promise < void > {
442
+
441
443
const conversation = await runtime . databaseAdapter . getConversation ( conversationId ) ;
444
+ console . log ( "analyze conversation" , conversation )
442
445
if ( ! conversation ) {
443
446
elizaLogger . error ( "No conversation found for analysis" , conversationId ) ;
444
447
return ;
@@ -450,25 +453,25 @@ export async function analyzeConversation(
450
453
elizaLogger . error ( "No messages found in conversation for analysis" , conversationId ) ;
451
454
return ;
452
455
}
453
-
454
- // Get the last message to use for state building
456
+ // Get the last message to use for state building
455
457
const lastMessage = messages [ messages . length - 1 ] ;
456
-
457
458
// Build state with conversation context
458
459
const state = await runtime . composeState ( lastMessage , {
459
460
conversationId : conversationId ,
460
461
twitterUserName : runtime . getSetting ( "TWITTER_USERNAME" )
461
462
} ) ;
462
463
464
+ //console.log("state:", state)
465
+
463
466
// Format conversation for per-user analysis
464
467
const analysisTemplate = `
465
- #Recent Conversations :
468
+ #Conversation :
466
469
{{recentUserConversations}}
467
470
468
471
#Instructions:
469
472
Evaluate the messages the other users sent to you in this conversation.
470
473
Rate each users messages sent to you as a whole using these metrics: [-5] very bad, [0] neutral, [5] very good.
471
- Evaluates these messages as the character ${ runtime . character . name } with the context of the whole conversation.
474
+ Evaluates these messages as the character {{agentName}} (@{{twitterUserName}}): with the context of the whole conversation.
472
475
If you aren't sure if the message was directed to you, or you're missing context to give a good answer, give the score [0] neutral.
473
476
474
477
Return ONLY a JSON object with usernames as keys and scores as values. Example format:
@@ -480,9 +483,12 @@ export async function analyzeConversation(
480
483
state,
481
484
template : analysisTemplate
482
485
} ) ;
483
-
484
- const analysis = await runtime . generateText ( {
485
- prompt : context ,
486
+ console . log ( "context" , context )
487
+
488
+ const analysis = await generateText ( {
489
+ runtime,
490
+ context,
491
+ modelClass : ModelClass . LARGE ,
486
492
} ) ;
487
493
488
494
elizaLogger . log ( "User sentiment scores:" , analysis ) ;
@@ -493,7 +499,7 @@ export async function analyzeConversation(
493
499
// Update conversation with analysis
494
500
await runtime . databaseAdapter . updateConversation ( {
495
501
id : conversationId ,
496
- status : 'CLOSED'
502
+ // status: 'CLOSED'
497
503
} ) ;
498
504
499
505
// Update user rapport based on sentiment scores
@@ -506,7 +512,7 @@ export async function analyzeConversation(
506
512
await runtime . databaseAdapter . setUserRapport (
507
513
userId ,
508
514
runtime . agentId ,
509
- score as number
515
+ score as number // Use the sentiment score directly
510
516
) ;
511
517
elizaLogger . log ( `Updated rapport for user ${ username } :` , score ) ;
512
518
}
@@ -526,7 +532,7 @@ export async function isConversationDone(
526
532
527
533
const timeInactive = now . getTime ( ) - lastMessageTime . getTime ( ) ;
528
534
if ( timeInactive > 45 * 60 * 1000 ) {
529
- elizaLogger . log ( "Conversation inactive for 45 minutes" ) ;
535
+ elizaLogger . log ( "Conversation inactive for 45 minutes" , conversationId ) ;
530
536
531
537
return true ;
532
538
}
0 commit comments