1- from typing import Tuple , List , Optional , Any
2-
3- from nextpy .ai .agent .base_agent import BaseAgent
1+ from typing import Tuple , List , Any
42from nextpy .ai .agent .assistant_agent import AssistantAgent
53from nextpy .ai import engine
64
@@ -25,12 +23,12 @@ class MultiAgentManager:
2523 debug_mode (bool): A flag indicating whether to enable debug mode.
2624 """
2725 DEFAULT_PROMPT = '''
28- {{#system~}} You are playing a role playing game with the following participants : {{agents}}{{~/system}}
26+ {{#system~}} You are playing a role playing game with the following participants : \n {{agents}}{{~/system}}
2927
3028 {{#user~}}
3129 Read the following conversation and choose who the next speaker will be:
3230 {{messages}}
33- Simply respond with the NAME of the next speaker. Do not include any numbers. Note, User is not a participant, you cannot choose User .
31+ Simply respond with the NAME of the next speaker without any other characters such as numbers or punctuations .
3432 {{~/user}}
3533
3634 {{#assistant~}}
@@ -70,6 +68,13 @@ def __init__(self,
7068
7169 self .debug_mode = debug_mode
7270
71+ if not any ([isinstance (agent , AssistantAgent )
72+ for agent in agents ]):
73+ self .DEFAULT_PROMPT = self .DEFAULT_PROMPT [:self .DEFAULT_PROMPT .find (
74+ '{{~/system}}' )] + '\n Note, User is also a participant, you can choose User.' + self .DEFAULT_PROMPT [self .DEFAULT_PROMPT .find ('{{~/system}}' ):]
75+ else :
76+ self .DEFAULT_PROMPT = self .DEFAULT_PROMPT [:self .DEFAULT_PROMPT .find (
77+ '{{~/system}}' )] + '\n Note, User is not a participant, you cannot choose User.' + self .DEFAULT_PROMPT [self .DEFAULT_PROMPT .find ('{{~/system}}' ):]
7378 self .engine = engine (
7479 self .DEFAULT_PROMPT , llm = llm , memory = memory , async_mode = async_mode )
7580 self .solution_summarizer = engine (
@@ -90,7 +95,7 @@ def agent_string(self):
9095 """
9196 Returns a string representation of all the agent names separated by commas.
9297 """
93- return ', ' .join ([agent .name for agent in self .agents ])
98+ return '\n \n ' .join ([f'NAME: { agent .name } \n DESC: { agent . description } ' for agent in self .agents ])
9499
95100 def run_sequence (self , context ):
96101 """
@@ -103,7 +108,7 @@ def run_sequence(self, context):
103108 A list of messages exchanged between agents during the sequence.
104109 """
105110 self .messages .append (['User' , context ])
106- while self .rounds > 0 and not self ._termination_message_received ():
111+ while self .rounds != 0 and not self ._termination_message_received ():
107112 if self .debug_mode :
108113 print (
109114 f'{ "-" * 5 } Messaging next agent : { self .agents [self .current_agent ].name } { "-" * 5 } \n \n ' )
@@ -130,7 +135,7 @@ async def a_run_sequence(self, context):
130135 A list of messages exchanged between agents during the sequence.
131136 """
132137 self .messages .append (['User' , context ])
133- while self .rounds > 0 and not self ._termination_message_received ():
138+ while self .rounds != 0 and not self ._termination_message_received ():
134139 if self .debug_mode :
135140 print (
136141 f'{ "-" * 5 } Messaging next agent : { self .agents [self .current_agent ].name } { "-" * 5 } \n \n ' )
@@ -157,7 +162,7 @@ def run_auto(self, context):
157162 A list containing the messages exchanged between agents and the final solution.
158163 """
159164 self .messages .append (['User' , context ])
160- while self .rounds > 0 and not self ._termination_message_received ():
165+ while self .rounds != 0 and not self ._termination_message_received ():
161166 next_agent = self ._choose_next_agent ()
162167 if self .debug_mode :
163168 print (
0 commit comments