에이전트 리즈닝: 실행 전 계획 세우기

에이전트 리즈닝: 실행 전 계획 세우기

에이전트가 복잡한 태스크를 받자마자 시작하지 않고, 먼저 태스크를 되새기며 계획을 세우고 그 계획을 태스크 설명에 주입하도록 만들 수 있어요. CrewAI의 리즈닝(Reasoning) 기능은 에이전트에 reasoning=True만 켜면 실행 전 반성→계획→준비 판단→계획 주입 과정을 자동으로 수행하게 합니다. 시도 횟수는 max_reasoning_attempts로 제한할 수 있어요.

출처: 공식문서

본문

개요

에이전트 리즈닝은 에이전트가 실행 전에 태스크를 반성하고 계획을 만들 수 있게 하는 기능입니다. 이는 에이전트가 태스크에 더 체계적으로 접근하고 할당된 작업을 수행할 준비가 되도록 보장합니다.

사용법

에이전트에 리즈닝을 활성화하려면 생성 시 reasoning=True로 설정하기만 하면 됩니다:

from crewai import Agent

agent = Agent(
    role="Data Analyst",
    goal="Analyze complex datasets and provide insights",
    backstory="You are an experienced data analyst with expertise in finding patterns in complex data.",
    reasoning=True,  # Enable reasoning
    max_reasoning_attempts=3  # Optional: Set a maximum number of reasoning attempts
)

동작 방식

리즈닝이 활성화되면 태스크 실행 전에 에이전트는 다음을 수행합니다:

  1. 태스크를 반성하고 상세한 계획을 생성
  2. 태스크를 실행할 준비가 되었는지 평가
  3. 준비되거나 max_reasoning_attempts에 도달할 때까지 필요에 따라 계획을 정제
  4. 실행 전에 리즈닝 계획을 태스크 설명에 주입

이 과정은 에이전트가 복잡한 태스크를 관리 가능한 단계로 분해하고 시작 전에 잠재적 문제를 식별하도록 돕습니다.

구성 옵션

  • reasoning (bool, 기본 False): 리즈닝 활성화/비활성화.
  • max_reasoning_attempts (int, 기본 None): 실행을 진행하기 전 계획을 정제할 최대 시도 횟수. None(기본)이면 준비될 때까지 계속 정제.

예시

from crewai import Agent, Task, Crew

# Create an agent with reasoning enabled
analyst = Agent(
    role="Data Analyst",
    goal="Analyze data and provide insights",
    backstory="You are an expert data analyst.",
    reasoning=True,
    max_reasoning_attempts=3  # Optional: Set a limit on reasoning attempts
)

# Create a task
analysis_task = Task(
    description="Analyze the provided sales data and identify key trends.",
    expected_output="A report highlighting the top 3 sales trends.",
    agent=analyst
)

# Create a crew and run the task
crew = Crew(agents=[analyst], tasks=[analysis_task])
result = crew.kickoff()

print(result)

오류 처리

리즈닝 과정은 내장된 오류 처리로 견고하게 설계되었습니다. 리즈닝 중 오류가 발생하면 에이전트는 리즈닝 계획 없이 태스크 실행을 진행합니다. 이렇게 해서 리즈닝 과정이 실패해도 태스크는 계속 실행될 수 있습니다.

from crewai import Agent, Task
import logging

# Set up logging to capture any reasoning errors
logging.basicConfig(level=logging.INFO)

# Create an agent with reasoning enabled
agent = Agent(
    role="Data Analyst",
    goal="Analyze data and provide insights",
    reasoning=True,
    max_reasoning_attempts=3
)

# Create a task
task = Task(
    description="Analyze the provided sales data and identify key trends.",
    expected_output="A report highlighting the top 3 sales trends.",
    agent=agent
)

# Execute the task
# If an error occurs during reasoning, it will be logged and execution will continue
result = agent.execute_task(task)

리즈닝 출력 예시

데이터 분석 태스크의 리즈닝 계획 예시:

Task: Analyze the provided sales data and identify key trends.

Reasoning Plan:
I'll analyze the sales data to identify the top 3 trends.

1. Understanding of the task:
   I need to analyze sales data to identify key trends that would be valuable for business decision-making.

2. Key steps I'll take:
   - First, I'll examine the data structure to understand what fields are available
   - Then I'll perform exploratory data analysis to identify patterns
   - Next, I'll analyze sales by time periods to identify temporal trends
   - I'll also analyze sales by product categories and customer segments
   - Finally, I'll identify the top 3 most significant trends

3. Approach to challenges:
   - If the data has missing values, I'll decide whether to fill or filter them
   - If the data has outliers, I'll investigate whether they're valid data points or errors
   - If trends aren't immediately obvious, I'll apply statistical methods to uncover patterns

4. Use of available tools:
   - I'll use data analysis tools to explore and visualize the data
   - I'll use statistical tools to identify significant patterns
   - I'll use knowledge retrieval to access relevant information about sales analysis

5. Expected outcome:
   A concise report highlighting the top 3 sales trends with supporting evidence from the data.

READY: I am ready to execute the task.

이 리즈닝 계획은 에이전트가 태스크에 대한 접근을 조직하고, 잠재적 문제를 고려하며, 기대 출력을 전달하도록 돕습니다.

더 알아보기