CAMEL-AI 핵심 기능 — ChatAgent와 에이전트 아키텍처

CAMEL-AI 핵심 기능

CAMEL-AI의 심장은 '에이전트'예요. 에이전트는 언어 모델과 상호작용하며 특정 과제를 수행하는 자율 주체로, 정의된 역할·기억·도구 사용 능력을 갖춰요. 핵심인 ChatAgent와 이를 둘러싼 아키텍처를 볼게요.

베이스 에이전트 아키텍처

모든 CAMEL 에이전트는 BaseAgent 추상 클래스를 상속해요. 그리고 두 필수 메서드를 정의해요.

메서드 목적 설명
reset() 상태 관리 에이전트를 초기 상태로 리셋
step() 과제 실행 에이전트 동작의 한 스텝 수행

ChatAgent

ChatAgent는 언어 모델과의 대화를 처리하는 주 구현체예요. 지원하는 기능:

  • 역할 정의를 위한 시스템 메시지 구성
  • 대화 이력 관리를 위한 메모리
  • 도구/함수 호출 능력
  • 응답 포맷팅과 구조화된 출력(structured output)
  • 스케줄링 전략과 함께하는 다중 모델 백엔드
  • 비동기(async) 동작 지원

기타 에이전트 타입

에이전트 용도
CriticAgent 응답·해결책 평가·검증
DeductiveReasonerAgent 논리 추론, 복잡한 문제 분해
EmbodiedAgent 물리 세계 맥락 이해·대응
KnowledgeGraphAgent 지식 그래프 구축·활용
MultiHopGeneratorAgent 다중 홉 추론, 중간 단계 생성
SearchAgent 정보 검색·탐색
TaskAgent 과제 분해·관리

기본 ChatAgent 사용

from camel.agents import ChatAgent

# 시스템 메시지로 에이전트 생성
agent = ChatAgent(system_message="You are a helpful assistant.")

# 대화 한 스텝 진행
response = agent.step("Hello, can you help me?")

모델 지정 방식 (6가지)

from camel.agents import ChatAgent
from camel.models import ModelFactory
from camel.types import ModelPlatformType, ModelType

# 1. 문자열만 (기본 플랫폼)
agent_1 = ChatAgent("You are a helpful assistant.", model="gpt-4o-mini")

# 2. ModelType enum (기본 플랫폼)
agent_2 = ChatAgent("You are a helpful assistant.", model=ModelType.GPT_4O_MINI)

# 3. (platform, model) 문자열 튜플
agent_3 = ChatAgent("You are a helpful assistant.", model=("openai", "gpt-4o-mini"))

# 4. enum 튜플
agent_4 = ChatAgent(
    "You are a helpful assistant.",
    model=(ModelPlatformType.ANTHROPIC, ModelType.CLAUDE_HAIKU_4_5),
)

# 5. 미지정 → 기본 플랫폼·모델
agent_5 = ChatAgent("You are a helpful assistant.")

# 6. ModelFactory로 미리 만든 모델
model = ModelFactory.create(
    model_platform=ModelPlatformType.OPENAI,
    model_type=ModelType.GPT_4O_MINI,
)
agent_6 = ChatAgent("You are a helpful assistant.", model=model)

도구 사용과 구조화 출력

from camel.agents import ChatAgent

# 도구 정의
def calculator(a: int, b: int) -> int:
    return a + b

# 도구를 가진 에이전트
agent = ChatAgent(tools=[calculator])
response = agent.step("What is 5 + 3?")

Pydantic 모델을 response_format으로 넘기면 JSON 형태의 구조화 출력을 강제할 수 있어요.

from pydantic import BaseModel, Field

class JokeResponse(BaseModel):
    joke: str = Field(description="A joke")
    funny_level: int = Field(description="Funny level, from 1 to 10")

agent = ChatAgent(model="gpt-4o-mini")
response = agent.step("Tell me a joke.", response_format=JokeResponse)
parsed_response = response.msgs[0].parsed
print(parsed_response.joke)

고급 기능

  • 모델 스케줄링: agent.add_model_scheduling_strategy("custom", custom_strategy) 로 스텝마다 쓸 모델 동적 선택
  • 출력 언어 제어: agent.set_output_language("Spanish") 로 대화 중 언어 전환

더 알아보기