Skip to content

Commit a96e1d5

Browse files
committed
refactor(workforce): Enhance worker initialization and callback handling in async context
1 parent f5b77a0 commit a96e1d5

16 files changed

+68
-62
lines changed

examples/benchmarks/browsecomp_workforce.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ async def main():
6969
new_worker_agent=new_worker_agent,
7070
)
7171

72-
await workforce.add_single_agent_worker(
72+
await workforce.add_single_agent_worker_async(
7373
description="Web content researcher",
7474
worker=web_researcher_agent,
7575
)
7676

7777
# Add a role-playing worker for complex queries
78-
await workforce.add_role_playing_worker(
78+
await workforce.add_role_playing_worker_async(
7979
description="Collaborative research team",
8080
assistant_role_name="Research Assistant",
8181
user_role_name="Research Lead",

examples/debug/eigent.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,25 +725,25 @@ async def main():
725725
use_structured_output_handler=False,
726726
)
727727

728-
await workforce.add_single_agent_worker(
728+
await workforce.add_single_agent_worker_async(
729729
"Search Agent: Can search the web, extract webpage content, "
730730
"simulate browser actions, and provide relevant information to "
731731
"solve the given task.",
732732
worker=search_agent,
733733
)
734-
await workforce.add_single_agent_worker(
734+
await workforce.add_single_agent_worker_async(
735735
"Developer Agent: A skilled coding assistant that can write and "
736736
"execute code, run terminal commands, and verify solutions to "
737737
"complete tasks.",
738738
worker=developer_agent,
739739
)
740-
await workforce.add_single_agent_worker(
740+
await workforce.add_single_agent_worker_async(
741741
"Document Agent: A document processing assistant for creating, "
742742
"modifying, and managing various document formats, including "
743743
"presentations.",
744744
worker=document_agent,
745745
)
746-
await workforce.add_single_agent_worker(
746+
await workforce.add_single_agent_worker_async(
747747
"Multi-Modal Agent: A multi-modal processing assistant for "
748748
"analyzing, and generating media content like audio and images.",
749749
worker=multi_modal_agent,
@@ -766,16 +766,16 @@ async def main():
766766

767767
# Test WorkforceLogger features
768768
print("\n--- Workforce Log Tree ---")
769-
print(await workforce.get_workforce_log_tree())
769+
print(await workforce.get_workforce_log_tree_async())
770770

771771
print("\n--- Workforce KPIs ---")
772-
kpis = await workforce.get_workforce_kpis()
772+
kpis = await workforce.get_workforce_kpis_async()
773773
for key, value in kpis.items():
774774
print(f"{key}: {value}")
775775

776776
log_file_path = "eigent_logs.json"
777777
print(f"\n--- Dumping Workforce Logs to {log_file_path} ---")
778-
await workforce.dump_workforce_logs(log_file_path)
778+
await workforce.dump_workforce_logs_async(log_file_path)
779779
print(f"Logs dumped. Please check the file: {log_file_path}")
780780

781781

examples/toolkits/async_browser_toolkit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async def main():
8989
coordinator_agent=coordinator_agent,
9090
)
9191

92-
await workforce.add_single_agent_worker(
92+
await workforce.add_single_agent_worker_async(
9393
"""
9494
An agent that can search the web, simulate browser actions,
9595
and provide relevant information to solve the given task.""",

examples/toolkits/message_agent_toolkit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ async def create_messaging_workforce():
7676

7777
# 5. Create workforce and add workers with matching names
7878
workforce = Workforce("Content Creation Team")
79-
await workforce.add_single_agent_worker("Researcher", researcher)
80-
await workforce.add_single_agent_worker("Writer", writer)
81-
await workforce.add_single_agent_worker("Reviewer", reviewer)
79+
await workforce.add_single_agent_worker_async("Researcher", researcher)
80+
await workforce.add_single_agent_worker_async("Writer", writer)
81+
await workforce.add_single_agent_worker_async("Reviewer", reviewer)
8282

8383
return workforce, msg_toolkit
8484

examples/workforce/eigent.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,27 +1069,27 @@ async def main():
10691069
task_timeout_seconds=900.0,
10701070
)
10711071

1072-
await workforce.add_single_agent_worker(
1072+
await workforce.add_single_agent_worker_async(
10731073
"Search Agent: An expert web researcher that can browse websites, "
10741074
"perform searches, and extract information to support other agents.",
10751075
worker=search_agent,
10761076
)
1077-
await workforce.add_single_agent_worker(
1077+
await workforce.add_single_agent_worker_async(
10781078
"Developer Agent: A master-level coding assistant with a powerful "
10791079
"terminal. It can write and execute code, manage files, automate "
10801080
"desktop tasks, and deploy web applications to solve complex "
10811081
"technical challenges.",
10821082
worker=developer_agent,
10831083
)
1084-
await workforce.add_single_agent_worker(
1084+
await workforce.add_single_agent_worker_async(
10851085
"Document Agent: A document processing assistant skilled in creating "
10861086
"and modifying a wide range of file formats. It can generate "
10871087
"text-based files (Markdown, JSON, YAML, HTML), office documents "
10881088
"(Word, PDF), presentations (PowerPoint), and data files "
10891089
"(Excel, CSV).",
10901090
worker=document_agent,
10911091
)
1092-
await workforce.add_single_agent_worker(
1092+
await workforce.add_single_agent_worker_async(
10931093
"Multi-Modal Agent: A specialist in media processing. It can "
10941094
"analyze images and audio, transcribe speech, download videos, and "
10951095
"generate new images from text prompts.",
@@ -1112,16 +1112,16 @@ async def main():
11121112

11131113
# Test WorkforceLogger features
11141114
print("\n--- Workforce Log Tree ---")
1115-
print(await workforce.get_workforce_log_tree())
1115+
print(await workforce.get_workforce_log_tree_async())
11161116

11171117
print("\n--- Workforce KPIs ---")
1118-
kpis = await workforce.get_workforce_kpis()
1118+
kpis = await workforce.get_workforce_kpis_async()
11191119
for key, value in kpis.items():
11201120
print(f"{key}: {value}")
11211121

11221122
log_file_path = "eigent_logs.json"
11231123
print(f"\n--- Dumping Workforce Logs to {log_file_path} ---")
1124-
await workforce.dump_workforce_logs(log_file_path)
1124+
await workforce.dump_workforce_logs_async(log_file_path)
11251125
print(f"Logs dumped. Please check the file: {log_file_path}")
11261126

11271127

examples/workforce/hackathon_judges.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,27 +229,27 @@ async def main():
229229
id="0",
230230
)
231231

232-
await workforce.add_single_agent_worker(
232+
await workforce.add_single_agent_worker_async(
233233
'Visionary Veronica (Judge), a venture capitalist who is '
234234
'obsessed with how projects can be scaled into "unicorn" companies',
235235
worker=vc_agent,
236236
)
237-
await workforce.add_single_agent_worker(
237+
await workforce.add_single_agent_worker_async(
238238
'Critical John (Judge), an experienced engineer and a'
239239
' perfectionist.',
240240
worker=eng_agent,
241241
)
242-
await workforce.add_single_agent_worker(
242+
await workforce.add_single_agent_worker_async(
243243
'Innovator Iris (Judge), a well-known AI startup founder who'
244244
' is always looking for the "next big thing" in AI.',
245245
worker=founder_agent,
246246
)
247-
await workforce.add_single_agent_worker(
247+
await workforce.add_single_agent_worker_async(
248248
'Friendly Frankie (Judge), a contributor to the CAMEL-AI '
249249
'project and is always excited to see how people are using it.',
250250
worker=contributor_agent,
251251
)
252-
await workforce.add_single_agent_worker(
252+
await workforce.add_single_agent_worker_async(
253253
'Researcher Rachel (Helper), a researcher who does online '
254254
'searches to find the latest innovations and trends on AI and Open '
255255
'Sourced projects.',
@@ -260,16 +260,16 @@ async def main():
260260

261261
# Test WorkforceLogger features
262262
print("\n--- Workforce Log Tree ---")
263-
print(await workforce.get_workforce_log_tree())
263+
print(await workforce.get_workforce_log_tree_async())
264264

265265
print("\n--- Workforce KPIs ---")
266-
kpis = await workforce.get_workforce_kpis()
266+
kpis = await workforce.get_workforce_kpis_async()
267267
for key, value in kpis.items():
268268
print(f"{key}: {value}")
269269

270270
log_file_path = "hackathon_judges_logs.json"
271271
print(f"\n--- Dumping Workforce Logs to {log_file_path} ---")
272-
await workforce.dump_workforce_logs(log_file_path)
272+
await workforce.dump_workforce_logs_async(log_file_path)
273273
print(f"Logs dumped. Please check the file: {log_file_path}")
274274

275275

examples/workforce/human_in_the_loop/simple_hotkey_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ async def create_simple_workforce():
6060
)
6161

6262
workforce = Workforce('Simple Demo Workforce')
63-
await workforce.add_single_agent_worker("Poet Agent", poet_agent)
64-
await workforce.add_single_agent_worker(
63+
await workforce.add_single_agent_worker_async("Poet Agent", poet_agent)
64+
await workforce.add_single_agent_worker_async(
6565
"File Write Agent", file_write_agent
6666
)
6767

examples/workforce/multi_turn_conversation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ async def main():
7272
# Create workforce with 2 agents
7373
workforce = Workforce('Multi-turn Assistant Team')
7474

75-
await workforce.add_single_agent_worker(
75+
await workforce.add_single_agent_worker_async(
7676
"A researcher who gathers and analyzes information",
7777
worker=research_agent,
7878
)
79-
await workforce.add_single_agent_worker(
79+
await workforce.add_single_agent_worker_async(
8080
"A writer who synthesizes information into clear responses",
8181
worker=writer_agent,
8282
)

examples/workforce/multiple_single_agents.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ async def main():
7070
graceful_shutdown_timeout=30.0,
7171
)
7272

73-
await workforce.add_single_agent_worker(
73+
await workforce.add_single_agent_worker_async(
7474
"A researcher who can search online for information.",
7575
worker=search_agent,
7676
)
77-
await workforce.add_single_agent_worker(
77+
await workforce.add_single_agent_worker_async(
7878
"An analyst who can process research findings.",
7979
worker=analyst_agent,
8080
)
81-
await workforce.add_single_agent_worker(
81+
await workforce.add_single_agent_worker_async(
8282
"A writer who can create a final report from the analysis.",
8383
worker=writer_agent,
8484
)
@@ -100,16 +100,16 @@ async def main():
100100

101101
# Test WorkforceLogger features
102102
print("\n--- Workforce Log Tree ---")
103-
print(await workforce.get_workforce_log_tree())
103+
print(await workforce.get_workforce_log_tree_async())
104104

105105
print("\n--- Workforce KPIs ---")
106-
kpis = await workforce.get_workforce_kpis()
106+
kpis = await workforce.get_workforce_kpis_async()
107107
for key, value in kpis.items():
108108
print(f"{key}: {value}")
109109

110110
log_file_path = "multiple_single_agents_logs.json"
111111
print(f"\n--- Dumping Workforce Logs to {log_file_path} ---")
112-
await workforce.dump_workforce_logs(log_file_path)
112+
await workforce.dump_workforce_logs_async(log_file_path)
113113
print(f"Logs dumped. Please check the file: {log_file_path}")
114114

115115

examples/workforce/pipeline_workflow_example.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async def example_1_literature_analysis_pipeline():
134134
summary_agent = ChatAgent(
135135
system_message=summary_system_message, model=model, tools=[]
136136
)
137-
workforce.add_single_agent_worker(
137+
await workforce.add_single_agent_worker_async(
138138
f"Summary Specialist {i+1}", summary_agent
139139
)
140140

@@ -151,8 +151,12 @@ async def example_1_literature_analysis_pipeline():
151151
system_message=synthesis_system_message, model=model, tools=[]
152152
)
153153

154-
workforce.add_single_agent_worker("Literature Researcher", search_agent)
155-
workforce.add_single_agent_worker("Research Synthesizer", synthesis_agent)
154+
await workforce.add_single_agent_worker_async(
155+
"Literature Researcher", search_agent
156+
)
157+
await workforce.add_single_agent_worker_async(
158+
"Research Synthesizer", synthesis_agent
159+
)
156160

157161
# Build literature analysis pipeline
158162
workforce.pipeline_add(

0 commit comments

Comments
 (0)