forked from daveshap/OpenAI_Agent_Swarm
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathagentbuilder_executives.py
More file actions
125 lines (115 loc) · 4.95 KB
/
Copy pathagentbuilder_executives.py
File metadata and controls
125 lines (115 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# agentbuilder_executives.py
import agentbuilder
from openai import OpenAI
import json
# HARDCODED key file
with open('openai.key', 'r') as file:
api_key = file.read().strip()
client = OpenAI(api_key=api_key)
class ExecutiveAgent:
def __init__(self, name, mission, goals, constraints):
self.name = name
self.mission = mission
self.goals = goals
self.constraints = constraints
self.worker_agents = []
def create_worker_agents(self):
# Define the workers' missions based on the executive's function
worker_missions = {
'Agent_ResearchFinder': [
"Search and retrieve academic papers on specific topics.",
"Continuously update the database with new research findings."
],
'Agent_Summarizer': [
"Summarize academic papers for easy comprehension.",
"Generate abstracts for quick insights into research papers."
],
'Agent_ThematicOrganizer': [
"Categorize academic papers by research topics.",
"Identify key themes for thematic mapping."
],
'Agent_CollaborationFacilitator': [
"Connect researchers with overlapping interests.",
"Create platforms for research data exchange."
]
}
# Create worker agents based on the missions specific to the executive
for mission in worker_missions.get(self.name, []):
worker_instructions = json.dumps({
"mission": mission,
"goals": self.goals,
"constraints": self.constraints
})
# Calls to the API to create a new worker agent with specific instructions
worker_agent = client.beta.assistants.create(
name=f"{self.name}_Worker",
model="gpt-4-1106-preview",
instructions=worker_instructions,
tools=[{"type": "retrieval"}]
# Add any other necessary parameters
)
self.worker_agents.append(worker_agent)
print(f"{len(self.worker_agents)} worker agents created for {self.name}")
# Creation of Executive Agents with their respective missions, goals, and constraints
executive_agents = [
ExecutiveAgent(
name='Agent_ResearchFinder',
mission='Identify and retrieve relevant academic documents for researchers.',
goals=[
'Utilize search algorithms to locate academic papers',
'Optimize search patterns for efficiency',
'Minimize redundancy in document retrieval'
],
constraints=[
'Only access open-source or authorized databases',
'Comply with copyright and data protection laws'
]
),
ExecutiveAgent(
name='Agent_Summarizer',
mission='Provide concise summaries of sourced academic documents.',
goals=[
'Extract key information without losing context',
'Generate accurate and coherent summaries',
'Adapt summarization techniques to different academic fields'
],
constraints=[
'Maintain the integrity and accuracy of the original documents',
'Avoid introduction of any bias or misinterpretation'
]
),
ExecutiveAgent(
name='Agent_ThematicOrganizer',
mission='Categorize academic documents by themes and relevance.',
goals=[
'Identify common themes within and across documents',
'Cluster documents in an intuitive and accessible manner',
'Provide thematic maps to guide researchers'
],
constraints=[
'Ensure categorization is adaptable to different research needs',
'Remain neutral and unbiased in theme identification'
]
),
ExecutiveAgent(
name='Agent_CollaborationFacilitator',
mission='Foster collaboration among researchers using the synthesized knowledge.',
goals=[
'Identify synergies among research efforts',
'Encourage data sharing and collaborative opportunities',
'Connect researchers with complementary goals'
],
constraints=[
'Respect the privacy and consent of all individuals involved',
'Promote inclusive and ethical collaboration practices'
]
)
]
# Function to initialize all executive agents and their directives
def initialize_executive_agents():
for executive in executive_agents:
agentbuilder.create_agent(executive.name, executive.mission, executive.goals, executive.constraints)
executive.create_worker_agents() # Now actually creates the workers
print(f"{executive.name} created with mission: {executive.mission}")
if __name__ == "__main__":
initialize_executive_agents()