L3: Multi-agent Custormer Support Automation
Multi-agent๋ฅผ ํ์ฉํ ๊ณ ๊ฐ ์ง์ ์๋ํ ์์คํ
- Role Playing
- Focus
- Tools
- Cooperation
- Guardrails
- Memory
ํ์ ํจํค์ง ์ค์น
!pip install crewai==0.28.8 crewai_tools==0.1.6 langchain_community==0.0.29
# ๊ฐ๋จํ warning ์ถ๋ ฅ ๋ฌด์
import warnings
warnings.filterwarnings(action='ignore')
# crewai ๋ผ์ด๋ธ๋ฌ๋ฆฌ import
from crewai import Agent, Task, Crew
# utils.py
# Add your utilities or helper functions to this file.
import os
from dotenv import load_dotenv, find_dotenv
# these expect to find a .env file at the directory above the lesson. # the format for that file is (without the comment) #API_KEYNAME=AStringThatIsTheLongAPIKeyFromSomeService
def load_env():
_ = load_dotenv(find_dotenv())
def get_openai_api_key():
load_env()
openai_api_key = os.getenv("OPENAI_API_KEY")
return openai_api_key
def get_serper_api_key():
load_env()
openai_api_key = os.getenv("SERPER_API_KEY")
return openai_api_key
# break line every 80 characters if line is longer than 80 characters
# don't break in the middle of a word
def pretty_print_result(result):
parsed_result = []
for line in result.split('\n'):
if len(line) > 80:
words = line.split(' ')
new_line = ''
for word in words:
if len(new_line) + len(word) + 1 > 80:
parsed_result.append(new_line)
new_line = word
else:
if new_line == '':
new_line = word
else:
new_line += ' ' + word
parsed_result.append(new_line)
else:
parsed_result.append(line)
return "\n".join(parsed_result)
# ๋ณธ ์์ ์์๋ GPT-3.5-turbo ๋ชจ๋ธ์ ์ฌ์ฉํฉ๋๋ค.
import os
openai_api_key = get_openai_api_key()
#os.environ["OPENAI_MODEL_NAME"] = 'gpt-3.5-turbo'
os.environ["OPENAI_MODEL_NAME"] = 'gpt-4o'
1. Role Playing, Focus and Cooperation
# ์ํฌํธ ์์ด์ ํธ ์์ฑ
support_agent = Agent(
role="์๋์ด๊ธ ์ํฌํธ ๋ํ",
goal="ํ์์ ๊ฐ์ฅ ์น์ ํ๊ณ ๋์์ด ๋๋ ์ง์ ๋ํ๊ฐ ๋๋ ๊ฒ",
backstory=(
"๋์ ์ผ์ crewAI (https://crewai.com)์์ ์ผํ๊ณ ์์ผ๋ฉฐ, "
"{customer}์๊ฒ ์ง์์ ์ ๊ณตํ๊ณ ์์ต๋๋ค. "
"๋์ ํ์ฌ์๊ฒ ๋งค์ฐ ์ค์ํ ๊ณ ๊ฐ์
๋๋ค. "
"๋๋ ์ต๊ณ ์ ์ง์์ ์ ๊ณตํด์ผ ํฉ๋๋ค!"
"์์ ํ๊ณ ์์ ํ ๋ต๋ณ์ ์ ๊ณตํ๊ณ , ๊ฐ์ ํ์ง ๋ง์ญ์์ค."
),
allow_delegation=False,
verbose=True
)
allow_delegation=False
์ค์ ์ ์์ด์ ํธ๊ฐ ๋ค๋ฅธ ์์ด์ ํธ์๊ฒ ํน์ ์์ ์ ์์ํ ์ ์๋๋ก ํฉ๋๋ค.- ์ด๋ ์์ด์ ํธ๊ฐ ํน์ ์์ ์ ์ํํ๋ ๋ฐ ๋ ์ ํฉํ ๋ค๋ฅธ ์์ด์ ํธ์๊ฒ ์์ ์ ์์ํ ์ ์๋๋ก ํฉ๋๋ค.
# ํ์ง ๋ณด์ฆ ์ง์ ์์ด์ ํธ ์์ฑ
support_quality_assurance_agent = Agent(
role="Quality Assurance ์ง์ ์ ๋ฌธ๊ฐ",
goal="ํ์๊ฒ ์ต๊ณ ์ ์ง์ ํ์ง ๋ณด์ฆ์ ์ ๊ณตํ์ฌ ์ธ์ ๋ฐ๋ ๊ฒ",
backstory=(
"๋์ ์ผ์ crewAI (https://crewai.com)์์ ์ผํ๊ณ ์์ผ๋ฉฐ, "
"{customer}์๊ฒ ์ง์์ ์ ๊ณตํ๊ณ ์์ต๋๋ค. "
"๋์ ํ์ฌ์๊ฒ ๋งค์ฐ ์ค์ํ ๊ณ ๊ฐ์
๋๋ค. "
"๋๋ ์ต๊ณ ์ ์ง์์ ์ ๊ณตํด์ผ ํฉ๋๋ค!"
"์์ ํ๊ณ ์์ ํ ๋ต๋ณ์ ์ ๊ณตํ๊ณ , ๊ฐ์ ํ์ง ๋ง์ญ์์ค."
),
verbose=True
)
#### ํ๊ธ ๋ฒ์ญ๊ฐ ์์ฑ
translator = Agent(
role="๋ฒ์ญ๊ฐ",
goal="๋ฒ์ญ๊ฐ๋ ์ฃผ์ด์ง ๊ธ์ ํ๊ธ๋ก ๋ฒ์ญํฉ๋๋ค.",
backstory="๋๋ QA๋ก๋ถํฐ ๊ธฐ์ ์๋ฌธ์ ํ๊ตญ์ด๋ก ๋ฒ์ญํ๋ ๋ฒ์ญ๊ฐ์
๋๋ค. "
"๋์ ๋ชฉํ๋ ๋ต๋ณ์ ๋ค๋ฅธ ์ธ์ด๋ก ๋ฒ์ญํ๋ ๊ฒ์
๋๋ค. "
"๋ฒ์ญ์ ์๋ณธ์ ์๋ฏธ๋ฅผ ์ต๋ํ ์ ์งํ๋ฉด์ "
"๋
์๊ฐ ์ฝ๊ฒ ์ดํดํ ์ ์๋๋ก ํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค.",
allow_delegation=False,
verbose=True
)

