OpenAI Agents SDK는 가볍고 강력한 Python 멀티 에이전트 워크플로우 구축 프레임워크입니다. 이는 OpenAI에서 공식적으로 발표한 프로덕션 레벨 에이전트 개발 도구이며, 이전 실험적 프로젝트인 Swarm의 업그레이드 버전입니다. 이 프레임워크는 간결하지만 완벽한 기능을 갖추고 있으며, 복잡한 멀티 에이전트 AI 애플리케이션을 구축하는 데 특화되어 있습니다.
# Python 가상 환경 생성
python -m venv env
source env/bin/activate
# 기본 버전 설치
pip install openai-agents
# 음성 지원 버전 설치
pip install 'openai-agents[voice]'
from agents import Agent, Runner
agent = Agent(name="Assistant", instructions="You are a helpful assistant")
result = Runner.run_sync(agent, "Write a haiku about recursion in programming.")
print(result.final_output)
from agents import Agent, Runner
import asyncio
spanish_agent = Agent(
name="Spanish agent",
instructions="You only speak Spanish.",
)
english_agent = Agent(
name="English agent",
instructions="You only speak English",
)
triage_agent = Agent(
name="Triage agent",
instructions="Handoff to the appropriate agent based on the language of the request.",
handoffs=[spanish_agent, english_agent],
)
async def main():
result = await Runner.run(triage_agent, input="Hola, ¿cómo estás?")
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())
import asyncio
from agents import Agent, Runner, function_tool
@function_tool
def get_weather(city: str) -> str:
return f"The weather in {city} is sunny."
agent = Agent(
name="Weather Assistant",
instructions="You are a helpful weather agent.",
tools=[get_weather],
)
async def main():
result = await Runner.run(agent, input="What's the weather in Tokyo?")
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())
output_type
이 설정된 경우 LLM이 일치하는 유형의 콘텐츠를 반환할 때 종료output_type
이 없는 경우 에이전트가 도구 호출 또는 핸드오프가 없는 메시지를 생성할 때 종료OPENAI_API_KEY
환경 변수 설정 필요# uv 패키지 관리자 설치
uv --version
# 종속성 설치
make sync
# 테스트 실행
make tests
# 타입 검사
make mypy
# 코드 스타일 검사
make lint
OpenAI Agents Python은 복잡한 AI 협업을 쉽고 사용하기 쉽게 만들어주는 전문적인 멀티 에이전트 개발 프레임워크입니다. 핵심 에이전트, 핸드오프, 보호 및 추적 메커니즘을 통해 개발자는 강력한 AI 애플리케이션 시스템을 빠르게 구축할 수 있습니다. 간단한 단일 에이전트 작업이든 복잡한 멀티 에이전트 협업 시나리오이든 이 프레임워크는 우아한 솔루션을 제공합니다.