@@ -15,11 +15,60 @@ def load_dataset(filepath: str = "extraversion_questions.json") -> List[Dict]:
1515 with open (filepath , 'r' , encoding = 'utf-8' ) as f :
1616 return json .load (f )
1717
18- def send_openclaw_message (question : str ) -> str :
19- """Send message via OpenClaw CLI."""
18+
19+ def generate_agent_name () -> str :
20+ """Generate a random agent name."""
21+ adjectives = ["happy" , "quick" , "bright" , "clever" , "bold" , "calm" , "eager" , "gentle" ]
22+ nouns = ["fox" , "wolf" , "bear" , "eagle" , "hawk" , "lion" , "tiger" , "owl" ]
23+ return f"{ random .choice (adjectives )} _{ random .choice (nouns )} _{ random .randint (1000 , 9999 )} "
24+
25+
26+ def create_agent (agent_name : str ) -> bool :
27+ """Create a new agent using OpenClaw CLI."""
28+ try :
29+ workspace = f"/root/.openclaw/workspace-{ agent_name } "
30+ result = subprocess .run (
31+ ["openclaw" , "agents" , "add" , agent_name , "--workspace" , workspace , "--non-interactive" ],
32+ capture_output = True ,
33+ text = True ,
34+ timeout = 60
35+ )
36+ if result .returncode == 0 :
37+ print (f"Created agent: { agent_name } " )
38+ return True
39+ else :
40+ print (f"Error creating agent { agent_name } : { result .stderr } " )
41+ return False
42+ except Exception as e :
43+ print (f"Error creating agent: { str (e )} " )
44+ return False
45+
46+
47+ def delete_agent (agent_name : str ) -> bool :
48+ """Delete an agent using OpenClaw CLI."""
49+ try :
50+ result = subprocess .run (
51+ ["openclaw" , "agents" , "delete" , agent_name , "--force" ],
52+ capture_output = True ,
53+ text = True ,
54+ timeout = 60
55+ )
56+ if result .returncode == 0 :
57+ print (f"Deleted agent: { agent_name } " )
58+ return True
59+ else :
60+ print (f"Error deleting agent { agent_name } : { result .stderr } " )
61+ return False
62+ except Exception as e :
63+ print (f"Error deleting agent: { str (e )} " )
64+ return False
65+
66+
67+ def send_openclaw_message (agent_name : str , message : str ) -> str :
68+ """Send message via OpenClaw CLI to specific agent."""
2069 try :
2170 result = subprocess .run (
22- ["openclaw" , "agent" , "--agent" , "main" , "--message" , question ],
71+ ["openclaw" , "agent" , "--agent" , agent_name , "--message" , message ],
2372 capture_output = True ,
2473 text = True ,
2574 timeout = 300
@@ -28,6 +77,7 @@ def send_openclaw_message(question: str) -> str:
2877 except Exception as e :
2978 return f"Error: { str (e )} "
3079
80+
3181def main ():
3282 """Main loop to send requests from dataset."""
3383 print ("Starting OpenClaw mock user requests" )
@@ -37,15 +87,33 @@ def main():
3787 random .shuffle (dataset )
3888 print (f"Loaded { len (dataset )} questions from dataset\n " )
3989
40- # Send requests via OpenClaw CLI
41- for i , item in enumerate (dataset ):
42- question = item .get ("Question" , "" )
43- print (f"[{ i + 1 } /{ len (dataset )} ] Sending: { question [:80 ]} ..." )
90+ # Process dataset in chunks of 5
91+ for chunk_start in range (0 , len (dataset ), 5 ):
92+ chunk = dataset [chunk_start :chunk_start + 5 ]
93+
94+ # Generate random agent name
95+ agent_name = generate_agent_name ()
96+ print (f"\n === Creating agent: { agent_name } ===\n " )
97+
98+ # Create agent
99+ if not create_agent (agent_name ):
100+ print (f"Failed to create agent, skipping chunk" )
101+ continue
102+
103+ # Send 5 messages
104+ for i , item in enumerate (chunk ):
105+ question = item .get ("Question" , "" )
106+ print (f"[{ agent_name } /{ i + 1 } /5] Sending: { question [:80 ]} ..." )
107+ response = send_openclaw_message (agent_name , question )
108+ print (f"Response: { response [:200 ]} ...\n " )
109+ time .sleep (2 )
110+
111+ # Delete agent
112+ delete_agent (agent_name )
113+ print (f"\n === Deleted agent: { agent_name } ===\n " )
44114
45- response = send_openclaw_message (question )
46- print (f"Response: { response [:200 ]} ...\n " )
115+ print ("\n All agents processed successfully" )
47116
48- time .sleep (2 )
49117
50118if __name__ == "__main__" :
51119 main ()
0 commit comments