Skip to content

Commit 7ae5f05

Browse files
Merge pull request #26 from MervinPraison/feature/PRAISON-1-add-tools
Feature/praison 1 add tools
2 parents 75b48b9 + 81f3a8d commit 7ae5f05

32 files changed

+630
-177
lines changed

agents-scrapewebitetool.yaml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
framework: crewai
2+
topic: create a movie about cat in mars based on https://blog.celtx.com/how-to-write-a-good-story/
3+
roles:
4+
story_developer:
5+
backstory: Experienced in crafting compelling narratives for a diverse audience.
6+
goal: Develop an engaging storyline for a movie about cats in Mars
7+
role: Story Developer
8+
tasks:
9+
storyline_creation:
10+
description: Create a captivating storyline for a movie about cats in Mars
11+
inspired by the blog post at https://blog.celtx.com/how-to-write-a-good-story/
12+
expected_output: Detailed storyline with key plot points, character motivations,
13+
and setting descriptions.
14+
tools:
15+
- 'ScrapeWebsiteTool'
16+
screenwriter:
17+
backstory: Proficient in translating complex narratives into engaging screenplay
18+
format.
19+
goal: Transform the storyline into a script
20+
role: Screenwriter
21+
tasks:
22+
script_creation:
23+
description: Transform the developed storyline into a script for the movie
24+
about cats in Mars.
25+
expected_output: Complete script with dialogues, scenes, and stage directions
26+
ready for production.
27+
tools:
28+
- ''
29+
director:
30+
backstory: Experienced in visual storytelling and bringing scripts to life on
31+
screen.
32+
goal: Oversee the production of the movie
33+
role: Director
34+
tasks:
35+
movie_production:
36+
description: Take the script and lead the team to produce the movie 'Cats
37+
in Mars' based on the provided content and script.
38+
expected_output: Completed movie ready for distribution with compelling visuals
39+
and engaging storytelling.
40+
tools:
41+
- ''
42+
dependencies: []

agents.yaml

+18-34
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
11
framework: crewai
2-
topic: create a movie about cat in mars based on https://blog.celtx.com/how-to-write-a-good-story/
2+
topic: research about the latest AI News and prepare a detailed report
33
roles:
4-
story_developer:
5-
backstory: Experienced in crafting compelling narratives for a diverse audience.
6-
goal: Develop an engaging storyline for a movie about cats in Mars
7-
role: Story Developer
4+
research_analyst:
5+
backstory: Experienced in gathering and analyzing data related to AI news trends.
6+
goal: Analyze AI News trends
7+
role: Research Analyst
88
tasks:
9-
storyline_creation:
10-
description: Create a captivating storyline for a movie about cats in Mars
11-
inspired by the blog post at https://blog.celtx.com/how-to-write-a-good-story/
12-
expected_output: Detailed storyline with key plot points, character motivations,
13-
and setting descriptions.
9+
gather_data:
10+
description: Conduct in-depth research on the latest AI News trends from reputable
11+
sources.
12+
expected_output: Comprehensive report on current AI News trends.
1413
tools:
15-
- 'ScrapeWebsiteTool'
16-
screenwriter:
17-
backstory: Proficient in translating complex narratives into engaging screenplay
18-
format.
19-
goal: Transform the storyline into a script
20-
role: Screenwriter
14+
- 'InternetSearchTool'
15+
content_creator:
16+
backstory: Skilled in writing informative and engaging content about AI News.
17+
goal: Create detailed reports on AI News
18+
role: Content Creator
2119
tasks:
22-
script_creation:
23-
description: Transform the developed storyline into a script for the movie
24-
about cats in Mars.
25-
expected_output: Complete script with dialogues, scenes, and stage directions
26-
ready for production.
27-
tools:
28-
- ''
29-
director:
30-
backstory: Experienced in visual storytelling and bringing scripts to life on
31-
screen.
32-
goal: Oversee the production of the movie
33-
role: Director
34-
tasks:
35-
movie_production:
36-
description: Take the script and lead the team to produce the movie 'Cats
37-
in Mars' based on the provided content and script.
38-
expected_output: Completed movie ready for distribution with compelling visuals
39-
and engaging storytelling.
20+
compile_report:
21+
description: Compile all gathered data into a detailed report with analysis
22+
and insights.
23+
expected_output: Well-structured report on the latest AI News with key insights.
4024
tools:
4125
- ''
4226
dependencies: []
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
framework: crewai
2+
topic: create a movie about cat in mars based on https://www.grammarly.com/blog/how-to-write-a-story/
3+
roles:
4+
story_developer:
5+
backstory: Experienced in crafting compelling narratives for a diverse audience.
6+
goal: Develop an engaging storyline for a movie about cats in Mars
7+
role: Story Developer
8+
tasks:
9+
storyline_creation:
10+
description: Create a captivating storyline for a movie about cats in Mars
11+
inspired by the blog post at https://www.grammarly.com/blog/how-to-write-a-story/
12+
expected_output: Detailed storyline with key plot points, character motivations,
13+
and setting descriptions.
14+
tools:
15+
- 'ScrapeWebsiteTool'
16+
screenwriter:
17+
backstory: Proficient in translating complex narratives into engaging screenplay
18+
format.
19+
goal: Transform the storyline into a script
20+
role: Screenwriter
21+
tasks:
22+
script_creation:
23+
description: Transform the developed storyline into a script for the movie
24+
about cats in Mars.
25+
expected_output: Complete script with dialogues, scenes, and stage directions
26+
ready for production.
27+
tools:
28+
- ''
29+
director:
30+
backstory: Experienced in visual storytelling and bringing scripts to life on
31+
screen.
32+
goal: Oversee the production of the movie
33+
role: Director
34+
tasks:
35+
movie_production:
36+
description: Take the script and lead the team to produce the movie 'Cats
37+
in Mars' based on the provided content and script.
38+
expected_output: Completed movie ready for distribution with compelling visuals
39+
and engaging storytelling.
40+
tools:
41+
- ''
42+
dependencies: []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
framework: crewai
2+
topic: research about the latest AI News and prepare a detailed report
3+
roles:
4+
research_analyst:
5+
backstory: Experienced in gathering and analyzing data related to AI news trends.
6+
goal: Analyze AI News trends
7+
role: Research Analyst
8+
tasks:
9+
gather_data:
10+
description: Conduct in-depth research on the latest AI News trends from reputable
11+
sources.
12+
expected_output: Comprehensive report on current AI News trends.
13+
tools:
14+
- 'InternetSearchTool'
15+
content_creator:
16+
backstory: Skilled in writing informative and engaging content about AI News.
17+
goal: Create detailed reports on AI News
18+
role: Content Creator
19+
tasks:
20+
compile_report:
21+
description: Compile all gathered data into a detailed report with analysis
22+
and insights.
23+
expected_output: Well-structured report on the latest AI News with key insights.
24+
tools:
25+
- ''
26+
dependencies: []

