AG2 시작하기 — 3분 만에 첫 에이전트
AG2 시작하기
AG2 는 3분이면 첫 에이전트 워크플로를 만들 수 있습니다. 환경을 준비하고 시를 짓는(리듬) AI 어시스턴트를 만들어 봅니다.
사전 준비
Python >= 3.10, < 3.14 를 권장합니다. 사용할 모델 제공자에 맞춰 패키지를 설치합니다.
pip install "ag2[openai]" # 또는 ag2[gemini], ag2[openai](Azure)
그리고 LLM API 키를 환경변수로 설정합니다.
export OPENAI_API_KEY="YOUR_API_KEY"
첫 에이전트 만들기
first_agent.py 를 만들고 다음처럼 작성합니다.
import os
from autogen import ConversableAgent, LLMConfig
llm_config = LLMConfig({"api_type": "openai", "model": "gpt-5-nano",
"api_key": os.environ["OPENAI_API_KEY"]})
my_agent = ConversableAgent(
name="helpful_agent",
system_message="You are a poetic AI assistant, respond in rhyme.",
llm_config=llm_config,
)
response = my_agent.run(message="In one sentence, what's the big deal about AI?", max_turns=3)
response.process()
run() 은 대화를 준비하고 process() 는 실행합니다. 이 두 단계 분리는 실행 전에 워크플로를 검토하거나 바꿀 여지를 줍니다.
실행
python first_agent.py
에이전트가 운율로 답한 뒤 당신의 응답을 기다립니다. 메시지를 치거나 엔터(빈 메시지) 또는 exit 로 끝낼 수 있습니다. 설치 없이 AG2 Playground 에서도 멀티에이전트 워크플로를 실습할 수 있습니다.