# 3.1 Your First CrewAI Agent [![GitHub](https://img.shields.io/badge/GitHub-%23121011.svg?logo=github&logoColor=white&label=55dcee6)](https://github.com/jongphago/ai_agent_master_class/commit/55dcee673150e95f8a2d46fbc9a90c31b611a515) ## 목차 (Table of Contents) - [3.1 Your First CrewAI Agent ](#31-your-first-crewai-agent-) - [3.2 Custom Tools](#32-custom-tools) - [3.3 News Reader Tasks and Agents](#33-news-reader-tasks-and-agents) - [3.4 News Reader Crew](#34-news-reader-crew) ## 용어 - Agents - Tasks - Crews ### 3.1.1 Agents CrewAI 프레임워크에서 Agent는 다음을 수행할 수 있는 자율적인 단위입니다. - 특정 작업(`tasks`) 수행합니다. - 역할(`role`)과 목표(goal)에 따라 결정을 내립니다. - 도구(`tools`)를 사용하여 목표를 달성합니다. - 다른 에이전트(`agents`)와 소통하고 협업합니다. - 상호작용의 기억(`memory`)을 유지합니다. - 허용된 경우 작업(`tasks`)을 위임합니다. ### 3.1.2 Tasks ### 3.1.3 Crews ## crewai 실행 구조 - `stdout` <div align="center"> <img src="images/image.png" alt="crewai execution structure" height="520px"> </div> ## crewai 실행 구조 - 도식화 <div align="center"> <img src="images/code_structure.png" alt="crewai execution structure" height="520px"> </div> ## config 파일 설정 - 클래스의 매개변수를 설정 파일을 통해 지정 - `config/agents.yaml` - role: 에이전트의 역할 - goal: 에이전트의 목표 - backstory: 에이전트의 배경 - `config/tasks.yaml` - description: 작업의 설명 - expected_output: 예상 출력 - agent: 작업을 수행할 에이전트 # 3.2 Custom Tools ## 3.2.1 Custom Tools 정의 - 매개변수 타입 지정 - 함수 정의 (doc-string) ```python from crewai.tools import tool @tool def counter_letters(sentence: str) : """ 이 함수는 매개변수로 주어지는 sentence의 문자 개수를 반환하는 함수입니다. sentence의 자료형은 str 입니다. 출력 형식은 int 입니다. """ print(f"tool called with sentence: {sentence}") return len(sentence) ``` ## task에 custom tools 사용 ```python from tools import counter_letters @CrewBase class TranslaotrCrew: ... @task def counter_task(self): return Task( config=self.tasks_config["counter_task"], tools = [counter_letters], ) ``` # 3.3 News Reader Tasks and Agents ## 3.3.1 Task config 속성 ```yaml researcher: role: Research Specialist goal: Conduct comprehensive research and analysis backstory: A dedicated research professional with years of experience verbose: true llm: provider/model-id # e.g. openai/gpt-4o, google/gemini-2.0-flash, anthropic/claude... # (see provider configuration examples below for more) ``` # 3.4 News Reader Crew ## 의존성 ```bash playwright install ``` ## sample code ```python from crewai_tools import SerperDevTool # Initialize the tool for internet searching capabilities search_tool = SerperDevTool() print(search_tool.run(search_query="민생회복 소비쿠폰")) ``` ## task간 입출력 Agent 클래스 정의 순서에 따라 입출력이 연결