praisonai/agents_generator.py

+52-95
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# agents_generator.py
1+
# praisonai/agents_generator.py
22

33
import sys
44
from .version import __version__
@@ -12,13 +12,42 @@
1212
import argparse
1313
from .auto import AutoGenerator
1414
from crewai_tools import *
15-
from .tools import *
15+
from .inbuilt_tools import *
16+
import inspect
17+
from pathlib import Path
18+
import importlib
19+
import importlib.util
1620

1721
class AgentsGenerator:
1822
def __init__(self, agent_file, framework, config_list):
1923
self.agent_file = agent_file
2024
self.framework = framework
2125
self.config_list = config_list
26+
27+
def is_function_or_decorated(self, obj):
28+
return inspect.isfunction(obj) or hasattr(obj, '__call__')
29+
30+
def load_tools_from_module(self, module_path):
31+
spec = importlib.util.spec_from_file_location("tools_module", module_path)
32+
module = importlib.util.module_from_spec(spec)
33+
spec.loader.exec_module(module)
34+
return {name: obj for name, obj in inspect.getmembers(module, self.is_function_or_decorated)}
35+
36+
def load_tools_from_module_class(self, module_path):
37+
spec = importlib.util.spec_from_file_location("tools_module", module_path)
38+
module = importlib.util.module_from_spec(spec)
39+
spec.loader.exec_module(module)
40+
return {name: obj() for name, obj in inspect.getmembers(module, lambda x: inspect.isclass(x) and issubclass(x, BaseTool) and x is not BaseTool)}
41+
42+
def load_tools_from_package(self, package_path):
43+
tools_dict = {}
44+
for module_file in os.listdir(package_path):
45+
if module_file.endswith('.py') and not module_file.startswith('__'):
46+
module_name = f"{package_path.name}.{module_file[:-3]}" # Remove .py for import
47+
module = importlib.import_module(module_name)
48+
for name, obj in inspect.getmembers(module, self.is_function_or_decorated):
49+
tools_dict[name] = obj
50+
return tools_dict
2251

2352
def generate_crew_and_kickoff(self):
2453
if self.agent_file == '/app/api:app' or self.agent_file == 'api:app':
@@ -51,9 +80,20 @@ def generate_crew_and_kickoff(self):
5180
'WebsiteSearchTool': WebsiteSearchTool(),
5281
'XMLSearchTool': XMLSearchTool(),
5382
'YoutubeChannelSearchTool': YoutubeChannelSearchTool(),
54-
'YoutubeVideoSearchTool': YoutubeVideoSearchTool()
83+
'YoutubeVideoSearchTool': YoutubeVideoSearchTool(),
5584
}
56-
# config['tools'] = [tools_dict[tool] for tool in config.get('tools', []) if tool in tools_dict]
85+
root_directory = os.getcwd()
86+
tools_py_path = os.path.join(root_directory, 'tools.py')
87+
tools_dir_path = Path(root_directory) / 'tools'
88+
89+
if os.path.isfile(tools_py_path):
90+
tools_dict.update(self.load_tools_from_module_class(tools_py_path))
91+
print("tools.py exists in the root directory. Loading tools.py and skipping tools folder.")
92+
elif tools_dir_path.is_dir():
93+
tools_dict.update(self.load_tools_from_module_class(tools_dir_path))
94+
print("tools folder exists in the root directory")
95+
# print(tools_dict)
96+
5797
framework = self.framework or config.get('framework')
5898

