AG2

AG2

AgentOps로 AG2(구 AutoGen) 에이전트를 추적하고 분석하는 방법을 소개해요. 설치, API 키 설정, 그리고 agentops.init() 한 번으로 모든 에이전트 상호작용이 자동 추적되는 방식까지 살펴볼게요.

출처: 문서

본문

AG2(구 AutoGen)는 멀티 에이전트 대화형 AI 시스템을 구축하는 프레임워크예요. AgentOps는 AG2를 위한 원활한 자동 계측을 제공합니다 — agentops.init()을 호출하기만 하면 모든 에이전트 상호작용이 추적됩니다.

설치 (Installation)

```bash pip theme={null} pip install agentops pyautogen ```
poetry add agentops pyautogen
uv pip install agentops pyautogen

API 키 설정 (Setting Up API Keys)

AG2를 AgentOps와 함께 사용하기 전에 API 키를 설정해야 해요. 다음을 얻을 수 있습니다.

그런 다음 환경 변수로 내보내거나 .env 파일에 설정할 수 있어요.

```bash Export to CLI theme={null} export OPENAI_API_KEY="your_openai_api_key_here" export AGENTOPS_API_KEY="your_agentops_api_key_here" ```
OPENAI_API_KEY="your_openai_api_key_here"
AGENTOPS_API_KEY="your_agentops_api_key_here"

그리고 Python 코드에서 환경 변수를 로드합니다.

from dotenv import load_dotenv
import os

# Load environment variables from .env file
load_dotenv()

# Set up environment variables with fallback values
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
os.environ["AGENTOPS_API_KEY"] = os.getenv("AGENTOPS_API_KEY")

사용법 (Usage)

애플리케이션 시작 시 AgentOps를 초기화하면 모든 AG2 에이전트 상호작용이 자동으로 추적됩니다.

```python Single Agent Conversation theme={null} import agentops import autogen import os

Initialize AgentOps

agentops.init()

Configure your AG2 agents

config_list = [ { "model": "gpt-4", "api_key": os.getenv("OPENAI_API_KEY"), } ]

llm_config = { "config_list": config_list, "timeout": 60, }

Create a single agent

assistant = autogen.AssistantAgent( name="assistant", llm_config=llm_config, system_message="You are a helpful AI assistant." )

user_proxy = autogen.UserProxyAgent( name="user_proxy", human_input_mode="TERMINATE", max_consecutive_auto_reply=10, is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), code_execution_config={"last_n_messages": 3, "work_dir": "coding"}, )

Initiate a conversation

user_proxy.initiate_chat( assistant, message="How can I implement a basic web scraper in Python?" )

</CodeGroup>

## 예제 (Examples)

<CardGroup cols={2}>
<Card title="AG2 Async Agent Chat" icon="notebook" href="/v2/examples/ag2">
  자동 응답이 포함된 AG2 비동기 에이전트 채팅
</Card>

<Card title="Async Human Input" icon="notebook" href="https://github.com/AgentOps-AI/agentops/blob/main/examples/ag2/ag2_async_agent.ipynb" newTab={true}>
  AG2 에이전트로 비동기 인간 입력을 보여줍니다.
</Card>

<Card title="Wikipedia Search Tool" icon="notebook" href="https://github.com/AgentOps-AI/agentops/blob/main/examples/ag2/tools_wikipedia_search.ipynb" newTab={true}>
  Wikipedia 검색 도구를 사용하는 AG2 에이전트 예제
</Card>

<Card title="Multi-Agent Group Chat" icon="notebook" href="https://github.com/AgentOps-AI/agentops/blob/main/examples/ag2/groupchat.py" newTab={true}>
  전체 AgentOps 트레이싱을 갖춘 특화 에이전트(리서처, 코더, 크리틱) 팀을 오케스트레이션합니다.
</Card>
</CardGroup>

## 리소스 (Resources)

<CardGroup cols={2}>
<Card title="AG2 - AgentOps Ecosystem Docs" icon="book" href="https://docs.ag2.ai/latest/docs/ecosystem/agentops/" newTab={true}>
  AgentOps와 통합하는 공식 AG2 문서
</Card>

<Card title="AG2 OpenTelemetry Tracing" icon="blog" href="https://docs.ag2.ai/latest/docs/blog/2026/02/08/AG2-OpenTelemetry-Tracing/" newTab={true}>
  AG2의 내장 트레이싱으로 멀티 에이전트 시스템의 완전한 관측성 확보
</Card>
</CardGroup>

## 더 알아보기 (Learn more)

- [AgentOps 공식 문서](https://docs.agentops.ai/v2/integrations/ag2)