Patronus AI 평가

Patronus AI 평가 (Patronus AI Evaluation)

Patronus AI는 CrewAI 에이전트를 위한 종합적인 평가·모니터링 기능을 제공해서, 모델 출력, 에이전트 동작, 전반적인 시스템 성능을 평가할 수 있게 해 줘요. 이 통합을 통해 프로덕션 환경에서 품질과 신뢰성을 유지하는 데 도움이 되는 지속적 평가 워크플로우를 구현할 수 있어요.

출처: 문서

본문

Overview (개요)

Patronus AI는 CrewAI 에이전트를 위한 종합적인 평가·모니터링 기능을 제공해 모델 출력, 에이전트 동작, 전반적인 시스템 성능을 평가할 수 있게 해 줘요. 이 통합으로 프로덕션 환경의 품질과 신뢰성을 유지하는 데 도움이 되는 지속적 평가 워크플로우를 구현할 수 있어요.

Key Features (주요 기능)

  • Automated Evaluation — 에이전트 출력과 동작의 실시간 평가.
  • Custom Criteria — 사용 사례에 맞춘 특정 평가 기준 정의.
  • Performance Monitoring — 시간에 따른 에이전트 성능 메트릭 추적.
  • Quality Assurance — 다양한 시나리오에서 일관된 출력 품질 보장.
  • Safety & Compliance — 잠재적 문제와 정책 위반 모니터링.

Evaluation Tools (평가 툴)

Patronus는 다양한 사용 사례를 위한 세 가지 주요 평가 툴을 제공해요:

  • PatronusEvalTool — 에이전트가 평가 태스크에 가장 적합한 evaluator와 기준을 선택할 수 있게 해 줘요.
  • PatronusPredefinedCriteriaEvalTool — 사용자가 지정한 사전 정의된 evaluator와 기준을 사용해요.
  • PatronusLocalEvaluatorTool — 사용자가 정의한 커스텀 함수 evaluator를 사용해요.

Installation (설치)

이 툴들을 사용하려면 Patronus 패키지를 설치해야 해요:

uv add patronus

또한 Patronus API key를 환경 변수로 설정해야 해요:

export PATRONUS_API_KEY="your_patronus_api_key"

Steps to Get Started (시작 단계)

Patronus 평가 툴을 효과적으로 사용하려면 다음 단계를 따르세요:

  • Install Patronus — 위 명령으로 Patronus 패키지를 설치하세요.
  • Set Up API Key — Patronus API key를 환경 변수로 설정하세요.
  • Choose the Right Tool — 필요에 맞는 적절한 Patronus 평가 툴을 선택하세요.
  • Configure the Tool — 필요한 파라미터로 툴을 구성하세요.

Examples (예시)

Using PatronusEvalTool

다음 예시는 에이전트가 가장 적합한 evaluator와 기준을 선택하도록 하는 PatronusEvalTool 사용법을 보여줘요:

from crewai import Agent, Task, Crew
from crewai_tools import PatronusEvalTool

# Initialize the tool
patronus_eval_tool = PatronusEvalTool()

# Define an agent that uses the tool
coding_agent = Agent(
    role="Coding Agent",
    goal="Generate high quality code and verify that the output is code",
    backstory="An experienced coder who can generate high quality python code.",
    tools=[patronus_eval_tool],
    verbose=True,
)

# Example task to generate and evaluate code
generate_code_task = Task(
    description="Create a simple program to generate the first N numbers in the Fibonacci sequence. Select the most appropriate evaluator and criteria for evaluating your output.",
    expected_output="Program that generates the first N numbers in the Fibonacci sequence.",
    agent=coding_agent,
)

# Create and run the crew
crew = Crew(agents=[coding_agent], tasks=[generate_code_task])
result = crew.kickoff()

Using PatronusPredefinedCriteriaEvalTool

다음 예시는 사전 정의된 evaluator와 기준을 사용하는 PatronusPredefinedCriteriaEvalTool 사용법을 보여줘요:

from crewai import Agent, Task, Crew
from crewai_tools import PatronusPredefinedCriteriaEvalTool

# Initialize the tool with predefined criteria
patronus_eval_tool = PatronusPredefinedCriteriaEvalTool(
    evaluators=[{"evaluator": "judge", "criteria": "contains-code"}]
)

