Skip to content

Commit 04fd825

Browse files
committed
Merge branch 'development' into release
2 parents 5b9895f + edc79e6 commit 04fd825

File tree

10 files changed

+435
-38
lines changed

10 files changed

+435
-38
lines changed

src/examples/crewai_example/instagram_post/__init__.py

Whitespace-only changes.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from crewai import Agent
2+
from tools.browser_tools import scrape_and_summarize_website
3+
from langchain_openai import ChatOpenAI
4+
# from langchain.llms import Ollama
5+
6+
7+
class MarketingAnalysisAgents:
8+
def __init__(self):
9+
# self.llm = Ollama(model=os.environ["MODEL"])
10+
self.llm = ChatOpenAI(model_name="gpt-4", temperature=0.7)
11+
12+
def product_competitor_agent(self):
13+
return Agent(
14+
role="Lead Market Analyst",
15+
goal="""\
16+
Conduct amazing analysis of the products and
17+
competitors, providing in-depth insights to guide
18+
marketing strategies.""",
19+
backstory="""\
20+
As the Lead Market Analyst at a premier
21+
digital marketing firm, you specialize in dissecting
22+
online business landscapes.""",
23+
tools=[scrape_and_summarize_website],
24+
allow_delegation=False,
25+
llm=self.llm,
26+
verbose=True,
27+
)
28+
29+
def strategy_planner_agent(self):
30+
return Agent(
31+
role="Chief Marketing Strategist",
32+
goal="""\
33+
Synthesize amazing insights from product analysis
34+
to formulate incredible marketing strategies.""",
35+
backstory="""\
36+
You are the Chief Marketing Strategist at
37+
a leading digital marketing agency, known for crafting
38+
bespoke strategies that drive success.""",
39+
tools=[scrape_and_summarize_website],
40+
llm=self.llm,
41+
verbose=True,
42+
)
43+
44+
def creative_content_creator_agent(self):
45+
return Agent(
46+
role="Creative Content Creator",
47+
goal="""\
48+
Develop compelling and innovative content
49+
for social media campaigns, with a focus on creating
50+
high-impact Instagram ad copies.""",
51+
backstory="""\
52+
As a Creative Content Creator at a top-tier
53+
digital marketing agency, you excel in crafting narratives
54+
that resonate with audiences on social media.
55+
Your expertise lies in turning marketing strategies
56+
into engaging stories and visual content that capture
57+
attention and inspire action.""",
58+
tools=[scrape_and_summarize_website],
59+
llm=self.llm,
60+
verbose=True,
61+
)
62+
63+
def senior_photographer_agent(self):
64+
return Agent(
65+
role="Senior Photographer",
66+
goal="""\
67+
Take the most amazing photographs for instagram ads that
68+
capture emotions and convey a compelling message.""",
69+
backstory="""\
70+
As a Senior Photographer at a leading digital marketing
71+
agency, you are an expert at taking amazing photographs that
72+
inspire and engage, you're now working on a new campaign for a super
73+
important customer and you need to take the most amazing photograph.""",
74+
tools=[scrape_and_summarize_website],
75+
llm=self.llm,
76+
allow_delegation=False,
77+
verbose=True,
78+
)
79+
80+
def chief_creative_diretor_agent(self):
81+
return Agent(
82+
role="Chief Creative Director",
83+
goal="""\
84+
Oversee the work done by your team to make sure it's the best
85+
possible and aligned with the product's goals, review, approve,
86+
ask clarifying question or delegate follow up work if necessary to make
87+
decisions""",
88+
backstory="""\
89+
You're the Chief Content Officer of leading digital
90+
marketing specialized in product branding. You're working on a new
91+
customer, trying to make sure your team is crafting the best possible
92+
content for the customer.""",
93+
tools=[scrape_and_summarize_website],
94+
llm=self.llm,
95+
verbose=True,
96+
)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
from dotenv import load_dotenv
3+
4+
load_dotenv()
5+
6+
7+
from langtrace_python_sdk import langtrace
8+
9+
langtrace.init()
10+
11+
from crewai import Crew
12+
from agents import MarketingAnalysisAgents
13+
from tasks import MarketingAnalysisTasks
14+
15+
tasks = MarketingAnalysisTasks()
16+
agents = MarketingAnalysisAgents()
17+
18+
print("## Welcome to the marketing Crew")
19+
print('-------------------------------')
20+
product_website = "https://langtrace.ai"
21+
product_details = "LLM App monitoring"
22+
23+
24+
# Create Agents
25+
product_competitor_agent = agents.product_competitor_agent()
26+
# strategy_planner_agent = agents.strategy_planner_agent()
27+
# creative_agent = agents.creative_content_creator_agent()
28+
# # Create Tasks
29+
website_analysis = tasks.product_analysis(product_competitor_agent, product_website, product_details)
30+
# market_analysis = tasks.competitor_analysis(product_competitor_agent, product_website, product_details)
31+
# campaign_development = tasks.campaign_development(strategy_planner_agent, product_website, product_details)
32+
# write_copy = tasks.instagram_ad_copy(creative_agent)
33+
34+
# Create Crew responsible for Copy
35+
copy_crew = Crew(
36+
agents=[
37+
product_competitor_agent,
38+
# strategy_planner_agent,
39+
# creative_agent
40+
],
41+
tasks=[
42+
website_analysis,
43+
# market_analysis,
44+
# campaign_development,
45+
# write_copy
46+
],
47+
verbose=True
48+
)
49+
50+
ad_copy = copy_crew.kickoff()
51+
52+
# Create Crew responsible for Image
53+
# senior_photographer = agents.senior_photographer_agent()
54+
# chief_creative_diretor = agents.chief_creative_diretor_agent()
55+
# # Create Tasks for Image
56+
# take_photo = tasks.take_photograph_task(senior_photographer, ad_copy, product_website, product_details)
57+
# approve_photo = tasks.review_photo(chief_creative_diretor, product_website, product_details)
58+
59+
# image_crew = Crew(
60+
# agents=[
61+
# senior_photographer,
62+
# chief_creative_diretor
63+
# ],
64+
# tasks=[
65+
# take_photo,
66+
# approve_photo
67+
# ],
68+
# verbose=True
69+
# )
70+
71+
# image = image_crew.kickoff()
72+
73+
# Print results
74+
print("\n\n########################")
75+
print("## Here is the result")
76+
print("########################\n")
77+
print("Your post copy:")
78+
print(ad_copy)
79+
# print("'\n\nYour midjourney description:")
80+
# print(image)
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
from crewai import Task
2+
from textwrap import dedent
3+
4+
5+
class MarketingAnalysisTasks:
6+
def product_analysis(self, agent, product_website, product_details):
7+
return Task(
8+
description=dedent(
9+
f"""\
10+
Analyze the given product website: {product_website}.
11+
Extra details provided by the customer: {product_details}.
12+
13+
Focus on identifying unique features, benefits,
14+
and the overall narrative presented.
15+
16+
Your final report should clearly articulate the
17+
product's key selling points, its market appeal,
18+
and suggestions for enhancement or positioning.
19+
Emphasize the aspects that make the product stand out.
20+
21+
Keep in mind, attention to detail is crucial for
22+
a comprehensive analysis. It's currenlty 2024.
23+
"""
24+
),
25+
agent=agent,
26+
expected_output="A detailed analysis of the product website, highlighting key features, benefits, and market positioning.",
27+
)
28+
29+
def competitor_analysis(self, agent, product_website, product_details):
30+
return Task(
31+
description=dedent(
32+
f"""\
33+
Explore competitor of: {product_website}.
34+
Extra details provided by the customer: {product_details}.
35+
36+
Identify the top 3 competitors and analyze their
37+
strategies, market positioning, and customer perception.
38+
39+
Your final report MUST include BOTH all context about {product_website}
40+
and a detailed comparison to whatever competitor they have competitors.
41+
"""
42+
),
43+
agent=agent,
44+
expected_output="A comprehensive analysis of the top 3 competitors, including their strategies, market positioning, and customer perception.",
45+
)
46+
47+
def campaign_development(self, agent, product_website, product_details):
48+
return Task(
49+
description=dedent(
50+
f"""\
51+
You're creating a targeted marketing campaign for: {product_website}.
52+
Extra details provided by the customer: {product_details}.
53+
54+
To start this campaing we will need a strategy and creative content ideas.
55+
It should be meticulously designed to captivate and engage
56+
the product's target audience.
57+
58+
Based on your ideas your co-workers will create the content for the campaign.
59+
60+
Your final answer MUST be ideas that will resonate with the audience and
61+
also include ALL context you have about the product and the customer.
62+
"""
63+
),
64+
agent=agent,
65+
expected_output="A detailed marketing campaign strategy, including creative content ideas and target audience analysis.",
66+
)
67+
68+
def instagram_ad_copy(self, agent):
69+
return Task(
70+
description=dedent(
71+
"""\
72+
Craft an engaging Instagram post copy.
73+
The copy should be punchy, captivating, concise,
74+
and aligned with the product marketing strategy.
75+
76+
Focus on creating a message that resonates with
77+
the target audience and highlights the product's
78+
unique selling points.
79+
80+
Your ad copy must be attention-grabbing and should
81+
encourage viewers to take action, whether it's
82+
visiting the website, making a purchase, or learning
83+
more about the product.
84+
85+
Your final answer MUST be 3 options for an ad copy for instagram that
86+
not only informs but also excites and persuades the audience.
87+
"""
88+
),
89+
agent=agent,
90+
expected_output="Three engaging Instagram ad copies that align with the product marketing strategy.",
91+
)
92+
93+
def take_photograph_task(self, agent, copy, product_website, product_details):
94+
return Task(
95+
description=dedent(
96+
f"""\
97+
You are working on a new campaign for a super important customer,
98+
and you MUST take the most amazing photo ever for an instagram post
99+
regarding the product, you have the following copy:
100+
{copy}
101+
102+
This is the product you are working with: {product_website}.
103+
Extra details provided by the customer: {product_details}.
104+
105+
Imagine what the photo you wanna take describe it in a paragraph.
106+
Here are some examples for you follow:
107+
- high tech airplaine in a beautiful blue sky in a beautiful sunset super cripsy beautiful 4k, professional wide shot
108+
- the last supper, with Jesus and his disciples, breaking bread, close shot, soft lighting, 4k, crisp
109+
- an bearded old man in the snows, using very warm clothing, with mountains full of snow behind him, soft lighting, 4k, crisp, close up to the camera
110+
111+
Think creatively and focus on how the image can capture the audience's
112+
attention. Don't show the actual product on the photo.
113+
114+
Your final answer must be 3 options of photographs, each with 1 paragraph
115+
describing the photograph exactly like the examples provided above.
116+
"""
117+
),
118+
agent=agent,
119+
expected_output="Three high-quality photographs that creatively capture the essence of the product and engage the audience.",
120+
)
121+
122+
def review_photo(self, agent, product_website, product_details):
123+
return Task(
124+
description=dedent(
125+
f"""\
126+
Review the photos you got from the senior photographer.
127+
Make sure it's the best possible and aligned with the product's goals,
128+
review, approve, ask clarifying question or delegate follow up work if
129+
necessary to make decisions. When delegating work send the full draft
130+
as part of the information.
131+
132+
This is the product you are working with: {product_website}.
133+
Extra details provided by the customer: {product_details}.
134+
135+
Here are some examples on how the final photographs should look like:
136+
- high tech airplaine in a beautiful blue sky in a beautiful sunset super cripsy beautiful 4k, professional wide shot
137+
- the last supper, with Jesus and his disciples, breaking bread, close shot, soft lighting, 4k, crisp
138+
- an bearded old man in the snows, using very warm clothing, with mountains full of snow behind him, soft lighting, 4k, crisp, close up to the camera
139+
140+
Your final answer must be 3 reviewed options of photographs,
141+
each with 1 paragraph description following the examples provided above.
142+
"""
143+
),
144+
agent=agent,
145+
expected_output="Three reviewed photographs that align with the product's goals and meet the required standards.",
146+
)

