@ -20,9 +20,7 @@ def _hash(input: str):
return hex_dig
return hex_dig
def msg_hash (
def msg_hash ( agent : Agent , content : str , turn : int , msg_type : str = " text " ) :
agent : Agent , content : str , turn : int , msg_type : str = " text "
) :
"""
"""
Generate a hash value for a message .
Generate a hash value for a message .
@ -37,8 +35,7 @@ def msg_hash(
"""
"""
time = time_ns ( )
time = time_ns ( )
return _hash (
return _hash (
f " agent: { agent . agent_name } \n content: { content } \n timestamp: "
f " agent: { agent . agent_name } \n content: { content } \n timestamp: " f " { str ( time ) } \n turn: { turn } \n msg_type: { msg_type } "
f " { str ( time ) } \n turn: { turn } \n msg_type: { msg_type } "
)
)
@ -67,11 +64,17 @@ class MessagePool:
>> > message_pool . add ( agent = agent2 , content = " Hello, agent1! " , turn = 1 )
>> > message_pool . add ( agent = agent2 , content = " Hello, agent1! " , turn = 1 )
>> > message_pool . add ( agent = agent3 , content = " Hello, agent1! " , turn = 1 )
>> > message_pool . add ( agent = agent3 , content = " Hello, agent1! " , turn = 1 )
>> > message_pool . get_all_messages ( )
>> > message_pool . get_all_messages ( )
[ { ' agent ' : Agent ( agent_name = ' agent1 ' ) , ' content ' : ' Hello, agent2! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } , { ' agent ' : Agent ( agent_name = ' agent2 ' ) , ' content ' : ' Hello, agent1! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } , { ' agent ' : Agent ( agent_name = ' agent3 ' ) , ' content ' : ' Hello, agent1! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } ]
[ { ' agent ' : Agent ( agent_name = ' agent1 ' ) , ' content ' : ' Hello, agent2! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } ,
{ ' agent ' : Agent ( agent_name = ' agent2 ' ) , ' content ' : ' Hello, agent1! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } ,
{ ' agent ' : Agent ( agent_name = ' agent3 ' ) , ' content ' : ' Hello, agent1! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } ]
>> > message_pool . get_visible_messages ( agent = agent1 , turn = 1 )
>> > message_pool . get_visible_messages ( agent = agent1 , turn = 1 )
[ { ' agent ' : Agent ( agent_name = ' agent1 ' ) , ' content ' : ' Hello, agent2! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } , { ' agent ' : Agent ( agent_name = ' agent2 ' ) , ' content ' : ' Hello, agent1! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } , { ' agent ' : Agent ( agent_name = ' agent3 ' ) , ' content ' : ' Hello, agent1! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } ]
[ { ' agent ' : Agent ( agent_name = ' agent1 ' ) , ' content ' : ' Hello, agent2! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } ,
{ ' agent ' : Agent ( agent_name = ' agent2 ' ) , ' content ' : ' Hello, agent1! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } ,
{ ' agent ' : Agent ( agent_name = ' agent3 ' ) , ' content ' : ' Hello, agent1! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } ]
>> > message_pool . get_visible_messages ( agent = agent2 , turn = 1 )
>> > message_pool . get_visible_messages ( agent = agent2 , turn = 1 )
[ { ' agent ' : Agent ( agent_name = ' agent1 ' ) , ' content ' : ' Hello, agent2! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } , { ' agent ' : Agent ( agent_name = ' agent2 ' ) , ' content ' : ' Hello, agent1! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } , { ' agent ' : Agent ( agent_name = ' agent3 ' ) , ' content ' : ' Hello, agent1! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } ]
[ { ' agent ' : Agent ( agent_name = ' agent1 ' ) , ' content ' : ' Hello, agent2! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } ,
{ ' agent ' : Agent ( agent_name = ' agent2 ' ) , ' content ' : ' Hello, agent1! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } ,
{ ' agent ' : Agent ( agent_name = ' agent3 ' ) , ' content ' : ' Hello, agent1! ' , ' turn ' : 1 , ' visible_to ' : ' all ' , ' logged ' : True } ]
"""
"""
def __init__ (
def __init__ (
@ -98,9 +101,7 @@ class MessagePool:
logger . info ( " MessagePool initialized " )
logger . info ( " MessagePool initialized " )
logger . info ( f " Number of agents: { len ( agents ) } " )
logger . info ( f " Number of agents: { len ( agents ) } " )
logger . info (
logger . info ( f " Agents: { [ agent . agent_name for agent in agents ] } " )
f " Agents: { [ agent . agent_name for agent in agents ] } "
)
logger . info ( f " moderator: { moderator . agent_name } is available " )
logger . info ( f " moderator: { moderator . agent_name } is available " )
logger . info ( f " Number of turns: { turns } " )
logger . info ( f " Number of turns: { turns } " )
@ -187,18 +188,11 @@ class MessagePool:
List [ Dict ] : The list of visible messages .
List [ Dict ] : The list of visible messages .
"""
"""
# Get the messages before the current turn
# Get the messages before the current turn
prev_messages = [
prev_messages = [ message for message in self . messages if message [ " turn " ] < turn ]
message
for message in self . messages
if message [ " turn " ] < turn
]
visible_messages = [ ]
visible_messages = [ ]
for message in prev_messages :
for message in prev_messages :
if (
if message [ " visible_to " ] == " all " or agent . agent_name in message [ " visible_to " ] :
message [ " visible_to " ] == " all "
or agent . agent_name in message [ " visible_to " ]
) :
visible_messages . append ( message )
visible_messages . append ( message )
return visible_messages
return visible_messages