# Define an agent that uses the tool
coding_agent = Agent(
    role="Coding Agent",
    goal="Generate high quality code",
    backstory="An experienced coder who can generate high quality python code.",
    tools=[patronus_eval_tool],
    verbose=True,
)

# Example task to generate code
generate_code_task = Task(
    description="Create a simple program to generate the first N numbers in the Fibonacci sequence.",
    expected_output="Program that generates the first N numbers in the Fibonacci sequence.",
    agent=coding_agent,
)

# Create and run the crew
crew = Crew(agents=[coding_agent], tasks=[generate_code_task])
result = crew.kickoff()

Using PatronusLocalEvaluatorTool

다음 예시는 커스텀 함수 evaluator를 사용하는 PatronusLocalEvaluatorTool 사용법을 보여줘요:

from crewai import Agent, Task, Crew
from crewai_tools import PatronusLocalEvaluatorTool
from patronus import Client, EvaluationResult
import random

# Initialize the Patronus client
client = Client()

# Register a custom evaluator
@client.register_local_evaluator("random_evaluator")
def random_evaluator(**kwargs):
    score = random.random()
    return EvaluationResult(
        score_raw=score,
        pass_=score >= 0.5,
        explanation="example explanation",
    )

# Initialize the tool with the custom evaluator
patronus_eval_tool = PatronusLocalEvaluatorTool(
    patronus_client=client,
    evaluator="random_evaluator",
    evaluated_model_gold_answer="example label",
)

# Define an agent that uses the tool
coding_agent = Agent(
    role="Coding Agent",
    goal="Generate high quality code",
    backstory="An experienced coder who can generate high quality python code.",
    tools=[patronus_eval_tool],
    verbose=True,
)

# Example task to generate code
generate_code_task = Task(
    description="Create a simple program to generate the first N numbers in the Fibonacci sequence.",
    expected_output="Program that generates the first N numbers in the Fibonacci sequence.",
    agent=coding_agent,
)

# Create and run the crew
crew = Crew(agents=[coding_agent], tasks=[generate_code_task])
result = crew.kickoff()

Parameters (파라미터)

PatronusEvalTool

PatronusEvalTool은 초기화 시 파라미터를 필요로 하지 않아요. Patronus API에서 사용 가능한 evaluator와 기준을 자동으로 가져와요.

PatronusPredefinedCriteriaEvalTool

PatronusPredefinedCriteriaEvalTool은 초기화 시 다음 파라미터를 받아요:

  • evaluators : 필수. 사용할 evaluator와 기준을 담은 딕셔너리 목록. 예: [{"evaluator": "judge", "criteria": "contains-code"}].

PatronusLocalEvaluatorTool

PatronusLocalEvaluatorTool은 초기화 시 다음 파라미터를 받아요:

  • patronus_client : 필수. Patronus 클라이언트 인스턴스.
  • evaluator : 선택. 사용할 등록된 로컬 evaluator의 이름. 기본값은 빈 문자열.
  • evaluated_model_gold_answer : 선택. 평가에 사용할 gold answer. 기본값은 빈 문자열.

Usage (사용법)

Patronus 평가 툴을 사용할 때 모델 입력, 출력, 컨텍스트를 제공하면 툴이 Patronus API에서 평가 결과를 반환해요.

PatronusEvalTool과 PatronusPredefinedCriteriaEvalTool의 경우, 툴을 호출할 때 다음 파라미터가 필요해요:

  • evaluated_model_input — 에이전트의 태스크 설명을 일반 텍스트로.
  • evaluated_model_output — 태스크에 대한 에이전트의 출력.
  • evaluated_model_retrieved_context — 에이전트의 컨텍스트.

PatronusLocalEvaluatorTool의 경우 같은 파라미터가 필요하지만, evaluator와 gold answer는 초기화 시 지정해요.

Conclusion (결론)

Patronus 평가 툴은 Patronus AI 플랫폼을 사용해 모델 입력과 출력을 평가·점수화할 수 있는 강력한 방법을 제공해요. 에이전트가 자신의 출력이나 다른 에이전트의 출력을 평가할 수 있게 함으로써, 이 툴들은 CrewAI 워크플로우의 품질과 신뢰성을 향상시키는 데 도움이 돼요.

더 알아보기 (Learn more)