src/examples/crewai_example/instagram_post/tools/__init__.py

Whitespace-only changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import json
2+
import os
3+
4+
import requests
5+
from crewai import Agent, Task
6+
from crewai_tools import tool
7+
from unstructured.partition.html import partition_html
8+
9+
from langchain_openai import ChatOpenAI
10+
11+
12+
@tool
13+
def scrape_and_summarize_website(website):
14+
"""Useful to scrape and summarize a website content, just pass a string with
15+
only the full url, no need for a final slash `/`, eg: https://google.com or https://clearbit.com/about-us"""
16+
url = f"https://chrome.browserless.io/content?token={os.environ['BROWSERLESS_API_KEY']}"
17+
payload = json.dumps({"url": website})
18+
headers = {'cache-control': 'no-cache', 'content-type': 'application/json'}
19+
response = requests.request("POST", url, headers=headers, data=payload)
20+
elements = partition_html(text=response.text)
21+
content = "\n\n".join([str(el) for el in elements])
22+
content = [content[i:i + 8000] for i in range(0, len(content), 8000)]
23+
summaries = []
24+
for chunk in content:
25+
agent = Agent(
26+
role='Principal Researcher',
27+
goal='Do amazing researches and summaries based on the content you are working with',
28+
backstory="You're a Principal Researcher at a big company and you need to do a research about a given topic.",
29+
# llm=Ollama(model=os.environ['MODEL']),
30+
llm=ChatOpenAI(model_name="gpt-4", temperature=0.7),
31+
allow_delegation=False)
32+
task = Task(
33+
agent=agent,
34+
description=f'Analyze and make a LONG summary the content bellow, make sure to include the ALL relevant information in the summary, return only the summary nothing else.\n\nCONTENT\n----------\n{chunk}',
35+
expected_output='A long summary of the content',
36+
)
37+
summary = task.execute_sync()
38+
summaries.append(summary)
39+
content = "\n\n".join(summaries)
40+
return f'\nScrapped Content: {content}\n'

src/langtrace_python_sdk/instrumentation/crewai/instrumentation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ def _instrument(self, **kwargs):
3939
"Crew.kickoff",
4040
patch_crew("Crew.kickoff", version, tracer),
4141
)
42+
_W(
43+
"crewai.crew",
44+
"Crew.kickoff_for_each",
45+
patch_crew("Crew.kickoff_for_each", version, tracer),
46+
)
47+
_W(
48+
"crewai.crew",
49+
"Crew.kickoff_async",
50+
patch_crew("Crew.kickoff_async", version, tracer),
51+
)
52+
_W(
53+
"crewai.crew",
54+
"Crew.kickoff_for_each_async",
55+
patch_crew("Crew.kickoff_for_each_async", version, tracer),
56+
)
4257
_W(
4358
"crewai.agent",
4459
"Agent.execute_task",

0 commit comments

Comments
 (0)