Files
openai--openai-agents-python/docs/ko/examples.md
T
2026-07-13 12:39:17 +08:00

136 lines
9.9 KiB
Markdown

---
search:
exclude: true
---
# 코드 예제
[리포지토리](https://github.com/openai/openai-agents-python/tree/main/examples)의 코드 예제 섹션에서 SDK의 다양한 샘플 구현을 확인해 보세요. 코드 예제는 다양한 패턴과 기능을 보여 주는 여러 카테고리로 구성되어 있습니다.
## 카테고리
- **[agent_patterns](https://github.com/openai/openai-agents-python/tree/main/examples/agent_patterns):** 이 카테고리의 코드 예제는 다음과 같은 일반적인 에이전트 설계 패턴을 보여 줍니다
- 결정론적 워크플로
- Agents as tools
- 스트리밍 이벤트를 사용하는 Agents as tools (`examples/agent_patterns/agents_as_tools_streaming.py`)
- 구조화된 입력 매개변수를 사용하는 Agents as tools (`examples/agent_patterns/agents_as_tools_structured.py`)
- 병렬 에이전트 실행
- 조건부 도구 사용
- 다양한 동작으로 도구 사용 강제 (`examples/agent_patterns/forcing_tool_use.py`)
- 입력/출력 가드레일
- 판정자로서의 LLM
- 라우팅
- 스트리밍 가드레일
- 도구 승인 및 상태 직렬화를 사용하는 휴먼인더루프 (HITL) (`examples/agent_patterns/human_in_the_loop.py`)
- 스트리밍을 사용하는 휴먼인더루프 (HITL) (`examples/agent_patterns/human_in_the_loop_stream.py`)
- 승인 흐름을 위한 사용자 정의 거부 메시지 (`examples/agent_patterns/human_in_the_loop_custom_rejection.py`)
- **[basic](https://github.com/openai/openai-agents-python/tree/main/examples/basic):** 이 코드 예제는 다음과 같은 SDK의 기본 기능을 보여 줍니다
- Hello world 코드 예제(기본 모델, GPT-5, 오픈 웨이트 모델)
- 에이전트 수명 주기 관리
- 실행 훅 및 에이전트 훅 수명 주기 코드 예제 (`examples/basic/lifecycle_example.py`)
- 동적 시스템 프롬프트
- 기본적인 도구 사용 (`examples/basic/tools.py`)
- 도구 입력/출력 가드레일 (`examples/basic/tool_guardrails.py`)
- 이미지 도구 출력 (`examples/basic/image_tool_output.py`)
- 스트리밍 출력(텍스트, 항목, 함수 호출 인수)
- 여러 턴에서 공유 세션 헬퍼를 사용하는 Responses WebSocket 전송 (`examples/basic/stream_ws.py`)
- 프롬프트 템플릿
- 파일 처리(로컬 및 원격, 이미지 및 PDF)
- 사용량 추적
- Runner가 관리하는 재시도 설정 (`examples/basic/retry.py`)
- 서드 파티 어댑터를 통해 Runner가 관리하는 재시도 (`examples/basic/retry_litellm.py`)
- 비엄격 출력 유형
- 이전 응답 ID 사용
- **[customer_service](https://github.com/openai/openai-agents-python/tree/main/examples/customer_service):** 항공사를 위한 고객 서비스 시스템 코드 예제입니다.
- **[financial_research_agent](https://github.com/openai/openai-agents-python/tree/main/examples/financial_research_agent):** 금융 데이터 분석을 위한 에이전트와 도구를 사용하여 구조화된 리서치 워크플로를 보여 주는 금융 리서치 에이전트입니다.
- **[handoffs](https://github.com/openai/openai-agents-python/tree/main/examples/handoffs):** 메시지 필터링을 사용하는 에이전트 핸드오프의 실용적인 코드 예제는 다음과 같습니다:
- 메시지 필터 코드 예제 (`examples/handoffs/message_filter.py`)
- 스트리밍을 사용하는 메시지 필터 (`examples/handoffs/message_filter_streaming.py`)
- **[hosted_mcp](https://github.com/openai/openai-agents-python/tree/main/examples/hosted_mcp):** OpenAI Responses API에서 호스티드 MCP(Model Context Protocol)를 사용하는 방법을 보여 주는 코드 예제는 다음과 같습니다:
- 승인이 없는 간단한 호스티드 MCP (`examples/hosted_mcp/simple.py`)
- Google Calendar와 같은 MCP 커넥터 (`examples/hosted_mcp/connectors.py`)
- 인터럽션(중단 처리) 기반 승인을 사용하는 휴먼인더루프 (HITL) (`examples/hosted_mcp/human_in_the_loop.py`)
- MCP 도구 호출을 위한 승인 시 콜백 (`examples/hosted_mcp/on_approval.py`)
- **[mcp](https://github.com/openai/openai-agents-python/tree/main/examples/mcp):** 다음을 포함하여 MCP(Model Context Protocol)로 에이전트를 구축하는 방법을 알아봅니다:
- 파일 시스템 코드 예제
- Git 코드 예제
- MCP 프롬프트 서버 코드 예제
- SSE(Server-Sent Events) 코드 예제
- SSE 원격 서버 연결 (`examples/mcp/sse_remote_example`)
- 스트리밍 가능한 HTTP 코드 예제
- 스트리밍 가능한 HTTP 원격 연결 (`examples/mcp/streamable_http_remote_example`)
- 스트리밍 가능한 HTTP를 위한 사용자 정의 HTTP 클라이언트 팩토리 (`examples/mcp/streamablehttp_custom_client_example`)
- `MCPUtil.get_all_function_tools`를 사용하여 모든 MCP 도구 미리 가져오기 (`examples/mcp/get_all_mcp_tools_example`)
- FastAPI와 함께 사용하는 MCPServerManager (`examples/mcp/manager_example`)
- MCP 도구 필터링 (`examples/mcp/tool_filter_example`)
- **[memory](https://github.com/openai/openai-agents-python/tree/main/examples/memory):** 에이전트를 위한 다양한 메모리 구현 코드 예제는 다음과 같습니다:
- SQLite 세션 저장소
- 고급 SQLite 세션 저장소
- Redis 세션 저장소
- SQLAlchemy 세션 저장소
- Dapr 상태 저장소 기반 세션 저장소
- 암호화된 세션 저장소
- OpenAI Conversations 세션 저장소
- Responses 압축 세션 저장소
- `ModelSettings(store=False)`를 사용하는 무상태 Responses 압축 (`examples/memory/compaction_session_stateless_example.py`)
- 파일 기반 세션 저장소 (`examples/memory/file_session.py`)
- 휴먼인더루프 (HITL)를 사용하는 파일 기반 세션 (`examples/memory/file_hitl_example.py`)
- 휴먼인더루프 (HITL)를 사용하는 SQLite 인메모리 세션 (`examples/memory/memory_session_hitl_example.py`)
- 휴먼인더루프 (HITL)를 사용하는 OpenAI Conversations 세션 (`examples/memory/openai_session_hitl_example.py`)
- 여러 세션에 걸친 HITL 승인/거부 시나리오 (`examples/memory/hitl_session_scenario.py`)
- **[model_providers](https://github.com/openai/openai-agents-python/tree/main/examples/model_providers):** 사용자 정의 제공업체와 서드 파티 어댑터를 포함하여 SDK에서 OpenAI 이외의 모델을 사용하는 방법을 살펴봅니다.
- **[realtime](https://github.com/openai/openai-agents-python/tree/main/examples/realtime):** SDK를 사용하여 실시간 경험을 구축하는 방법을 보여 주는 코드 예제는 다음과 같습니다:
- 구조화된 텍스트 및 이미지 메시지를 사용하는 웹 애플리케이션 패턴
- 명령줄 오디오 루프 및 재생 처리
- WebSocket을 통한 Twilio Media Streams 통합
- Realtime Calls API 연결 흐름을 사용하는 Twilio SIP 통합
- **[reasoning_content](https://github.com/openai/openai-agents-python/tree/main/examples/reasoning_content):** 추론 콘텐츠를 사용하는 방법을 보여 주는 코드 예제는 다음과 같습니다:
- Runner API에서 스트리밍 및 비스트리밍 방식으로 사용하는 추론 콘텐츠 (`examples/reasoning_content/runner_example.py`)
- OpenRouter를 통해 OSS 모델에서 사용하는 추론 콘텐츠 (`examples/reasoning_content/gpt_oss_stream.py`)
- 기본 추론 콘텐츠 코드 예제 (`examples/reasoning_content/main.py`)
- **[research_bot](https://github.com/openai/openai-agents-python/tree/main/examples/research_bot):** 복잡한 다중 에이전트 리서치 워크플로를 보여 주는 간단한 딥 리서치 클론입니다.
- **[sandbox](https://github.com/openai/openai-agents-python/tree/main/examples/sandbox):** 격리된 작업 공간에서 에이전트를 실행하는 코드 예제는 다음과 같습니다:
- 기본 샌드박스 에이전트 설정 (`examples/sandbox/basic.py`)
- Unix 로컬 및 Docker 샌드박스 수명 주기 코드 예제
- 샌드박스 기반 핸드오프 (`examples/sandbox/handoffs.py`)
- 샌드박스 메모리 및 스냅샷 재개 (`examples/sandbox/memory.py`)
- 도구로 노출된 샌드박스 에이전트 (`examples/sandbox/sandbox_agents_as_tools.py`)
- **[tools](https://github.com/openai/openai-agents-python/tree/main/examples/tools):** 다음과 같은 OpenAI 호스트하는 도구와 실험적 Codex 도구를 구현하는 방법을 알아봅니다:
- 웹 검색 및 필터를 사용하는 웹 검색
- 파일 검색
- Code interpreter
- 파일 편집 및 승인을 지원하는 패치 적용 도구 (`examples/tools/apply_patch.py`)
- 승인 콜백을 사용하는 셸 도구 실행 (`examples/tools/shell.py`)
- 휴먼인더루프 (HITL) 인터럽션(중단 처리) 기반 승인을 사용하는 셸 도구 (`examples/tools/shell_human_in_the_loop.py`)
- 인라인 스킬을 사용하는 호스티드 컨테이너 셸 (`examples/tools/container_shell_inline_skill.py`)
- 스킬 참조를 사용하는 호스티드 컨테이너 셸 (`examples/tools/container_shell_skill_reference.py`)
- 로컬 스킬을 사용하는 로컬 셸 (`examples/tools/local_shell_skill.py`)
- 네임스페이스 및 지연된 도구를 사용하는 도구 검색 (`examples/tools/tool_search.py`)
- 컴퓨터 사용
- 이미지 생성
- 실험적 Codex 도구 워크플로 (`examples/tools/codex.py`)
- 실험적 Codex 동일 스레드 워크플로 (`examples/tools/codex_same_thread.py`)
- **[voice](https://github.com/openai/openai-agents-python/tree/main/examples/voice):** 스트리밍 음성 코드 예제를 포함하여 TTS 및 STT 모델을 사용하는 음성 에이전트 코드 예제를 살펴봅니다.