멀티모달 에이전트

멀티모달 에이전트 (Multimodal Agents)

텍스트뿐 아니라 이미지 같은 비텍스트 콘텐츠도 처리해야 하는 태스크가 있다면, CrewAI의 멀티모달 에이전트가 답이에요. 에이전트를 만들 때 multimodal=True만 켜면 이미지 처리용 도구(AddImageTool)가 자동으로 붙어서, URL이나 로컬 경로의 이미지를 분석하고 설명을 내놓게 돼요.

출처: 공식문서

본문

멀티모달 기능 활성화

멀티모달 에이전트를 만들려면 에이전트를 초기화할 때 multimodal 파라미터를 True로 설정하면 돼요.

from crewai import Agent

agent = Agent(
    role="Image Analyst",
    goal="Analyze and extract insights from images",
    backstory="An expert in visual content interpretation with years of experience in image analysis",
    multimodal=True  # This enables multimodal capabilities
)

multimodal=True로 설정하면 에이전트는 AddImageTool을 포함한 비텍스트 콘텐츠 처리용 도구로 자동 구성돼요.

이미지 다루기

멀티모달 에이전트에는 AddImageTool이 미리 구성돼 있어요. 이 도구 덕분에 이미지를 처리할 수 있는데, 멀티모달 기능을 켜면 자동으로 포함되므로 직접 추가할 필요가 없어요. 멀티모달 에이전트로 이미지를 분석하는 전체 예시를 볼게요.

from crewai import Agent, Task, Crew

# Create a multimodal agent
image_analyst = Agent(
    role="Product Analyst",
    goal="Analyze product images and provide detailed descriptions",
    backstory="Expert in visual product analysis with deep knowledge of design and features",
    multimodal=True
)

# Create a task for image analysis
task = Task(
    description="Analyze the product image at https://example.com/product.jpg and provide a detailed description",
    expected_output="A detailed description of the product image",
    agent=image_analyst
)

# Create and run the crew
crew = Crew(
    agents=[image_analyst],
    tasks=[task]
)

result = crew.kickoff()

컨텍스트를 활용한 고급 사용법

멀티모달 에이전트의 태스크를 만들 때 이미지에 대한 추가 컨텍스트나 구체적인 질문을 제공할 수 있어요. 태스크 설명에 에이전트가 집중해야 할 특정 측면을 명시할 수 있죠.

from crewai import Agent, Task, Crew

# Create a multimodal agent for detailed analysis
expert_analyst = Agent(
    role="Visual Quality Inspector",
    goal="Perform detailed quality analysis of product images",
    backstory="Senior quality control expert with expertise in visual inspection",
    multimodal=True  # AddImageTool is automatically included
)

# Create a task with specific analysis requirements
inspection_task = Task(
    description="""
    Analyze the product image at https://example.com/product.jpg with focus on:
    1. Quality of materials
    2. Manufacturing defects
    3. Compliance with standards
    Provide a detailed report highlighting any issues found.
    """,
    expected_output="A detailed report highlighting any issues found",
    agent=expert_analyst
)

# Create and run the crew
crew = Crew(
    agents=[expert_analyst],
    tasks=[inspection_task]
)

result = crew.kickoff()

도구 세부 사항

멀티모달 에이전트에서 AddImageTool은 다음 스키마로 자동 구성돼요.

class AddImageToolSchema:
    image_url: str  # Required: The URL or path of the image to process
    action: Optional[str] = None  # Optional: Additional context or specific questions about the image

멀티모달 에이전트는 내장 도구를 통해 이미지 처리를 자동으로 처리해서 다음과 같은 일을 할 수 있어요.

  • URL 또는 로컬 파일 경로를 통한 이미지 접근
  • 선택적 컨텍스트나 구체적인 질문과 함께 이미지 콘텐츠 처리
  • 시각 정보와 태스크 요구사항에 기반한 분석과 인사이트 제공

모범 사례

  1. 이미지 접근(Image Access)
    • 에이전트가 도달할 수 있는 URL로 이미지가 접근 가능한지 확인해요.
    • 로컬 이미지는 임시로 호스팅하거나 절대 파일 경로를 사용하는 걸 고려해요.
    • 태스크 실행 전에 이미지 URL이 유효하고 접근 가능한지 확인해요.
  2. 태스크 설명(Task Description)
    • 이미지의 어떤 측면을 분석하길 원하는지 구체적으로 명시해요.
    • 태스크 설명에 명확한 질문이나 요구사항을 포함해요.
    • 집중 분석을 위해 선택적 action 파라미터를 사용하는 것도 고려해요.
  3. 리소스 관리(Resource Management)
    • 이미지 처리는 텍스트 전용 태스크보다 더 많은 컴퓨팅 리소스가 필요할 수 있어요.
    • 일부 언어 모델은 이미지 데이터에 base64 인코딩이 필요할 수 있어요.
    • 성능 최적화를 위해 여러 이미지에 대해 배치 처리를 고려해요.
  4. 환경 설정(Environment Setup)
    • 이미지 처리에 필요한 의존성이 환경에 있는지 확인해요.
    • 언어 모델이 멀티모달 기능을 지원하는지 확인해요.
    • 설정을 검증하기 위해 먼저 작은 이미지로 테스트해요.
  5. 오류 처리(Error Handling)
    • 이미지 로딩 실패에 대한 적절한 오류 처리를 구현해요.
    • 이미지 처리가 실패할 때의 폴백 전략을 마련해요.
    • 디버깅을 위해 이미지 처리 작업을 모니터링하고 로그로 남겨요.

더 알아보기