Microsoft 에서 만든 Multi-Agent framework, AutoGen


Agent 사용법

응답 받기

on_messages() 함수를 이용해서 에이전트의 응답(response)을 받을 수 있다.

이때 응답은 response.inner_messagesresponse.chat_message 를 포함한다.

  • inner_messages 는 에이전트의 “thought process” 를 저장한다.
  • chat_message 는 에이전트의 최종 응답을 포함한다.

아래는 agent 의 on_messages() 호출 예시이다.

async def assistant_run() -> None:
    response = await agent.on_messages(
        [TextMessage(content="Find information on AutoGen", source="user")],
        cancellation_token=CancellationToken(),
    )
    print(response.inner_messages)
    print(response.chat_message)


# Use asyncio.run(assistant_run()) when running in a script.
await assistant_run()

cancellation_token 을 이용해서 언제 취소되는지 명시적으로 지정해주는걸 알 수 있다.

주의할 점은 이 on_messages() 함수는 agent의 inner state를 변경하므로, 동일한 메시지나 히스토리를 입력으로 사용하면 안된다는 점이다.

도구 호출

AgentChat에서 AssistantAgent는 웹 검색 도구와 같은 tool 을 사용하여 특정 작업을 수행할 수 있으며, 이러한 tool 은 Python 함수나 BaseTool의 하위 클래스로 구현될 수 있다.

agent = AssistantAgent(
    "assistant", tools=[tool], 
    model_client=model_client, 
    system_message="Use the `df` variable to access the dataset."
)

Multi-Agent (Team) 사용법

RoundRobinGroupChat 은 모든 에이전트가 동일한 맥락을 공유하고 돌아가면서 응답하는 간단하면서도 효과적인 팀 구성 방식이다. 각 에이전트는 자신의 차례가 되면 다른 모든 에이전트에게 응답을 방송하여 팀 전체가 일관된 맥락을 유지할 수 있도록 해준다.

2개의 에이전트로 시(poem)를 쓰는 팀을 만든다고 가정해보자. 한 에이전트는 시를 작성하고, 다른 하나는 작성된 시를 평가한다.

# Create the primary agent.
primary_agent = AssistantAgent(
    "primary",
    model_client=model_client,
    system_message="You are a helpful AI assistant.",
)

# Create the critic agent.
critic_agent = AssistantAgent(
    "critic",
    model_client=model_client,
    system_message="Provide constructive feedback. Respond with 'APPROVE' to when your feedbacks are addressed.",
)

# Define a termination condition that stops the task if the critic approves.
text_termination = TextMentionTermination("APPROVE")

# Create a team with the primary and critic agents.
team = RoundRobinGroupChat(
    [primary_agent, critic_agent], 
    termination_condition=text_termination
)

이렇게 되면 아래와 같이 APPROVE 라는 메시지가 나올때까지 둘이 핑퐁하며 시를 쓰게 된다.

---------- user ----------
Write a short poem about the fall season.
---------- primary ----------
Golden leaves in crisp air dance,  
---------- critic ----------
Your poem beautifully captures the essence of the fall season
...
---------- primary ----------
Thank you for your thoughtful feedback! I
...
---------- critic ----------
APPROVE
...
---------- Summary ----------
Number of messages: 5
Finish reason: Text 'APPROVE' mentioned
Total prompt tokens: 972
Total completion tokens: 455
Duration: 11.78 seconds

종료 조건

AutoGen 에서는 이런 Team 이 동작중일때 종료하는 것을 상당히 신경쓴것으로 보인다. 외부에서는 특정 함수 호출로 team 동작을 정지시키거나, 내부에서는 termination text(또는 token) 을 지정해줄 수 있다.

특히 지원되는 내부적 종료 조건이 상당히 많다.

  • MaxMessageTermination: 에이전트 및 작업 메시지를 포함하여 지정된 수의 메시지가 생성된 후 중지
  • TextMentionTermination: 메시지에서 특정 텍스트 또는 문자열이 언급될 때 중지
  • SourceMatchTermination: 특정 에이전트가 응답한 후 중지

이러한 컨디션들을 &| 로 조합해서 사용할 수 있다.

max_msg_termination = MaxMessageTermination(max_messages=10)
text_termination = TextMentionTermination("APPROVE")
combined_termination = max_msg_termination | text_termination

Solving GAIA Benchmark

Agent 성능을 테스트 위한 gaia벤치마크를 수행하기 위해서 Magentic-One 이라는 multi-agent 시스템을 사용한다.

magentic-one

Magentic-One 은 orchestrator 와 여러 에이전트로 구성되어 있으며, 이 중에서 에이전트는 각각 다른 역할을 수행한다.

  • Orchestrator: 작업 분해 및 계획 수립, 다른 에이전트 지시, 전체 진행 상황 추적 및 필요한 경우 수정 작업을 담당하는 주 에이전트.
  • Coder: 언어 모델을 기반으로 한 에이전트로, 코드 작성을 주로 진행하고, 다른 에이전트로부터 수집된 정보를 분석하여 새로운 콘텐츠 생성 등을 수행하도록 설계.
  • ComputerTerminal: Coder의 프로그램을 실행하고 새로운 프로그래밍 라이브러리를 설치할 수 있는 콘솔에 접근.

눈에 띄는 점은 코드 생성과 실행을 각 에이전트에서 따로 수행한다는 점이다.

Appendix

AgentChat 은 에이전트 내부의 이벤트를 나타내는 메시지 개념도 지원

  • 도구 호출 요청을 나타내는 ToolCallRequestEvent
  • 도구 호출 결과를 포함하는 ToolCallExecutionEvent

Reference




    Enjoy Reading This Article?

    Here are some more articles you might like to read next:

  • Deepseek-R1 모델
  • 학습할때 메모리가 터진다고? Cut Your Losses!
  • GRPO 대신 DAPO: RL 최적화로 LLM 추론 능력 끌어올리기
  • DeepSeek-V3 기술 요약
  • python accelerate 라이브러리 함수 조사기