Delegation (์์)
- CrewAI ์์ด์ ํธ๋ ๋ค๋ฅธ ์์ด์ ํธ์๊ฒ ์ผ๋ถ ์์ ์ ์์ํ ์ ์์ต๋๋ค.
- ์์์ ์์ด์ ํธ๊ฐ ์์ ์ ์๋ฃํ ์ ์์ ๋ ์ฌ์ฉ๋ฉ๋๋ค.
- Query์ ์์ค์ ๋ฐ๋ผ ์์์ด ๊ฐ๋ฅํฉ๋๋ค.
- ์๋ฅผ ๋ค๋ฉด, ์ง๋ฌธ์ ๋์ด๋๊ฐ ๋ฎ์ ๊ฒฝ์ฐ์๋ ์ํฌํธ ์์ด์ ํธ์ ๋ต๋ณ์์ ๋์ด๋๊ณ ๋ ์ด์์ ์์์ด ํ์ํ์ง ์์ ์ ์์ต๋๋ค.
- ๋ฐ๋ฉด์, ์ง๋ฌธ์ ๋์ด๋๊ฐ ๋์ ๊ฒฝ์ฐ์๋ ์ฌ๋ฌ ๋จ๊ณ์ ์์์ด ํ์ํ ์ ์์ต๋๋ค.
- ์์์ ๋จ๊ณ์ ์ผ๋ก ์ด๋ฃจ์ด์ง ์ ์์ต๋๋ค.
- delegation์ด ๊ผญ ํ์ํ์ง ์์ ๊ฒฝ์ฐ์๋ ์์์ ์ฌ์ฉํ์ง ์์๋ ๋ฉ๋๋ค.
- ํํ๊ฒ reviewer๊ฐ ํ์ํ ์์ ์ ์์์ ์ฌ์ฉํฉ๋๋ค.
[Agent Role]
- Role Playing: ๋ ์์ด์ ํธ์๊ฒ ์ญํ , ๋ชฉํ ๋ฐ ๋ฐฐ๊ฒฝ ์ด์ผ๊ธฐ๊ฐ ์ฃผ์ด์ก์ต๋๋ค.
- Focus: ๋ ์์ด์ ํธ์๊ฒ ์์ ๋ค์ด ํ๋ ์ดํ๋ ์ญํ ์ ๋ํด ์ง์คํ ๊ฒ์ ์์ฒญํ์ต๋๋ค.
- Cooperation: ์ง์ ํ์ง ๋ณด์ฆ ์์ด์ ํธ๋ ์ง์ ์์ด์ ํธ์๊ฒ ์์ ์ ์์ํ ์ ์์ผ๋ฏ๋ก ์ด ๋ ์์ด์ ํธ๊ฐ ํจ๊ป ์์ ํ ์ ์์ต๋๋ค.
2. Tools, Guardrails and Memory¶
Tools : agent๊ฐ ์ฌ์ฉํ ์ ์๋ ๋๊ตฌ๋ค์ ์ ์ํฉ๋๋ค. ๋ง์ Tool์ด github repository์ ์์ต๋๋ค. ์ด๋ฒ ์์ ์์๋ crewai_tools์ ์ผ๋ถ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
- SerperDevTool : ํน๋ณํ ๋ชฉ์ ์ ์ํ ๋๊ตฌ๋ก, ๊ฐ๋ฐ ์ค์ธ ํน์ ๊ธฐ๋ฅ์ ๊ฐ์ง๊ณ ์์ต๋๋ค.
- ScrapeWebsiteTool : ์น์ฌ์ดํธ์ ์ ์ฒด ๋ด์ฉ์ ์คํฌ๋ํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค. data collection์ ์ด์์ ์ ๋๋ค.
- WebsiteSearchTool : ์น์ฌ์ดํธ ์ปจํ ์ธ ๊ฒ์์ ์ํ RAG ๋๊ตฌ๋ก, ์น ๋ฐ์ดํฐ ์ถ์ถ์ ์ต์ ํ๋์ด ์์ต๋๋ค.
๊ธฐํ Tools ์ฌ์ฉ ์์ ¶
- ๊ณ ๊ฐ ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ
- ์ด์ ๋ํ์ ์ ๊ทผํ๊ธฐ
- CRM์์ ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ
- ๊ธฐ์กด ๋ฒ๊ทธ ๋ณด๊ณ ์ ํ์ธ
- ๊ธฐ์กด ๊ธฐ๋ฅ ์์ฒญ ํ์ธ
- ์งํ ์ค์ธ ํฐ์ผ ํ์ธ
- ๋ฑ ๋ฑ
from crewai_tools import SerperDevTool, \
ScrapeWebsiteTool, \
WebsiteSearchTool
# crewai docs ์คํฌ๋ํ ๋๊ตฌ ์์
search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool() # ์ ์ฒด ์น์ฌ์ดํธ ์คํฌ๋ํ ๋๊ตฌ
docs_scrape_tool = ScrapeWebsiteTool(
website_url="https://docs.crewai.com/how-to/Creating-a-Crew-and-kick-it-off/"
)
๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก ์์ด์ ํธ์๊ฒ ๋๊ตฌ๋ฅผ ์ ๊ณตํ๋ ๋ฐฉ๋ฒ¶
- Agent Level: ์์ด์ ํธ๋ ์ํํ๋ ๋ชจ๋ ์์ ์์ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
- Task Level: ์์ด์ ํธ๋ ํด๋น ํน์ ์์ ์ ์ํํ ๋๋ง ๋๊ตฌ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
Note: Task Tools๋ Agent Tools๋ฅผ ๋ฌด์ํฉ๋๋ค.
Tasks ์์ฑ¶
- Tool์ Task level์ ์ ๋ฌ ํฉ๋๋ค.
inquiry_resolution = Task(
description=(
"{customer}์ ๋น์ ์๊ฒ ๋งค์ฐ ์ค์ํ ์ง๋ฌธ์ ํ์ต๋๋ค. :"
"{inquiry}\n\n"
"{customer}์ {person}์ด ์ฐ๋ฝํ์ต๋๋ค. "
"๊ฐ๋ฅํ ์ต์์ ์ง์์ ์ ๊ณตํ๋๋ก ๋
ธ๋ ฅํ์ญ์์ค."
"๊ณ ๊ฐ์ ์ง๋ฌธ์ ์์ ํ๊ณ ์ ํํ ๋ต๋ณ์ ์ ๊ณตํด์ผ ํฉ๋๋ค."
"๋ชจ๋ ๊ฒ์ ์ฌ์ฉํ์ฌ ์ต์์ ์ง์์ ์ ๊ณตํ์ญ์์ค."
),
expected_output=(
"์์ธํ๊ณ ์ ๋ณด๊ฐ ํ๋ถํ ๋ต๋ณ์ ์ ๊ณตํ์ญ์์ค. "
"๊ณ ๊ฐ์ ์ง๋ฌธ์ ๋ชจ๋ ์ธก๋ฉด์ ๋ค๋ฃน๋๋ค. "
"๋ต๋ณ์๋ ๋ต์ ์ฐพ๋ ๋ฐ ์ฌ์ฉํ ๋ชจ๋ ๊ฒ์ ๋ํ ์ฐธ์กฐ๊ฐ ํฌํจ๋์ด์ผ ํฉ๋๋ค. "
"๋ต๋ณ์ด ์์ ํ๊ณ ์ง๋ฌธ์ด ํ๋๋ ๋จ์ง ์๋๋กํ์ญ์์ค. "
"๋ต๋ณ ๋ด์ฉ์ ๋์์ด ๋๊ณ ์น์ ํ ํค์ ์ ์งํ์ญ์์ค."
),
tools=[docs_scrape_tool],
agent=support_agent,
)
quality_assurance_review
๋ ์ด๋ค ๋๊ตฌ๋ ์ฌ์ฉํ์ง ์์ต๋๋ค.- ์ฌ๊ธฐ์ QA ์์ด์ ํธ๋ ์ง์ ์์ด์ ํธ์ ์์ ์ ๊ฒํ ํฉ๋๋ค.
quality_assurance_review = Task(
description=(
"๋ฆฌ๋ทฐ๋ฅผ ํตํด {customer}์ ๋ํ ๋ต๋ณ์ด ์์ ํ๊ณ ์ ํํ๋ฉฐ ๊ณ ๊ฐ ์ง์์ ๋ํ "
"๊ธฐ๋์น๊ฐ ๋์ ํ์ง ๊ธฐ์ค์ ์ค์ํ๋์ง ํ์ธํ์ญ์์ค.\n"
"๊ณ ๊ฐ์ ์ง๋ฌธ์ ๋ชจ๋ ๋ถ๋ถ์ด ์น์ ํ๊ณ ์น์ ํ ํค์ผ๋ก "
"์ฒ ์ ํ๊ฒ ๋ค๋ฃจ์ด์ก๋์ง ํ์ธํ์ญ์์ค.\n"
"์ ๋ณด๋ฅผ ์ฐพ๋ ๋ฐ ์ฌ์ฉ๋ ์ฐธ์กฐ ๋ฐ ์์ค๋ฅผ ํ์ธํ์ฌ "
"๋ต๋ณ์ด ์ ์ง์๋์๊ณ "
"์ง๋ฌธ์ด ํ๋๋ ๋จ์ง ์๋๋กํ์ญ์์ค."
),
expected_output=(
"๋ง์ง๋ง์ผ๋ก, ๋ต๋ณ์ ๊ณ ๊ฐ์๊ฒ ๋ณด๋ผ ์ค๋น๊ฐ ๋์ด์ผ ํฉ๋๋ค. "
"์ด ๋ต๋ณ์ ๊ณ ๊ฐ์ ์ง๋ฌธ์ ์์ ํ ๋ค๋ฃจ๋ฉฐ ๋ชจ๋ ๊ด๋ จ ํผ๋๋ฐฑ๊ณผ ๊ฐ์ ์ฌํญ์ "
"ํฌํจํด์ผํฉ๋๋ค.\n"
"๋๋ฌด ๊ณต์์ ์ด์ง ์๊ฒ, ์ฐ๋ฆฌ๋ ์น ํ ํ์ฌ์ง๋ง ์ ๋ฌธ์ ์ด๊ณ ์น๊ทผํ ํค์ ์ ์งํ์ญ์์ค."
),
agent=support_quality_assurance_agent,
)
translate = Task(
description=("์ฃผ์ด์ง ๊ธ์ ํ๊ธ๋ก ๋ฒ์ญํฉ๋๋ค."
"๊ตฌ์ด์ฒด์ ๊ฒฝ์ด์ฒด๋ฅผ ์์ด์ ๋ฒ์ญํ์ธ์."),
expected_output="ํ๊ตญ์ด๋ก ๋ฒ์ญ๋ ๊ธ์ ์ ๊ณตํฉ๋๋ค.",
agent=translator
)
Crew ์์ฑ¶
- Memory:
memory=True
์ค์ ์ crew๊ฐ ์ด์ ์ ์ํํ ์์ ์ ํจ๊ป ์ ๋ ฅํฉ๋๋ค. ์ด๋ ๋ค์ ์์ ์ ์ํํ ๋ ์ด์ ์์ ์ ๊ฒฐ๊ณผ๋ฅผ ์ ์ ์๊ฒ ์ ๋ฌํฉ๋๋ค.
crew = Crew(
agents=[support_agent, support_quality_assurance_agent, translator],
tasks=[inquiry_resolution, quality_assurance_review, translate],
verbose=2,
memory=True
)
Guardrails¶
- ์๋ ์คํ์ ํตํด, ์์ด์ ํธ์ ์๋ต์ด ์ฐ๋ฆฌ๊ฐ ๊ธฐ๋ํ๋ ๋ฒ์ ๋ด์ ์๋์ง ํ์ธํ ์ ์์ต๋๋ค.
inputs = {
"customer": "DeepLearningAI",
"person": "Andrew Ng",
"inquiry": "Crew๋ฅผ ์ค์ ํ๊ณ ์์ํ๋ ๋ฐ ๋์์ด ํ์ํฉ๋๋ค. "
"ํนํ ํฌ๋ฃจ์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ์ ๋ํด "
"์๋ด๋ฅผ ์ ๊ณตํ ์ ์์ต๋๊น?"
}
result = crew.kickoff(inputs=inputs)
[DEBUG]: == Working Agent: ์๋์ด๊ธ ์ํฌํธ ๋ํ
[INFO]: == Starting Task: DeepLearningAI์ ๋น์ ์๊ฒ ๋งค์ฐ ์ค์ํ ์ง๋ฌธ์ ํ์ต๋๋ค. :Crew๋ฅผ ์ค์ ํ๊ณ ์์ํ๋ ๋ฐ ๋์์ด ํ์ํฉ๋๋ค. ํนํ ํฌ๋ฃจ์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์๋ด๋ฅผ ์ ๊ณตํ ์ ์์ต๋๊น?
DeepLearningAI์ Andrew Ng์ด ์ฐ๋ฝํ์ต๋๋ค. ๊ฐ๋ฅํ ์ต์์ ์ง์์ ์ ๊ณตํ๋๋ก ๋
ธ๋ ฅํ์ญ์์ค.๊ณ ๊ฐ์ ์ง๋ฌธ์ ์์ ํ๊ณ ์ ํํ ๋ต๋ณ์ ์ ๊ณตํด์ผ ํฉ๋๋ค.๋ชจ๋ ๊ฒ์ ์ฌ์ฉํ์ฌ ์ต์์ ์ง์์ ์ ๊ณตํ์ญ์์ค.
2024-05-25 22:03:34,346 - 8670450240 - manager.py-manager:282 - WARNING: Error in TokenCalcHandler.on_llm_start callback: KeyError('Could not automatically map gpt-4o to a tokeniser. Please use `tiktoken.get_encoding` to explicitly get the tokeniser you expect.')
2024-05-25 22:03:34,347 - 8670450240 - manager.py-manager:282 - WARNING: Error in TokenCalcHandler.on_llm_start callback: KeyError('Could not automatically map gpt-4o to a tokeniser. Please use `tiktoken.get_encoding` to explicitly get the tokeniser you expect.')
2024-05-25 22:03:34,347 - 8670450240 - manager.py-manager:282 - WARNING: Error in TokenCalcHandler.on_llm_start callback: KeyError('Could not automatically map gpt-4o to a tokeniser. Please use `tiktoken.get_encoding` to explicitly get the tokeniser you expect.')
> Entering new CrewAgentExecutor chain...
Thought: To provide the best possible and accurate support for DeepLearningAI, I need to gather detailed information on how to set up a Crew and add memory to it in CrewAI. I will first read the relevant content from the provided documentation link.
Action: Read website content
Action Input: {"url": "https://docs.crewai.com/how-to/Creating-a-Crew-and-kick-it-off/"}
2024-05-25 22:03:37,550 - 8670450240 - manager.py-manager:282 - WARNING: Error in TokenCalcHandler.on_llm_start callback: KeyError('Could not automatically map gpt-4o to a tokeniser. Please use `tiktoken.get_encoding` to explicitly get the tokeniser you expect.')
2024-05-25 22:03:37,551 - 8670450240 - manager.py-manager:282 - WARNING: Error in TokenCalcHandler.on_llm_start callback: KeyError('Could not automatically map gpt-4o to a tokeniser. Please use `tiktoken.get_encoding` to explicitly get the tokeniser you expect.')
2024-05-25 22:03:37,551 - 8670450240 - manager.py-manager:282 - WARNING: Error in TokenCalcHandler.on_llm_start callback: KeyError('Could not automatically map gpt-4o to a tokeniser. Please use `tiktoken.get_encoding` to explicitly get the tokeniser you expect.')
Assembling and Activating Your CrewAI Team - crewAI
Skip to content
crewAI
Assembling and Activating Your CrewAI Team
Initializing search
crewAI
crewAI
crewAI
Home
Core Concepts
Core Concepts
Agents
Tasks
Tools
Processes
Crews
Collaboration
Memory
How to Guides
How to Guides
Installing CrewAI
Getting Started
Getting Started
Table of contents
Introduction
Step 0: Installation
Step 1: Assemble Your Agents
Step 2: Define the Tasks
Step 3: Form the Crew
Step 4: Kick It Off
Conclusion
Create Custom Tools
Using Sequential Process
Using Hierarchical Process
Connecting to any LLM
Customizing Agents
Human Input on Execution
Agent Monitoring with AgentOps
Tools Docs
Tools Docs
Google Serper Search
Browserbase Web Loader
Scrape Website
Directory Read
File Read
Selenium Scraper
Directory RAG Search
PDF RAG Search
TXT RAG Search
CSV RAG Search
XML RAG Search
JSON RAG Search
Docx Rag Search
MDX RAG Search
PG RAG Search
Website RAG Search
Github RAG Search
Code Docs RAG Search
Youtube Video RAG Search
Youtube Channel RAG Search
Examples
Examples
Trip Planner Crew
Create Instagram Post
Stock Analysis
Game Generator
Drafting emails with LangGraph
Landing Page Generator
Prepare for meetings
Telemetry
Getting Started
Introduction¶
Embark on your CrewAI journey by setting up your environment and initiating your AI crew with the latest features. This guide ensures a smooth start, incorporating all recent updates for an enhanced experience.
Step 0: Installation¶
Install CrewAI and any necessary packages for your project. CrewAI is compatible with Python >=3.10,<=3.13.
pip install crewai
pip install 'crewai[tools]'
Step 1: Assemble Your Agents¶
Define your agents with distinct roles, backstories, and enhanced capabilities like verbose mode and memory usage. These elements add depth and guide their task execution and interaction within the crew.
import os
os.environ["SERPER_API_KEY"] = "Your Key" # serper.dev API key
os.environ["OPENAI_API_KEY"] = "Your Key"
from crewai import Agent
from crewai_tools import SerperDevTool
search_tool = SerperDevTool()
# Creating a senior researcher agent with memory and verbose mode
researcher = Agent(
role='Senior Researcher',
goal='Uncover groundbreaking technologies in {topic}',
verbose=True,
memory=True,
backstory=(
"Driven by curiosity, you're at the forefront of"
"innovation, eager to explore and share knowledge that could change"
"the world."
),
tools=[search_tool],
allow_delegation=True
)
# Creating a writer agent with custom tools and delegation capability
writer = Agent(
role='Writer',
goal='Narrate compelling tech stories about {topic}',
verbose=True,
memory=True,
backstory=(
"With a flair for simplifying complex topics, you craft"
"engaging narratives that captivate and educate, bringing new"
"discoveries to light in an accessible manner."
),
tools=[search_tool],
allow_delegation=False
)
Step 2: Define the Tasks¶
Detail the specific objectives for your agents, including new features for asynchronous execution and output customization. These tasks ensure a targeted approach to their roles.
from crewai import Task
# Research task
research_task = Task(
description=(
"Identify the next big trend in {topic}."
"Focus on identifying pros and cons and the overall narrative."
"Your final report should clearly articulate the key points,"
"its market opportunities, and potential risks."
),
expected_output='A comprehensive 3 paragraphs long report on the latest AI trends.',
tools=[search_tool],
agent=researcher,
)
# Writing task with language model configuration
write_task = Task(
description=(
"Compose an insightful article on {topic}."
"Focus on the latest trends and how it's impacting the industry."
"This article should be easy to understand, engaging, and positive."
),
expected_output='A 4 paragraph article on {topic} advancements formatted as markdown.',
tools=[search_tool],
agent=writer,
async_execution=False,
output_file='new-blog-post.md' # Example of output customization
)
Step 3: Form the Crew¶
Combine your agents into a crew, setting the workflow process they'll follow to accomplish the tasks. Now with options to configure language models for enhanced interaction and additional configurations for optimizing performance.
from crewai import Crew, Process
# Forming the tech-focused crew with some enhanced configurations
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential, # Optional: Sequential task execution is default
memory=True,
cache=True,
max_rpm=100,
share_crew=True
)
Step 4: Kick It Off¶
Initiate the process with your enhanced crew ready. Observe as your agents collaborate, leveraging their new capabilities for a successful project outcome. Input variables will be interpolated into the agents and tasks for a personalized approach.
# Starting the task execution process with enhanced feedback
result = crew.kickoff(inputs={'topic': 'AI in healthcare'})
print(result)
Conclusion¶
Building and activating a crew in CrewAI has evolved with new functionalities. By incorporating verbose mode, memory capabilities, asynchronous task execution, output customization, language model configuration, and enhanced crew configurations, your AI team is more equipped than ever to tackle challenges efficiently. The depth of agent backstories and the precision of their objectives enrich collaboration, leading to successful project outcomes. This guide aims to provide you with a clear and detailed understanding of setting up and utilizing the CrewAI framework to its full potential.
Back to top
Previous
Installing CrewAI
Next
Create Custom Tools
Copyright © 2024 crewAI, Inc
Made with
Material for MkDocs
2024-05-25 22:03:50,724 - 8670450240 - manager.py-manager:282 - WARNING: Error in TokenCalcHandler.on_llm_start callback: KeyError('Could not automatically map gpt-4o to a tokeniser. Please use `tiktoken.get_encoding` to explicitly get the tokeniser you expect.')
2024-05-25 22:03:50,725 - 8670450240 - manager.py-manager:282 - WARNING: Error in TokenCalcHandler.on_llm_start callback: KeyError('Could not automatically map gpt-4o to a tokeniser. Please use `tiktoken.get_encoding` to explicitly get the tokeniser you expect.')
2024-05-25 22:03:50,725 - 8670450240 - manager.py-manager:282 - WARNING: Error in TokenCalcHandler.on_llm_start callback: KeyError('Could not automatically map gpt-4o to a tokeniser. Please use `tiktoken.get_encoding` to explicitly get the tokeniser you expect.')
Thought: I now can give a great answer
Final Answer:
Hello Andrew,
Thank you for reaching out! I'd be happy to guide you through setting up a Crew and adding memory to it in CrewAI. Below are the detailed steps to help you get started:
### Setting Up a Crew and Adding Memory in CrewAI
#### Step 0: Installation
First, ensure you have CrewAI and the necessary packages installed. CrewAI is compatible with Python versions >=3.10 and <=3.13. You can install it using the following commands:
```bash
pip install crewai
pip install 'crewai[tools]'
```
#### Step 1: Assemble Your Agents
Next, you need to define your agents with specific roles, backstories, and capabilities like verbose mode and memory usage. Here's an example of creating two agents:
```python
import os
os.environ["SERPER_API_KEY"] = "Your Key" # serper.dev API key
os.environ["OPENAI_API_KEY"] = "Your Key"
from crewai import Agent
from crewai_tools import SerperDevTool
search_tool = SerperDevTool()
# Creating a senior researcher agent with memory and verbose mode
researcher = Agent(
role='Senior Researcher',
goal='Uncover groundbreaking technologies in {topic}',
verbose=True,
memory=True,
backstory=(
"Driven by curiosity, you're at the forefront of"
"innovation, eager to explore and share knowledge that could change"
"the world."
),
tools=[search_tool],
allow_delegation=True
)
# Creating a writer agent with custom tools and delegation capability
writer = Agent(
role='Writer',
goal='Narrate compelling tech stories about {topic}',
verbose=True,
memory=True,
backstory=(
"With a flair for simplifying complex topics, you craft"
"engaging narratives that captivate and educate, bringing new"
"discoveries to light in an accessible manner."
),
tools=[search_tool],
allow_delegation=False
)
```
#### Step 2: Define the Tasks
Define specific tasks for your agents, including details for asynchronous execution and output customization. Here are examples of tasks for the agents:
```python
from crewai import Task
# Research task
research_task = Task(
description=(
"Identify the next big trend in {topic}. "
"Focus on identifying pros and cons and the overall narrative. "
"Your final report should clearly articulate the key points, "
"its market opportunities, and potential risks."
),
expected_output='A comprehensive 3 paragraphs long report on the latest AI trends.',
tools=[search_tool],
agent=researcher,
)
# Writing task with language model configuration
write_task = Task(
description=(
"Compose an insightful article on {topic}. "
"Focus on the latest trends and how it's impacting the industry. "
"This article should be easy to understand, engaging, and positive."
),
expected_output='A 4 paragraph article on {topic} advancements formatted as markdown.',
tools=[search_tool],
agent=writer,
async_execution=False,
output_file='new-blog-post.md' # Example of output customization
)
```
#### Step 3: Form the Crew
Combine your agents into a crew, setting the workflow process they will follow to accomplish the tasks. Here’s an example of forming a crew with memory:
```python
from crewai import Crew, Process
# Forming the tech-focused crew with some enhanced configurations
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential, # Optional: Sequential task execution is default
memory=True,
cache=True,
max_rpm=100,
share_crew=True
)
```
#### Step 4: Kick It Off
Finally, initiate the process with your enhanced crew ready. Here’s how you can start the task execution process:
```python
# Starting the task execution process with enhanced feedback
result = crew.kickoff(inputs={'topic': 'AI in healthcare'})
print(result)
```
### Conclusion
By following these steps, you will have successfully set up a Crew in CrewAI with memory capabilities. This setup allows your agents to remember context and previous interactions, improving their performance and collaboration.
If you have any further questions or need additional assistance, please don't hesitate to reach out. We're here to help!
Best regards,
[Your Name]
CrewAI Support Representative
> Finished chain.
[DEBUG]: == [์๋์ด๊ธ ์ํฌํธ ๋ํ] Task output: Hello Andrew,
Thank you for reaching out! I'd be happy to guide you through setting up a Crew and adding memory to it in CrewAI. Below are the detailed steps to help you get started:
### Setting Up a Crew and Adding Memory in CrewAI
#### Step 0: Installation
First, ensure you have CrewAI and the necessary packages installed. CrewAI is compatible with Python versions >=3.10 and <=3.13. You can install it using the following commands:
```bash
pip install crewai
pip install 'crewai[tools]'
```
#### Step 1: Assemble Your Agents
Next, you need to define your agents with specific roles, backstories, and capabilities like verbose mode and memory usage. Here's an example of creating two agents:
```python
import os
os.environ["SERPER_API_KEY"] = "Your Key" # serper.dev API key
os.environ["OPENAI_API_KEY"] = "Your Key"
from crewai import Agent
from crewai_tools import SerperDevTool
search_tool = SerperDevTool()
# Creating a senior researcher agent with memory and verbose mode
researcher = Agent(
role='Senior Researcher',
goal='Uncover groundbreaking technologies in {topic}',
verbose=True,
memory=True,
backstory=(
"Driven by curiosity, you're at the forefront of"
"innovation, eager to explore and share knowledge that could change"
"the world."
),
tools=[search_tool],
allow_delegation=True
)
# Creating a writer agent with custom tools and delegation capability
writer = Agent(
role='Writer',
goal='Narrate compelling tech stories about {topic}',
verbose=True,
memory=True,
backstory=(
"With a flair for simplifying complex topics, you craft"
"engaging narratives that captivate and educate, bringing new"
"discoveries to light in an accessible manner."
),
tools=[search_tool],
allow_delegation=False
)
```
#### Step 2: Define the Tasks
Define specific tasks for your agents, including details for asynchronous execution and output customization. Here are examples of tasks for the agents:
```python
from crewai import Task
# Research task
research_task = Task(
description=(
"Identify the next big trend in {topic}. "
"Focus on identifying pros and cons and the overall narrative. "
"Your final report should clearly articulate the key points, "
"its market opportunities, and potential risks."
),
expected_output='A comprehensive 3 paragraphs long report on the latest AI trends.',
tools=[search_tool],
agent=researcher,
)
# Writing task with language model configuration
write_task = Task(
description=(
"Compose an insightful article on {topic}. "
"Focus on the latest trends and how it's impacting the industry. "
"This article should be easy to understand, engaging, and positive."
),
expected_output='A 4 paragraph article on {topic} advancements formatted as markdown.',
tools=[search_tool],
agent=writer,
async_execution=False,
output_file='new-blog-post.md' # Example of output customization
)
```
#### Step 3: Form the Crew
Combine your agents into a crew, setting the workflow process they will follow to accomplish the tasks. Here’s an example of forming a crew with memory:
```python
from crewai import Crew, Process
# Forming the tech-focused crew with some enhanced configurations
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential, # Optional: Sequential task execution is default
memory=True,
cache=True,
max_rpm=100,
share_crew=True
)
```
#### Step 4: Kick It Off
Finally, initiate the process with your enhanced crew ready. Here’s how you can start the task execution process:
```python
# Starting the task execution process with enhanced feedback
result = crew.kickoff(inputs={'topic': 'AI in healthcare'})
print(result)
```
### Conclusion
By following these steps, you will have successfully set up a Crew in CrewAI with memory capabilities. This setup allows your agents to remember context and previous interactions, improving their performance and collaboration.
If you have any further questions or need additional assistance, please don't hesitate to reach out. We're here to help!
Best regards,
[Your Name]
CrewAI Support Representative
[DEBUG]: == Working Agent: Quality Assurance ์ง์ ์ ๋ฌธ๊ฐ
[INFO]: == Starting Task: ๋ฆฌ๋ทฐ๋ฅผ ํตํด DeepLearningAI์ ๋ํ ๋ต๋ณ์ด ์์ ํ๊ณ ์ ํํ๋ฉฐ ๊ณ ๊ฐ ์ง์์ ๋ํ ๊ธฐ๋์น๊ฐ ๋์ ํ์ง ๊ธฐ์ค์ ์ค์ํ๋์ง ํ์ธํ์ญ์์ค.
๊ณ ๊ฐ์ ์ง๋ฌธ์ ๋ชจ๋ ๋ถ๋ถ์ด ์น์ ํ๊ณ ์น์ ํ ํค์ผ๋ก ์ฒ ์ ํ๊ฒ ๋ค๋ฃจ์ด์ก๋์ง ํ์ธํ์ญ์์ค.
์ ๋ณด๋ฅผ ์ฐพ๋ ๋ฐ ์ฌ์ฉ๋ ์ฐธ์กฐ ๋ฐ ์์ค๋ฅผ ํ์ธํ์ฌ ๋ต๋ณ์ด ์ ์ง์๋์๊ณ ์ง๋ฌธ์ด ํ๋๋ ๋จ์ง ์๋๋กํ์ญ์์ค.
To ensure that the response to Andrew from DeepLearningAI is complete, accurate, and meets our high-quality standards, I will first review the provided context thoroughly. I will then check if all parts of the customer’s question are addressed in a friendly and professional tone. Additionally, I will verify the references and sources used to ensure their accuracy. Finally, I will include specific examples, address potential challenges, and provide a call-to-action to prompt further engagement with the customer.
First, I need to confirm the completeness and accuracy of the provided steps and ensure that they include specific details on adding memory to the Crew in CrewAI, as well as specific examples and illustrations.
Thought: I need to verify if the provided steps are complete and include all necessary details, specific examples, and potential challenges. I will also ensure the response is friendly and professional.
Action: Ask question to co-worker
Action Input: {"coworker": "์๋์ด๊ธ ์ํฌํธ ๋ํ", "question": "Could you please review the provided steps for setting up a Crew and adding memory in CrewAI to ensure they are complete, accurate, and include specific details on how to add memory? Also, check if there are any potential challenges or limitations related to DeepLearningAI that should be addressed. Here is the context: \n\nHello Andrew,\n\nThank you for reaching out! I'd be happy to guide you through setting up a Crew and adding memory to it in CrewAI. Below are the detailed steps to help you get started:\n\n### Setting Up a Crew and Adding Memory in CrewAI\n\n#### Step 0: Installation\nFirst, ensure you have CrewAI and the necessary packages installed. CrewAI is compatible with Python versions >=3.10 and <=3.13. You can install it using the following commands:\n```bash\npip install crewai\npip install 'crewai[tools]'\n```\n\n#### Step 1: Assemble Your Agents\nNext, you need to define your agents with specific roles, backstories, and capabilities like verbose mode and memory usage. Here's an example of creating two agents:\n```python\nimport os\nos.environ['SERPER_API_KEY'] = 'Your Key' # serper.dev API key\nos.environ['OPENAI_API_KEY'] = 'Your Key'\nfrom crewai import Agent\nfrom crewai_tools import SerperDevTool\n\nsearch_tool = SerperDevTool()\n\n# Creating a senior researcher agent with memory and verbose mode\nresearcher = Agent(\n role='Senior Researcher',\n goal='Uncover groundbreaking technologies in {topic}',\n verbose=True,\n memory=True,\n backstory=(\n 'Driven by curiosity, you\'re at the forefront of'\n 'innovation, eager to explore and share knowledge that could change'\n 'the world.'\n ),\n tools=[search_tool],\n allow_delegation=True\n)\n\n# Creating a writer agent with custom tools and delegation capability\nwriter = Agent(\n role='Writer',\n goal='Narrate compelling tech stories about {topic}',\n verbose=True,\n memory=True,\n backstory=(\n 'With a flair for simplifying complex topics, you craft'\n 'engaging narratives that captivate and educate, bringing new'\n 'discoveries to light in an accessible manner.'\n ),\n tools=[search_tool],\n allow_delegation=False\n)\n```\n\n#### Step 2: Define the Tasks\nDefine specific tasks for your agents, including details for asynchronous execution and output customization. Here are examples of tasks for the agents:\n```python\nfrom crewai import Task\n\n# Research task\nresearch_task = Task(\n description=(\n 'Identify the next big trend in {topic}. '\n 'Focus on identifying pros and cons and the overall narrative. '\n 'Your final report should clearly articulate the key points, '\n 'its market opportunities, and potential risks.'\n ),\n expected_output='A comprehensive 3 paragraphs long report on the latest AI trends.',\n tools=[search_tool],\n agent=researcher,\n)\n\n# Writing task with language model configuration\nwrite_task = Task(\n description=(\n 'Compose an insightful article on {topic}. '\n 'Focus on the latest trends and how it\'s impacting the industry. '\n 'This article should be easy to understand, engaging, and positive.'\n ),\n expected_output='A 4 paragraph article on {topic} advancements formatted as markdown.',\n tools=[search_tool],\n agent=writer,\n async_execution=False,\n output_file='new-blog-post.md' # Example of output customization\n)\n```\n\n#### Step 3: Form the Crew\nCombine your agents into a crew, setting the workflow process they will follow to accomplish the tasks. Here’s an example of forming a crew with memory:\n```python\nfrom crewai import Crew, Process\n\n# Forming the tech-focused crew with some enhanced configurations\ncrew = Crew(\n agents=[researcher, writer],\n tasks=[research_task, write_task],\n process=Process.sequential, # Optional: Sequential task execution is default\n memory=True,\n cache=True,\n max_rpm=100,\n share_crew=True\n)\n```\n\n#### Step 4: Kick It Off\nFinally, initiate the process with your enhanced crew ready. Here’s how you can start the task execution process:\n```python\n# Starting the task execution process with enhanced feedback\nresult = crew.kickoff(inputs={'topic': 'AI in healthcare'})\nprint(result)\n```\n\n### Conclusion\nBy following these steps, you will have successfully set up a Crew in CrewAI with memory capabilities. This setup allows your agents to remember context and previous interactions, improving their performance and collaboration.\n\nIf you have any further questions or need additional assistance, please don't hesitate to reach out. We're here to help!\n\nBest regards,\n[Your Name]\nCrewAI Support Representative"}
I encountered an error while trying to use the tool. This was the error: AgentTools.ask_question() missing 1 required positional argument: 'context'.
Tool Ask question to co-worker accepts these inputs: Ask question to co-worker(coworker: str, question: str, context: str) - Ask a specific question to one of the following co-workers: [์๋์ด๊ธ ์ํฌํธ ๋ํ, ๋ฒ์ญ๊ฐ]
The input to this tool should be the coworker, the question you have for them, and ALL necessary context to ask the question properly, they know nothing about the question, so share absolute everything you know, don't reference things but instead explain them.
Thought: I need to ensure that the response to Andrew is complete, accurate, and meets the high-quality standards expected by DeepLearningAI. I will address any potential challenges or limitations related to DeepLearningAI and include a friendly call-to-action. Since my previous attempt to ask a co-worker failed, I will delegate the task to ensure all necessary information is reviewed and enhanced if needed.
Action: Delegate work to co-worker
Action Input: {"coworker": "์๋์ด๊ธ ์ํฌํธ ๋ํ", "task": "Review the provided steps for setting up a Crew and adding memory in CrewAI to ensure they are complete, accurate, and include specific details on how to add memory. Also, check if there are any potential challenges or limitations related to DeepLearningAI that should be addressed.", "context": "Here is the context: \n\nHello Andrew,\n\nThank you for reaching out! I'd be happy to guide you through setting up a Crew and adding memory to it in CrewAI. Below are the detailed steps to help you get started:\n\n### Setting Up a Crew and Adding Memory in CrewAI\n\n#### Step 0: Installation\nFirst, ensure you have CrewAI and the necessary packages installed. CrewAI is compatible with Python versions >=3.10 and <=3.13. You can install it using the following commands:\n```bash\npip install crewai\npip install 'crewai[tools]'\n```\n\n#### Step 1: Assemble Your Agents\nNext, you need to define your agents with specific roles, backstories, and capabilities like verbose mode and memory usage. Here's an example of creating two agents:\n```python\nimport os\nos.environ['SERPER_API_KEY'] = 'Your Key' # serper.dev API key\nos.environ['OPENAI_API_KEY'] = 'Your Key'\nfrom crewai import Agent\nfrom crewai_tools import SerperDevTool\n\nsearch_tool = SerperDevTool()\n\n# Creating a senior researcher agent with memory and verbose mode\nresearcher = Agent(\n role='Senior Researcher',\n goal='Uncover groundbreaking technologies in {topic}',\n verbose=True,\n memory=True,\n backstory=(\n 'Driven by curiosity, you\'re at the forefront of'\n 'innovation, eager to explore and share knowledge that could change'\n 'the world.'\n ),\n tools=[search_tool],\n allow_delegation=True\n)\n\n# Creating a writer agent with custom tools and delegation capability\nwriter = Agent(\n role='Writer',\n goal='Narrate compelling tech stories about {topic}',\n verbose=True,\n memory=True,\n backstory=(\n 'With a flair for simplifying complex topics, you craft'\n 'engaging narratives that captivate and educate, bringing new'\n 'discoveries to light in an accessible manner.'\n ),\n tools=[search_tool],\n allow_delegation=False\n)\n```\n\n#### Step 2: Define the Tasks\nDefine specific tasks for your agents, including details for asynchronous execution and output customization. Here are examples of tasks for the agents:\n```python\nfrom crewai import Task\n\n# Research task\nresearch_task = Task(\n description=(\n 'Identify the next big trend in {topic}. '\n 'Focus on identifying pros and cons and the overall narrative. '\n 'Your final report should clearly articulate the key points, '\n 'its market opportunities, and potential risks.'\n ),\n expected_output='A comprehensive 3 paragraphs long report on the latest AI trends.',\n tools=[search_tool],\n agent=researcher,\n)\n\n# Writing task with language model configuration\nwrite_task = Task(\n description=(\n 'Compose an insightful article on {topic}. '\n 'Focus on the latest trends and how it\'s impacting the industry. '\n 'This article should be easy to understand, engaging, and positive.'\n ),\n expected_output='A 4 paragraph article on {topic} advancements formatted as markdown.',\n tools=[search_tool],\n agent=writer,\n async_execution=False,\n output_file='new-blog-post.md' # Example of output customization\n)\n```\n\n#### Step 3: Form the Crew\nCombine your agents into a crew, setting the workflow process they will follow to accomplish the tasks. Here’s an example of forming a crew with memory:\n```python\nfrom crewai import Crew, Process\n\n# Forming the tech-focused crew with some enhanced configurations\ncrew = Crew(\n agents=[researcher, writer],\n tasks=[research_task, write_task],\n process=Process.sequential, # Optional: Sequential task execution is default\n memory=True,\n cache=True,\n max_rpm=100,\n share_crew=True\n)\n```\n\n#### Step 4: Kick It Off\nFinally, initiate the process with your enhanced crew ready. Here’s how you can start the task execution process:\n```python\n# Starting the task execution process with enhanced feedback\nresult = crew.kickoff(inputs={'topic': 'AI in healthcare'})\nprint(result)\n```\n\n### Conclusion\nBy following these steps, you will have successfully set up a Crew in CrewAI with memory capabilities. This setup allows your agents to remember context and previous interactions, improving their performance and collaboration.\n\nIf you have any further questions or need additional assistance, please don't hesitate to reach out. We're here to help!\n\nBest regards,\n[Your Name]\nCrewAI Support Representative"}
gpt-4o ๋ต๋ณ
my best complete final answer to the task.
์๋ ํ์ธ์ Andrew๋,
๋ฌธ์ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค! CrewAI์์ ํฌ๋ฃจ๋ฅผ ์ค์ ํ๊ณ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ์ ์๋ดํด ๋๋ฆฌ๊ฒ ์ต๋๋ค. ์๋์ ์์ํ๋ ๋ฐ ๋์์ด ๋ ์์ธํ ๋จ๊ณ๋ค์ด ๋์ ์์ต๋๋ค.
CrewAI์์ ํฌ๋ฃจ ์ค์ ๋ฐ ๋ฉ๋ชจ๋ฆฌ ์ถ๊ฐ¶
0๋จ๊ณ: ์ค์น¶
๋จผ์ , CrewAI์ ํ์ํ ํจํค์ง๊ฐ ์ค์น๋์ด ์๋์ง ํ์ธํ์ธ์. CrewAI๋ Python ๋ฒ์ 3.10 ์ด์ 3.13 ์ดํ์ ํธํ๋ฉ๋๋ค. ๋ค์ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ ์ค์นํ ์ ์์ต๋๋ค:
pip install crewai
pip install 'crewai[tools]'
1๋จ๊ณ: ์์ด์ ํธ ๊ตฌ์ฑ¶
๋ค์์ผ๋ก, ํน์ ์ญํ , ๋ฐฐ๊ฒฝ ์ด์ผ๊ธฐ, ๊ธฐ๋ฅ(์: ์์ธํ ๋ชจ๋ ๋ฐ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ)์ ๊ฐ์ถ ์์ด์ ํธ๋ฅผ ์ ์ํด์ผ ํฉ๋๋ค. ๋ค์์ ๋ ๋ช ์ ์์ด์ ํธ๋ฅผ ๋ง๋๋ ์์ ์ ๋๋ค:
import os
os.environ['SERPER_API_KEY'] = 'Your Key' # serper.dev API ํค
os.environ['OPENAI_API_KEY'] = 'Your Key'
from crewai import Agent
from crewai_tools import SerperDevTool
search_tool = SerperDevTool()
# ๋ฉ๋ชจ๋ฆฌ์ ์์ธํ ๋ชจ๋๋ฅผ ๊ฐ์ถ ์ ์ ์ฐ๊ตฌ์ ์์ด์ ํธ ์์ฑ
researcher = Agent(
role='์ ์ ์ฐ๊ตฌ์',
goal='{topic}์์ ํ์ ์ ์ธ ๊ธฐ์ ์ ๋ฐ๊ฒฌํ๋ค',
verbose=True,
memory=True,
backstory=(
'ํธ๊ธฐ์ฌ์ด ๋ง์ ๋น์ ์ ํ์ ์ ์ ๋์ ์์ผ๋ฉฐ, ์ธ์์ ๋ฐ๊ฟ ์ ์๋ '
'์ง์์ ํ๊ตฌํ๊ณ ๊ณต์ ํ๊ธฐ๋ฅผ ์ด๋งํฉ๋๋ค.'
),
tools=[search_tool],
allow_delegation=True
)
# ๋ง์ถคํ ๋๊ตฌ์ ์์ ๊ธฐ๋ฅ์ ๊ฐ์ถ ์๊ฐ ์์ด์ ํธ ์์ฑ
writer = Agent(
role='์๊ฐ',
goal='{topic}์ ๋ํ ๋งค๋ ฅ์ ์ธ ๊ธฐ์ ์ด์ผ๊ธฐ๋ฅผ ์์ ํ๋ค',
verbose=True,
memory=True,
backstory=(
'๋ณต์กํ ์ฃผ์ ๋ฅผ ๊ฐ๋จํ๊ฒ ๋ง๋๋ ์ฌ๋ฅ์ ๊ฐ์ง ๋น์ ์ '
'์๋ก์ด ๋ฐ๊ฒฌ์ ์ฝ๊ฒ ์ ๊ทผํ ์ ์๊ฒ ๋ง๋ค์ด ์ฃผ๋ ๋งค๋ ฅ์ ์ด๊ณ ๊ต์ก์ ์ธ '
'์์ฌ๋ฅผ ์์ฑํฉ๋๋ค.'
),
tools=[search_tool],
allow_delegation=False
)
2๋จ๊ณ: ์์ ์ ์¶
์์ด์ ํธ๋ฅผ ์ํ ํน์ ์์ ์ ์ ์ํ๊ณ ๋น๋๊ธฐ ์คํ ๋ฐ ์ถ๋ ฅ ๋ง์ถคํ์ ๋ํ ์ธ๋ถ ์ ๋ณด๋ฅผ ํฌํจํฉ๋๋ค. ๋ค์์ ์์ด์ ํธ๋ฅผ ์ํ ์์ ์์์ ๋๋ค:
from crewai import Task
# ์ฐ๊ตฌ ์์
research_task = Task(
description=(
'{topic}์ ๋ค์ ํฐ ํธ๋ ๋๋ฅผ ์๋ณํ์ญ์์ค. '
'์ฅ์ ๊ณผ ๋จ์ , ์ ์ฒด ๋ด๋ฌํฐ๋ธ๋ฅผ ์๋ณํ๋ ๋ฐ ์ค์ ์ ๋ก๋๋ค. '
'์ต์ข
๋ณด๊ณ ์๋ ์ฃผ์ ์ฌํญ, ์์ฅ ๊ธฐํ ๋ฐ ์ ์ฌ์ ์ํ์ ๋ช
ํํ '
'์ค๋ช
ํด์ผ ํฉ๋๋ค.'
),
expected_output='์ต์ AI ํธ๋ ๋์ ๋ํ ์ข
ํฉ์ ์ธ 3๋จ๋ฝ ๋ณด๊ณ ์.',
tools=[search_tool],
agent=researcher,
)
# ์ธ์ด ๋ชจ๋ธ ๊ตฌ์ฑ์ด ํฌํจ๋ ์์ฑ ์์
write_task = Task(
description=(
'{topic}์ ๋ํ ํต์ฐฐ๋ ฅ ์๋ ๊ธฐ์ฌ๋ฅผ ์์ฑํ์ญ์์ค. '
'์ต์ ํธ๋ ๋์ ์ฐ์
์ ๋ฏธ์น๋ ์ํฅ์ ์ค์ ์ผ๋ก ๋ค๋ฃน๋๋ค. '
'์ด ๊ธฐ์ฌ๋ ์ดํดํ๊ธฐ ์ฝ๊ณ ๋งค๋ ฅ์ ์ด๋ฉฐ ๊ธ์ ์ ์ธ ํค์ผ๋ก ์์ฑ๋์ด์ผ ํฉ๋๋ค.'
),
expected_output='{topic} ๋ฐ์ ์ ๋ํ 4๋จ๋ฝ ๊ธฐ์ฌ, ๋งํฌ๋ค์ด ํ์.',
tools=[search_tool],
agent=writer,
async_execution=False,
output_file='new-blog-post.md' # ์ถ๋ ฅ ๋ง์ถคํ ์์
)
3๋จ๊ณ: ํฌ๋ฃจ ๊ตฌ์ฑ¶
์์ด์ ํธ๋ฅผ ํฌ๋ฃจ์ ๊ฒฐํฉํ๊ณ ์์ ์ ์ํํ๊ธฐ ์ํ ์ํฌํ๋ก์ฐ ํ๋ก์ธ์ค๋ฅผ ์ค์ ํฉ๋๋ค. ๋ค์์ ๋ฉ๋ชจ๋ฆฌ๊ฐ ์๋ ํฌ๋ฃจ๋ฅผ ๊ตฌ์ฑํ๋ ์์ ์ ๋๋ค:
from crewai import Crew, Process
# ๊ธฐ์ ์ค์ฌ์ ํฌ๋ฃจ ๊ตฌ์ฑ๊ณผ ์ผ๋ถ ํฅ์๋ ๊ตฌ์ฑ
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential, # ์ ํ ์ฌํญ: ์์ฐจ ์์
์คํ์ด ๊ธฐ๋ณธ๊ฐ
memory=True,
cache=True,
max_rpm=100,
share_crew=True
)
4๋จ๊ณ: ์์ํ๊ธฐ¶
๋ง์ง๋ง์ผ๋ก, ํฅ์๋ ํฌ๋ฃจ๊ฐ ์ค๋น๋๋ฉด ํ๋ก์ธ์ค๋ฅผ ์์ํฉ๋๋ค. ๋ค์์ ์์ ์คํ ํ๋ก์ธ์ค๋ฅผ ์์ํ๋ ๋ฐฉ๋ฒ์ ๋๋ค:
# ํฅ์๋ ํผ๋๋ฐฑ๊ณผ ํจ๊ป ์์
์คํ ํ๋ก์ธ์ค ์์
result = crew.kickoff(inputs={'topic': 'AI in healthcare'})
print(result)
๊ฒฐ๋ก ¶
์ด ๋จ๊ณ๋ฅผ ๋ฐ๋ฅด๋ฉด ๋ฉ๋ชจ๋ฆฌ ๊ธฐ๋ฅ์ด ์๋ CrewAI์์ ํฌ๋ฃจ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ์ค์ ํ ์ ์์ต๋๋ค. ์ด ์ค์ ์ ์์ด์ ํธ๊ฐ ์ปจํ ์คํธ์ ์ด์ ์ํธ์์ฉ์ ๊ธฐ์ตํ ์ ์๊ฒ ํ์ฌ ์ฑ๋ฅ๊ณผ ํ์ ์ ํฅ์์ํต๋๋ค.
์ถ๊ฐ ์ง๋ฌธ์ด๋ ๋์์ด ํ์ํ๋ฉด ์ธ์ ๋ ์ง ๋ฌธ์ํด ์ฃผ์ธ์. ์ ํฌ๊ฐ ๋์๋๋ฆฌ๊ฒ ์ต๋๋ค!
๊ฐ์ฌํฉ๋๋ค,
[Your Name]
CrewAI ์ง์ ๋ด๋น์
์ด๋ฌํ ๋จ๊ณ๊ฐ ๋ช ํํ๊ณ ์์ธํ๋ฉฐ ์์๋ก ๋ท๋ฐ์นจ๋์ด ์์ด, DeepLearningAI์ ๋์ ํ์ง ๊ธฐ์ค์ ์ถฉ์กฑํ ๊ฒ์ด๋ผ ํ์ ํฉ๋๋ค.
gpt-3.5-turbo ๋ต๋ณ
๋ ๋ต๋ณ์ ์ฐจ์ด๋ฅผ ๋ณด๋ฉด ํ๊ธ system prompt๋ฅผ ๋ ์ ์ดํดํ ๊ฒ์ 4o๋ก ์ต๊ทผ์ ๋์จ ๋ชจ๋ธ์ธ๋งํผ instruction์ด ์๋์ด crewAI์ document๋ฅผ ์ ์ฐพ์์ ์์ ๊น์ง ๋ณด์ฌ์ฃผ๋ ๋๋ผ์์ ๋ณด์ฌ ์ฃผ์๋ค. ํ์ง๋ง 3.5-turbo๋ ์์ฝ๊ฒ๋ prompt๋ฅผ ์ ์ดํดํ์ง ๋ชปํ๊ณ ๋ต๋ณ์์ instruction์ ๊ทธ๋๋ก ๋ณด์ฌ์ฃผ์๋ค. ํ์ง๋ง 3.5-turbo๋ ์์ง๊น์ง๋ 4o๋ณด๋ค ๋ ์ ๋ ดํ๊ธฐ ๋๋ฌธ์ ๊ฐ๋จํ ์์ ์ ๋ง์ด ์ฌ์ฉํ ์ ์์ ๊ฒ์ผ๋ก ๋ณด์ธ๋ค.
์ deeplearning AI์ crewAI ์์ ๋ฅผ ํตํด RAG์ multi-agent๋ฅผ ํตํด prompt์ ํ๋ฆฌํฐ๋ฅผ ๋์ผ ์ ์๋ ๋ฐฉ๋ฒ์ ์์ ๋ณด์๋ค.
4o์ ๋ต๋ณ์ด ๊ธฐ๋ ์ด์์ด๊ณ ์ด๋ฒ์ ๊ฐ์ ๋ ํ ํฌ๋์ด์ ๋ ๊ธฐ์กด ํ๊ธ ๋๋น 1.7๋ฐฐ๋ ์๋ ์ ์์ด ๋ง์ด ์ฌ์ฉ๋ ๊ฒ์ผ๋ก ๋ณด์ธ๋ค.
'๐ ๏ธ Tools' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[OpenAI] ๋ชจ๋ธ๋ณ ์ง์ ์ค๋จ ์์ ๋ ์ง, Model deprecations (0) | 2024.06.15 |
---|---|
[draw.io] sql๋ฌธ ๊ฐ์ ธ์ค๊ธฐ (0) | 2024.06.03 |
[CrewAI] Key elements of AI agent (2) (0) | 2024.05.21 |
[LLM Agents] Multi AI Agent System with crewAI (0) | 2024.05.19 |
[Github] Github PR(pull request) template ๋ง๋ค์ด ์ฃผ๋ ์ฌ์ดํธ (0) | 2024.03.05 |