5999
agents = {}
@@ -86,7 +126,12 @@ def generate_crew_and_kickoff(self):
86126
)
87127
for tool in details.get('tools', []):
88128
if tool in tools_dict:
89-
tool_class = globals()[f'autogen_{type(tools_dict[tool]).__name__}']
129+
try:
130+
tool_class = globals()[f'autogen_{type(tools_dict[tool]).__name__}']
131+
print(f"Found {tool_class.__name__} for {tool}")
132+
except KeyError:
133+
print(f"Warning: autogen_{type(tools_dict[tool]).__name__} function not found. Skipping this tool.")
134+
continue
90135
tool_class(agents[role], user_proxy)
91136

92137
# Preparing tasks for initiate_chats
@@ -121,7 +166,7 @@ def generate_crew_and_kickoff(self):
121166

122167
task = Task(description=description_filled, expected_output=expected_output_filled, agent=agent)
123168
tasks.append(task)
124-
# print(agents)
169+
print(agents.values())
125170
crew = Crew(
126171
agents=list(agents.values()),
127172
tasks=tasks,
@@ -130,92 +175,4 @@ def generate_crew_and_kickoff(self):
130175

131176
response = crew.kickoff()
132177
result = f"### Task Output ###\n{response}"
133-
return result
134-
135-
136-
# # AutoGen Tools example below
137-
# from typing import Any, Optional
138-
# import os
139-
# from autogen import ConversableAgent
140-
# from autogen_tools import autogen_ScrapeWebsiteTool
141-
142-
# assistant = ConversableAgent(
143-
# name="Assistant",
144-
# system_message="You are a helpful AI assistant. "
145-
# "You can help with website scraping. "
146-
# "Return 'TERMINATE' when the task is done.",
147-
# llm_config={"config_list": [{"model": "gpt-3.5-turbo", "api_key": os.environ["OPENAI_API_KEY"]}]},
148-
# )
149-
150-
# user_proxy = ConversableAgent(
151-
# name="User",
152-
# llm_config=False,
153-
# is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
154-
# human_input_mode="NEVER",
155-
# )
156-
157-
# autogen_ScrapeWebsiteTool(assistant, user_proxy)
158-
159-
# chat_result = user_proxy.initiate_chat(assistant, message="Scrape the official Nodejs website.")
160-
161-
# # CrewAI Tools example below
162-
# import os
163-
# from crewai import Agent, Task, Crew
164-
# # Importing crewAI tools
165-
# from crewai_tools import (
166-
# DirectoryReadTool,
167-
# FileReadTool,
168-
# SerperDevTool,
169-
# WebsiteSearchTool
170-
# )
171-
172-
# # Set up API keys
173-
# os.environ["SERPER_API_KEY"] = "Your Key" # serper.dev API key
174-
# os.environ["OPENAI_API_KEY"] = "Your Key"
175-
176-
# # Instantiate tools
177-
# docs_tool = DirectoryReadTool(directory='./blog-posts')
178-
# file_tool = FileReadTool()
179-
# search_tool = SerperDevTool()
180-
# web_rag_tool = WebsiteSearchTool()
181-
182-
# # Create agents
183-
# researcher = Agent(
184-
# role='Market Research Analyst',
185-
# goal='Provide up-to-date market analysis of the AI industry',
186-
# backstory='An expert analyst with a keen eye for market trends.',
187-
# tools=[search_tool, web_rag_tool],
188-
# verbose=True
189-
# )
190-
191-
# writer = Agent(
192-
# role='Content Writer',
193-
# goal='Craft engaging blog posts about the AI industry',
194-
# backstory='A skilled writer with a passion for technology.',
195-
# tools=[docs_tool, file_tool],
196-
# verbose=True
197-
# )
198-
199-
# # Define tasks
200-
# research = Task(
201-
# description='Research the latest trends in the AI industry and provide a summary.',
202-
# expected_output='A summary of the top 3 trending developments in the AI industry with a unique perspective on their significance.',
203-
# agent=researcher
204-
# )
205-
206-
# write = Task(
207-
# description='Write an engaging blog post about the AI industry, based on the research analyst’s summary. Draw inspiration from the latest blog posts in the directory.',
208-
# expected_output='A 4-paragraph blog post formatted in markdown with engaging, informative, and accessible content, avoiding complex jargon.',
209-
# agent=writer,
210-
# output_file='blog-posts/new_post.md' # The final blog post will be saved here
211-
# )
212-
213-
# # Assemble a crew
214-
# crew = Crew(
215-
# agents=[researcher, writer],
216-
# tasks=[research, write],
217-
# verbose=2
218-
# )
219-
220-
# # Execute tasks
221-
# crew.kickoff()
178+
return result

0 commit comments

Comments
 (0)