• AI agent frameworks
    DEV 2024. 11. 16. 09:24

    사진: Unsplash 의 Ben Lambert

    이전글 - AI agent, CoT, ReAct에 대한 설명

    2024.11.15 - [DEV] - AI Agent concept

     

    AI Agent concept

    AgentAI agent workflow가 올해 엄청난 AI 진전을 이끌 것이라고 생각합니다. 아마도 차세대 기초 모델보다 더 큰 진전이 있을 것입니다.-앤드류 응(Andrew Ng)기업의 대부분(82%)이 1~3년 내에

    developer-as-job.tistory.com

     

    AI agent frameworks

    다양한 AI agent framework들이 존재

    LangChain(LangGraph), LLamaIndex, AutoGen, crewAI, Transformers Agent....

    crewAI

    https://www.crewai.com/

    crewAI에 대해 학습 가능한 deeplearning AI short course

    https://www.deeplearning.ai/short-courses/multi-ai-agent-systems-with-crewai/

     

    Multi AI Agent Systems with crewAI

    Learn key principles of designing effective AI agents, and organizing a team of AI agents to perform complex, multi-step tasks.

    www.deeplearning.ai

    CrewAI의 에이전트는 LangChain으로 코딩된 ReAct 에이전트

    crewAI reAct

     

    작업을 완료했다고 생각할 때까지 루프에서 CoT 프롬프트를 수행.

    Thought, Action, Observation 할 때마다 = money

    아무튼 개발자가 해야 하는 일은 Agent를 만들고, agent가 수행할 Task 생성, agent가 사용할 수 있는 Tool을 생성, Process를 생성

    crewAI의 높은 추상화위에 위 component들을 작업하지만 내부적으론 reAct 기반으로 동작

     

    crewAI 구조

     

    Task

     - agent가 수행할 작업, 각 작업은 agent에게 할당

    Agent

     - 특정업무를 수행할 AI agent, 각 agent는 다른 작업의 전문가

    Tool

     - agent가 작업을 수행할 때 사용하는 도구

     - 검색엔진, 번역, 계산...

    process

     - 에이전트가 함께 작업하는 방식지시

     - 순차적, 병렬적, 관리자 agent가 일반 agent를 할당

    Example

    여행 계획 agent

    https://github.com/crewAIInc/crewAI-examples/tree/main/trip_planner

     

    여행계획 agent 생성

    class TripAgents():
    
      def city_selection_agent(self):
        return Agent(
            role='City Selection Expert',
            goal='Select the best city based on weather, season, and prices',
            backstory=
            'An expert in analyzing travel data to pick ideal destinations',
            tools=[
                SearchTools.search_internet,
                BrowserTools.scrape_and_summarize_website,
            ],
            verbose=True)
    
      def local_expert(self):
        return Agent(
            role='Local Expert at this city',
            goal='Provide the BEST insights about the selected city',
            backstory="""A knowledgeable local guide with extensive information
            about the city, it's attractions and customs""",
            tools=[
                SearchTools.search_internet,
                BrowserTools.scrape_and_summarize_website,
            ],
            verbose=True)
    
      def travel_concierge(self):
        return Agent(
            role='Amazing Travel Concierge',
            goal="""Create the most amazing travel itineraries with budget and 
            packing suggestions for the city""",
            backstory="""Specialist in travel planning and logistics with 
            decades of experience""",
            tools=[
                SearchTools.search_internet,
                BrowserTools.scrape_and_summarize_website,
                CalculatorTools.calculate,
            ],
            verbose=True)

     

    여행계획시 실행할 task설정

    class TripTasks:
    
        def identify_task(self, agent, origin, cities, interests, range):
            return Task(
                description=dedent(f"""
                    Analyze and select the best city for the trip based 
                    on specific criteria such as weather patterns, seasonal
                    events, and travel costs. This task involves comparing
                    multiple cities, considering factors like current weather
                    conditions, upcoming cultural or seasonal events, and
                    overall travel expenses. 
                    
                    Your final answer must be a detailed
                    report on the chosen city, and everything you found out
                    about it, including the actual flight costs, weather 
                    forecast and attractions.
                    {self.__tip_section()}
    
                    Traveling from: {origin}
                    City Options: {cities}
                    Trip Date: {range}
                    Traveler Interests: {interests}
                """),
                agent=agent,
                expected_output="Detailed report on the chosen city including flight costs, weather forecast, and attractions"
            )
    
        def gather_task(self, agent, origin, interests, range):
            return Task(
                description=dedent(f"""
                    As a local expert on this city you must compile an 
                    in-depth guide for someone traveling there and wanting 
                    to have THE BEST trip ever!
                    Gather information about key attractions, local customs,
                    special events, and daily activity recommendations.
                    Find the best spots to go to, the kind of place only a
                    local would know.
                    This guide should provide a thorough overview of what 
                    the city has to offer, including hidden gems, cultural
                    hotspots, must-visit landmarks, weather forecasts, and
                    high level costs.
                    
                    The final answer must be a comprehensive city guide, 
                    rich in cultural insights and practical tips, 
                    tailored to enhance the travel experience.
                    {self.__tip_section()}
    
                    Trip Date: {range}
                    Traveling from: {origin}
                    Traveler Interests: {interests}
                """),
                agent=agent,
                expected_output="Comprehensive city guide including hidden gems, cultural hotspots, and practical travel tips"
            )
    
        def plan_task(self, agent, origin, interests, range):
            return Task(
                description=dedent(f"""
                    Expand this guide into a full 7-day travel 
                    itinerary with detailed per-day plans, including 
                    weather forecasts, places to eat, packing suggestions, 
                    and a budget breakdown.
                    
                    You MUST suggest actual places to visit, actual hotels 
                    to stay and actual restaurants to go to.
                    
                    This itinerary should cover all aspects of the trip, 
                    from arrival to departure, integrating the city guide
                    information with practical travel logistics.
                    
                    Your final answer MUST be a complete expanded travel plan,
                    formatted as markdown, encompassing a daily schedule,
                    anticipated weather conditions, recommended clothing and
                    items to pack, and a detailed budget, ensuring THE BEST
                    TRIP EVER. Be specific and give it a reason why you picked
                    each place, what makes them special! {self.__tip_section()}
    
                    Trip Date: {range}
                    Traveling from: {origin}
                    Traveler Interests: {interests}
                """),
                agent=agent,
                expected_output="Complete expanded travel plan with daily schedule, weather conditions, packing suggestions, and budget breakdown"
            )

     

    생성한 agent, task 연결하여 crew.kickoff

    agents = TripAgents()
        tasks = TripTasks()
    
        city_selector_agent = agents.city_selection_agent()
        local_expert_agent = agents.local_expert()
        travel_concierge_agent = agents.travel_concierge()
    
        identify_task = tasks.identify_task(
          city_selector_agent,
          self.origin,
          self.cities,
          self.interests,
          self.date_range
        )
        gather_task = tasks.gather_task(
          local_expert_agent,
          self.origin,
          self.interests,
          self.date_range
        )
        plan_task = tasks.plan_task(
          travel_concierge_agent, 
          self.origin,
          self.interests,
          self.date_range
        )
    
        crew = Crew(
          agents=[
            city_selector_agent, local_expert_agent, travel_concierge_agent
          ],
          tasks=[identify_task, gather_task, plan_task],
          verbose=True
        )
    
        result = crew.kickoff()
        return result

     

    genspark의 sparkpages와 비슷한 결과 생성

    https://www.genspark.ai/travel

    genspark travel page

    genspark의 sparkpages나 perplexity의 발견하기도 이런 방식으로 만들지 않았을까 싶고, 비슷하게 만들어 볼 수 있을 것 같다.
    query time에 생성하면 시간, 비용이 너무 크고, batch time에 문서를 만들어 두고 제공하는 방식이 되어야 할 것 같고, 위 서비스들도 그렇게 하는 것으로 보임

    genspark 우상단 'sparkpage 생성'을 클릭해보면 주제를 입력하면 실시간으로 주제 관련된 문서를 작성

     

    sparkpage 생성

     

    생성하는데 꽤 오래 걸림

    생성된 품질 좋은 페이지의 엔티티를 지식그래프로 연결하거나 벡터디비에 넣고 생성형 검색, 일반 검색의 소스로 사용해도 좋을 듯
    만약 생성된 문서를 서비스 하려면 문서의 품질을 평가 할 수 있는 기능도 필요해보인다.

     

    728x90

    'DEV' 카테고리의 다른 글

    프로젝트 관리에 도움 되는 가이드라인  (0) 2024.11.19
    class에 단일 책임이 있는지 판단하는 방법  (0) 2024.11.18
    AI Agent concept  (3) 2024.11.15
    Multimodal RAG  (2) 2024.11.14
    ETL, ECL and vector DB  (0) 2024.11.13
go.