Psiska commited on
Commit
7432811
·
1 Parent(s): 8c2c4d9

Modularised the agents

Browse files
Files changed (2) hide show
  1. __pycache__/crew.cpython-310.pyc +0 -0
  2. crew.py +31 -143
__pycache__/crew.cpython-310.pyc CHANGED
Binary files a/__pycache__/crew.cpython-310.pyc and b/__pycache__/crew.cpython-310.pyc differ
 
crew.py CHANGED
@@ -67,157 +67,44 @@ CODE_TOOLS = [
67
  AITools.code_execution_tool
68
  ]
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
 
72
  #CrewAIInstrumentor().instrument(tracer_provider=tracer_provider)
73
 
74
  @CrewBase
75
  class GAIACrew():
76
- agents: List[BaseAgent]
77
  tasks: List[Task]
78
 
79
- @agent
80
- def web_search_agent(self) -> Agent:
81
- return Agent(
82
- config=self.agents_config["web_search_agent"],
83
- allow_delegation=False,
84
- llm=AGENT_MODEL,
85
- max_iter=2,
86
- tools=WEB_TOOLS,
87
- verbose=True
88
- )
89
-
90
- @agent
91
- def web_browser_agent(self) -> Agent:
92
- return Agent(
93
- config=self.agents_config["web_browser_agent"],
94
- allow_delegation=False,
95
- llm=AGENT_MODEL,
96
- max_iter=3,
97
- tools=WEB_TOOLS,
98
- verbose=True
99
- )
100
-
101
- @agent
102
- def image_analysis_agent(self) -> Agent:
103
- return Agent(
104
- config=self.agents_config["image_analysis_agent"],
105
- allow_delegation=False,
106
- llm=AGENT_MODEL,
107
- max_iter=2,
108
- tools=MEDIA_TOOLS,
109
- verbose=True
110
- )
111
-
112
- @agent
113
- def audio_analysis_agent(self) -> Agent:
114
- return Agent(
115
- config=self.agents_config["audio_analysis_agent"],
116
- allow_delegation=False,
117
- llm=AGENT_MODEL,
118
- max_iter=2,
119
- tools=[AITools.audio_analysis_tool],
120
- verbose=True
121
- )
122
-
123
- @agent
124
- def video_analysis_agent(self) -> Agent:
125
- return Agent(
126
- config=self.agents_config["video_analysis_agent"],
127
- allow_delegation=False,
128
- llm=AGENT_MODEL,
129
- max_iter=2,
130
- tools=MEDIA_TOOLS,
131
- verbose=True
132
- )
133
-
134
- @agent
135
- def youtube_analysis_agent(self) -> Agent:
136
- return Agent(
137
- config=self.agents_config["youtube_analysis_agent"],
138
- allow_delegation=False,
139
- llm=AGENT_MODEL,
140
- max_iter=2,
141
- tools=MEDIA_TOOLS,
142
- verbose=True
143
- )
144
-
145
- @agent
146
- def document_analysis_agent(self) -> Agent:
147
- return Agent(
148
- config=self.agents_config["document_analysis_agent"],
149
- allow_delegation=False,
150
- llm=AGENT_MODEL,
151
- max_iter=2,
152
- tools=DOCUMENT_TOOLS,
153
- verbose=True
154
- )
155
 
156
- @agent
157
- def arithmetic_agent(self) -> Agent:
158
- return Agent(
159
- config=self.agents_config["document_analysis_agent"],
160
- allow_delegation=False,
161
- llm=AGENT_MODEL,
162
- max_iter=2,
163
- tools=ARITHMETIC_TOOLS,
164
- verbose=True
165
- )
166
-
167
- @agent
168
- def code_generation_agent(self) -> Agent:
169
- return Agent(
170
- config=self.agents_config["code_generation_agent"],
171
- allow_delegation=False,
172
- llm=AGENT_MODEL,
173
- max_iter=3,
174
- tools=CODE_TOOLS,
175
- verbose=True
176
- )
177
-
178
- @agent
179
- def code_execution_agent(self) -> Agent:
180
- return Agent(
181
- config=self.agents_config["code_execution_agent"],
182
- allow_delegation=False,
183
- llm=AGENT_MODEL,
184
- max_iter=3,
185
- tools=CODE_TOOLS,
186
- verbose=True
187
- )
188
-
189
- @agent
190
- def translation_agent(self) -> Agent:
191
- return Agent(
192
- config=self.agents_config["translation_agent"],
193
- allow_delegation=False,
194
- llm=AGENT_MODEL,
195
- max_iter=2,
196
- tools=DOCUMENT_TOOLS,
197
- verbose=True
198
- )
199
-
200
- @agent
201
- def summarization_agent(self) -> Agent:
202
- return Agent(
203
- config=self.agents_config["summarization_agent"],
204
- allow_delegation=False,
205
- llm=AGENT_MODEL,
206
- max_iter=2,
207
- tools=DOCUMENT_TOOLS,
208
- verbose=True
209
- )
210
-
211
- @agent
212
- def manager_agent(self) -> Agent:
213
- return Agent(
214
- config=self.agents_config["manager_agent"],
215
- allow_delegation=True,
216
- llm=MANAGER_MODEL,
217
- max_iter=5,
218
- verbose=True
219
- )
220
-
221
  @task
222
  def manager_task(self) -> Task:
223
  return Task(
@@ -228,10 +115,11 @@ class GAIACrew():
228
  def crew(self) -> Crew:
229
  return Crew(
230
  agents=self.agents,
231
- tasks=self.tasks,
232
  verbose=True
233
  )
234
 
 
235
  def run_crew(question, file_path):
236
  final_question = question
237
 
 
67
  AITools.code_execution_tool
68
  ]
69
 
70
+ #Get specific tools
71
+ def get_tools_for(agent_name: str):
72
+ if "document" in agent_name or "translation" in agent_name or "summarization" in agent_name:
73
+ return DOCUMENT_TOOLS
74
+ elif any(keyword in agent_name for keyword in ["image", "audio", "video", "youtube"]):
75
+ return MEDIA_TOOLS
76
+ elif "web_search" in agent_name or "web_browser" in agent_name:
77
+ return WEB_TOOLS
78
+ elif "code_generation" in agent_name or "code_execution" in agent_name:
79
+ return CODE_TOOLS
80
+ elif "arithmetic" in agent_name:
81
+ return ARITHMETIC_TOOLS
82
+ elif "manager" in agent_name:
83
+ return []
84
+ else:
85
+ return []
86
 
87
 
88
  #CrewAIInstrumentor().instrument(tracer_provider=tracer_provider)
89
 
90
  @CrewBase
91
  class GAIACrew():
 
92
  tasks: List[Task]
93
 
94
+ @property
95
+ def agents(self) -> List[Agent]:
96
+ return [
97
+ Agent(
98
+ config=self.agents_config[name],
99
+ allow_delegation=("manager" in name),
100
+ llm=MANAGER_MODEL if "manager" in name else AGENT_MODEL,
101
+ max_iter=5 if "manager" in name else 2,
102
+ tools=get_tools_for(name),
103
+ verbose=True
104
+ )
105
+ for name in self.agents_config.keys()
106
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  @task
109
  def manager_task(self) -> Task:
110
  return Task(
 
115
  def crew(self) -> Crew:
116
  return Crew(
117
  agents=self.agents,
118
+ tasks=[self.manager_task()],
119
  verbose=True
120
  )
121
 
122
+
123
  def run_crew(question, file_path):
124
  final_question = question
125