AutoGen

AutoGen Overview

  • AutoGen : 여러 Agent 사용해 LLM Application 제작을 돕는 프레임워크

Agent

Contents

Assistant Agent

from autogen import AssistantAgent, UserProxyAgent
 
llm_config = {"model": "gpt-4", "api_key": os.environ["OPENAI_API_KEY"]}
assistant = AssistantAgent("assistant", llm_config=llm_config)
user_proxy = UserProxyAgent("user_proxy", code_execution_config=False)
 
# Start the chat
user_proxy.initiate_chat(
    assistant,
    message="Tell me a joke.",
)

chat

ConversableAgent : 대화 가능한 Agent

import os
from autogen import ConversableAgent
 
cathy = ConversableAgent(
    "cathy",
    system_message="Your name is Cathy and you are a part of a duo of comedians.",
    llm_config={"config_list": [{"model": "gpt-4", "temperature": 0.9, "api_key": os.environ.get("OPENAI_API_KEY")}]},
    human_input_mode="NEVER",  # Never ask for human input.
)
 
joe = ConversableAgent(
    "joe",
    system_message="Your name is Joe and you are a part of a duo of comedians.",
    llm_config={"config_list": [{"model": "gpt-4", "temperature": 0.7, "api_key": os.environ.get("OPENAI_API_KEY")}]},
    human_input_mode="NEVER",  # Never ask for human input.
)
 
result = joe.initiate_chat(cathy, message="Cathy, tell me a joke.", max_turns=2)

conversation

Terminate Chat

  • Parameters Trigger
    • initiate_chat(max_turn) : 채팅 시작 시 종료 지점 설정할 수 있다.
  • Agent-Triggered Termination
    • max_consecutive_auto_reply : Agent가 응답하는 횟수를 세어 중단한다
    • is_termination_msg : 종료 메시지를 설정해줄 수 있다.

Human input mode

  • Never
    • Agent가 완전히 자동으로 작동하도록 할 때 유용하다.
    • 사람이 전혀 개입하지 않는다.
  • Always
    • 항상 사람의 명령에 따른다.
    • 빈칸으로 입력시 auto reply 작동한다.
  • Terminated
    • 종료 조건 충족될 때만 사람의 입력 요청된다.
    • Terminate 조건 충족 전까지는 auto reply로 진행되다가 충족 시에 사람의 입력 받는다.

Code Executor

Local Code Executor

LocalCodeExecutor | 550

  • Agent 실행 코드 - Message with code blocks
  • Agent가 Code Executor 사용해 [code file 생성 + 실행] 프로세스 실행한다.
  • 로컬에서 코드를 실행한다.

Docker Code Executor

DockerCodeExecutor | 550

  • 작동 방식은 같으나, 코드 실행 부분이 도커 컨테이너에서 실행된다.
  • Local의 방식은 보안적인 측면에서 좋지 않다고 명시되어 있다.

Group Chat

group chat

  • Group Chat Manager에 의해서 조율된다.
  • Agent B가 메시지 전달 Manager가 A, C, D에게 전달
  • 다음 Agent를 정하는 방법도 여러 방법으로 결정 가능(e.g. round_robin, random, manual, auto)

Reference