OpenAI Agents SDK

OpenAI Agents SDK

OpenAI Agents SDK를 LiteLLM Proxy를 통해 어떤 LLM 프로바이더와도 함께 사용할 수 있어요.

출처: 문서

본문

OpenAI Agents SDK는 멀티 에이전트 워크플로를 구축하기 위한 가벼운 프레임워크예요. 공식 LiteLLM 확장 기능을 포함하고 있어 100개 이상의 지원 프로바이더를 사용할 수 있어요.

빠른 시작 (Quick Start)

1. 의존성 설치 (Install Dependencies)

uv add "openai-agents[litellm]"

2. Config에 모델 추가 (Add Model to Config)

config.yaml

model_list:
  - model_name: gpt-5.6-terra
    litellm_params:
      model: "openai/gpt-5.6-terra"
      api_key: "os.environ/OPENAI_API_KEY"
  - model_name: claude-sonnet
    litellm_params:
      model: "anthropic/claude-sonnet-5"
      api_key: "os.environ/ANTHROPIC_API_KEY"
  - model_name: gemini-3.1-pro-preview
    litellm_params:
      model: "gemini/gemini-3.1-pro-preview"
      api_key: "os.environ/GEMINI_API_KEY"

3. LiteLLM Proxy 시작 (Start LiteLLM Proxy)

litellm --config config.yaml

4. Proxy와 함께 사용 (Use with Proxy)

Via Proxy (Proxy 경유)

from agents import Agent, Runner
from agents.extensions.models.litellm_model import LitellmModel

# Point to LiteLLM proxy
agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    model=LitellmModel(
        model="claude-sonnet",  # Model from config.yaml
        api_key="sk-<your-litellm-api-key>",      # LiteLLM API key
        base_url="http://localhost:4000"
    )
)
result = await Runner.run(agent, "What is LiteLLM?")
print(result.final_output)

Direct (Proxy 없이 직접)

from agents import Agent, Runner
from agents.extensions.models.litellm_model import LitellmModel

# Use any provider directly
agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    model=LitellmModel(
        model="anthropic/claude-sonnet-5",
        api_key="your-anthropic-key"
    )
)
result = await Runner.run(agent, "What is LiteLLM?")
print(result.final_output)

사용량 추적 (Track Usage)

토큰 소비를 모니터링하려면 사용량 추적을 활성화해요:

from agents import Agent, ModelSettings
from agents.extensions.models.litellm_model import LitellmModel

agent = Agent(
    name="Assistant",
    model=LitellmModel(model="claude-sonnet", api_key="sk-<your-litellm-api-key>"),
    model_settings=ModelSettings(include_usage=True)
)
result = await Runner.run(agent, "Hello")
print(result.context_wrapper.usage)  # Token counts

환경 변수 (Environment Variables)

변수 설명
LITELLM_BASE_URL http://localhost:4000 LiteLLM 프록시 URL
LITELLM_API_KEY sk- LiteLLM API 키

더 알아보기 (Learn more)