
최근 OpenAI는 실험적 프로젝트였던 Swarm의 뒤를 잇는 프로덕션 수준의 Agent SDK를 발표했습니다 🚀
Swarm을 통해 에이전트 기반 소프트웨어에 대한 가능성을 엿보았다면, 이번 SDK는 실제 제품에 사용할 수 있을 정도로 성숙해졌다고 볼 수 있어요.
https://datasciencebeehive.tistory.com/194
OpenAI의 멀티 에이전트 프레임워크, Swarm 🐝 소개
OpenAI가 새롭게 Swarm 🐝이라는 실험적인 프레임워크를 발표했어요! 이 프레임워크는 멀티 에이전트 시스템을 쉽게 개발할 수 있도록 지원하며, 교육용과 실험용 목적으로 설계되었답니다. 🎓
datasciencebeehive.tistory.com
이번 포스팅에서는 MacBook에서 OpenAI Agent SDK를 세팅하고, 두 가지 예제를 다뤄볼게요.
하나는 “Hello World” 수준의 간단한 예제이고, 다른 하나는 금융 서비스/알고리즘 트레이딩에 접목 가능한 구조예요! 💼📈
🤖 OpenAI Agent SDK란?
OpenAI Agent SDK는 아래 세 가지 개념을 중심으로 구성돼 있어요:
- 🧠 Agent – 프롬프트와 툴을 장착한 LLM 기반 에이전트
- 🤝 Handoff – 특정 작업을 다른 에이전트에게 위임
- 🛡️ Guardrail – 유효하지 않은 입력을 사전 필터링
Python과 이 기능들을 조합하면, 실제 서비스에 쓸 수 있는 똑똑한 에이전트 시스템을 만들 수 있어요!
게다가 tracing 기능도 내장되어 있어, 디버깅과 흐름 확인이 매우 쉬워요 👀
https://openai.github.io/openai-agents-python/
OpenAI Agents SDK
OpenAI Agents SDK The OpenAI Agents SDK enables you to build agentic AI apps in a lightweight, easy-to-use package with very few abstractions. It's a production-ready upgrade of our previous experimentation for agents, Swarm. The Agents SDK has a very smal
openai.github.io
🧰 MacBook에서 개발 환경 세팅하기
저는 pyenv와 venv를 사용해서 파이썬 가상환경을 설정했어요.
간단한 단계로 따라오세요 👇
1️⃣ Python 폴더/환경 만들기
mkdir agent-demo
python3 -m venv agent-demo
source agent-demo/bin/activate
2️⃣ 필요한 라이브러리 설치
(agent-demo) $ pip install openai-agents jupyter nest_asyncio
3️⃣ Jupyter Notebook 실행
(agent-demo) $ jupyter notebook
👋 예제 1: 엔비디아에 대해 묻기 – 주식 분석 어시스턴트 만들기
import os
os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY"
import nest_asyncio
nest_asyncio.apply()
from agents import Agent, Runner
# 📊 주식 분석 어시스턴트 에이전트 정의
agent = Agent(
name="Stock Assistant",
instructions=(
"You are a financial market expert specialized in stock analysis. "
"When asked about a stock, provide insights about its recent performance, valuation, earnings, and market sentiment. "
"Make sure your answers are informative and concise."
),
model="gpt-4o" # 명시적으로 모델 지정 가능
)
# 🎯 엔비디아에 대한 질문
question = "Can you give me a brief analysis of NVIDIA's recent stock performance and future outlook?"
result = Runner.run_sync(agent, question)
print(result.final_output)
📚 예제 2: 금융 서비스에 적용 – 주식시장 질문 라우팅 시스템 💹
이번에는 다양한 금융 질문을 분야별 에이전트에게 자동 분배하는 시스템을 만들어볼게요.
이 구조는 다음과 같이 응용할 수 있어요:
- 금융 고객 상담 챗봇 💬
- 투자 리서치 보조 도구 📑
- 자동화된 의사결정 시스템 🤖
import nest_asyncio
nest_asyncio.apply()
from agents import Agent, Runner
import asyncio
# 📈 에이전트 정의
stock_agent = Agent(
name="Stock Expert",
instructions="You are an expert in stock trading, including swing trades and fundamentals. Answer clearly and concisely."
)
etf_agent = Agent(
name="ETF Expert",
instructions="You are an ETF investing expert. Explain expense ratios, diversification, and portfolio strategies."
)
crypto_agent = Agent(
name="Crypto Expert",
instructions="You are a crypto market specialist. Provide up-to-date information about Bitcoin and altcoins."
)
macro_agent = Agent(
name="Macro Expert",
instructions="You are a macroeconomics expert. Explain inflation, interest rates, and central bank policies."
)
# 🔄 트리아지 에이전트
triage_agent = Agent(
name="Finance Triage Agent",
instructions=(
"If the question is about stocks, hand it off to the Stock Expert.\n"
"If it's about ETFs, hand it off to the ETF Expert.\n"
"If it's about crypto, hand it off to the Crypto Expert.\n"
"If it's about macroeconomics, hand it off to the Macro Expert.\n"
"If it doesn't match any, respond: 'I cannot answer that question.'"
),
handoffs=[stock_agent, etf_agent, crypto_agent, macro_agent],
)
# ▶️ 실행 함수
async def main():
question = "Is now a good time to buy QQQ or should I wait?"
result = await Runner.run(triage_agent, input=question)
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())
📌 출력 예시:
This is your ETF Expert. The answer to your question is as follows:
QQQ is a tech-heavy ETF tracking the Nasdaq-100. If the market shows bullish technical signals... (이하 생략)
🧾 요약 ✨
OpenAI의 Agent SDK는 매우 강력하면서도 직관적인 프레임워크예요.
🎯 핵심 개념 정리:
- Agent: 역할을 정의한 AI
- Handoff: 역할 분담
- Guardrail: 안전장치
💡 금융 서비스에 이런 식으로 활용해보세요:
- 📊 투자 상담 챗봇
- 🧠 AI 기반 트레이딩 어시스턴트
- 🏦 자산 포트폴리오 추천 시스템
🤔 여러분의 아이디어는?
이 SDK를 활용해서 어떤 금융 서비스를 만들어보고 싶으신가요?
궁금하거나 공유하고 싶은 아이디어가 있다면 댓글로 알려주세요! 👇💬
📚 공식 문서 보기
'AI 공부 > AI Agents' 카테고리의 다른 글
AI 에이전트 시리즈 5 - 🧠 Goal-Based Agent란? 📊 Goal-Based 트레이딩 에이전트 만들기 (파이썬 예제 포함) (0) | 2025.03.25 |
---|---|
AI 에이전트 시리즈4 - Model-Based Reflex Agent란? 그리고 금융 서비스에서의 활용법 (0) | 2025.03.24 |
AI 에이전트 시리즈 - 3. AI Agentic Frameworks(AI 에이전트 프레임워크) (2) | 2025.03.21 |
AI 에이전트 시리즈 - 2. AI 에이전트란 무엇인가? 금융 서비스와 알고리즘 트레이딩에 적용하기 (1) | 2025.03.20 |
[AI 에이전트] 언제 AI 에이전트를 사용하고 ❌ 언제 피해야 할까? 금융 서비스 예제로 깊이 파헤치기 🏦💡 (3) | 2025.03.20 |