Environment:Openai Openai agents python Python 3 9 Runtime
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Python |
| Last Updated | 2026-02-11 14:00 GMT |
Overview
Python 3.9+ environment with the OpenAI Agents SDK core dependencies: openai, pydantic, griffe, typing-extensions, and requests.
Description
This environment provides the base runtime for the OpenAI Agents SDK. It requires Python 3.9 or higher and includes the core dependency set that enables agent definition, execution, streaming, guardrails, handoffs, and tracing. The SDK uses dataclass slots conditionally based on Python version (3.10+ gets slots for better memory). MCP support is only available on Python 3.10+.
Usage
Use this environment for any workflow involving the OpenAI Agents SDK. It is the mandatory prerequisite for all agent construction, runner invocation, tool execution, guardrail attachment, and result extraction operations.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Any (OS Independent) | Linux, macOS, Windows all supported |
| Python | >= 3.9 | Supports 3.9, 3.10, 3.11, 3.12, 3.13, 3.14 |
| Disk | Minimal | No large model downloads; SDK is lightweight |
Dependencies
System Packages
- No system-level packages required for the core SDK
Python Packages
- `openai` >= 2.9.0, < 3
- `pydantic` >= 2.12.3, < 3
- `griffe` >= 1.5.6, < 2
- `typing-extensions` >= 4.12.2, < 5
- `requests` >= 2.0, < 3
- `types-requests` >= 2.0, < 3
- `mcp` >= 1.19.0, < 2 (Python 3.10+ only)
Credentials
The following environment variables must be set:
- `OPENAI_API_KEY`: OpenAI API key for model invocation and tracing export. Can alternatively be passed programmatically via `set_api_key()`.
Quick Install
pip install openai-agents
Code Evidence
Python version compatibility from `pyproject.toml:6`:
requires-python = ">=3.9"
Dataclass slots conditional on Python version from `editor.py:12`:
_DATACLASS_KWARGS = {"slots": True} if sys.version_info >= (3, 10) else {}
MCP conditional on Python 3.10+ from `pyproject.toml:16`:
"mcp>=1.19.0, <2; python_version >= '3.10'",
Python 3.9 compatibility workaround from `realtime/openai_realtime.py:250-252`:
# Note: Avoid a module-level union alias for Python 3.9 compatibility.
# Using a union at runtime (e.g., A | B) in a type alias triggers evaluation
# during import on 3.9. We instead inline the union in annotations below.
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `ImportError: mcp` | MCP requires Python 3.10+ | Upgrade to Python 3.10 or higher |
| `RuntimeError: AgentRunner.run_sync() cannot be called when an event loop is already running` | Calling `run_sync()` from async context | Use `await Runner.run()` instead in async code |
| `OPENAI_API_KEY is not set, skipping trace export` | Missing API key | Set `OPENAI_API_KEY` env var or call `set_api_key()` |
Compatibility Notes
- Python 3.9: Fully supported but MCP features are unavailable. PEP 604 union syntax (`A | B`) cannot be used in type aliases at module level.
- Python 3.10+: Full feature support including MCP servers. Dataclass `slots=True` enabled for better memory efficiency.
- Python 3.11+: Native `ExceptionGroup` used; on 3.10 the `exceptiongroup` backport is imported.
Related Pages
- Implementation:Openai_Openai_agents_python_Agent_Constructor
- Implementation:Openai_Openai_agents_python_Runner_Run
- Implementation:Openai_Openai_agents_python_RunResult
- Implementation:Openai_Openai_agents_python_Function_Tool_Decorator
- Implementation:Openai_Openai_agents_python_Execute_Tools_And_Side_Effects