Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions .github/workflows/codex-python-pypy-qualify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Qualify PyPy native wheel

on:
push:
branches: [feat/codex-harness]
paths: [.github/workflows/codex-python-pypy-qualify.yml]
pull_request:
paths: [.github/workflows/codex-python-pypy-qualify.yml]
workflow_dispatch:

permissions:
contents: read

jobs:
pypy311-linux-x64:
if: >-
github.repository == 'openai/openai-agents-python' &&
(github.ref == 'refs/heads/feat/codex-harness' ||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository))
runs-on: ubuntu-24.04
timeout-minutes: 180
defaults:
run:
shell: bash
env:
RUSTUP_TOOLCHAIN: 1.95.0
MATURIN_PGO: 'false'
OPENAI_AGENTS_NATIVE_MANYLINUX: manylinux_2_39
PYTHONDONTWRITEBYTECODE: '1'
CARGO_BUILD_JOBS: '3'
CARGO_INCREMENTAL: '0'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97
with:
python-version: pypy3.11-v8.0.1
architecture: x64
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884
with:
version: '0.13.4'
enable-cache: false
- uses: ./.github/actions/setup-native
- name: Pin the build and consumer interpreter
run: |
python -I - <<'PYTHON'
import os
import platform
import sys
from pathlib import Path
assert platform.python_implementation() == 'PyPy'
assert sys.version_info[:3] == (3, 11, 17)
assert sys.implementation.version[:3] == (8, 0, 1)
assert platform.machine() == 'x86_64'
with open(os.environ['GITHUB_ENV'], 'a', encoding='utf-8') as output:
output.write(f'PYPY_EXECUTABLE={Path(sys.executable).resolve()}\n')
PYTHON
- name: Install pinned native build dependencies
run: |
uv venv --python "$PYPY_EXECUTABLE" .venv
"$PYPY_EXECUTABLE" -I - <<'PYTHON' > "$RUNNER_TEMP/pypy-build-requirements.txt"
import tomllib
from pathlib import Path
packages = tomllib.loads(Path('uv.lock').read_text())['package']
for name in ('maturin', 'hatchling'):
versions = {item['version'] for item in packages if item['name'] == name}
assert len(versions) == 1, (name, versions)
version, = versions
if name == 'maturin':
assert version == '1.16.0'
print(f'{name}=={version}')
print('patchelf==0.19.1')
PYTHON
uv pip install --python .venv/bin/python --requirement "$RUNNER_TEMP/pypy-build-requirements.txt"
printf '%s\n' "$GITHUB_WORKSPACE/.venv/bin" >> "$GITHUB_PATH"
- name: Build the release-profile SDK wheel
run: |
.venv/bin/python -I - <<'PYTHON'
import sys
assert sys.implementation.name == 'pypy'
assert sys.version_info[:3] == (3, 11, 17)
PYTHON
env -u OPENAI_AGENTS_NATIVE_WHEEL .venv/bin/python -m hatchling build --target wheel --directory "$GITHUB_WORKSPACE/dist"
.venv/bin/python -I - <<'PYTHON'
import hashlib
import json
from pathlib import Path
wheel, = Path('dist').glob('openai_agents-*-pp311-pypy311_pp80-manylinux_2_39_x86_64.whl')
receipt = json.loads(wheel.with_name(wheel.name + '.pristine.json').read_text())
assert receipt['native_build']['profile'] == 'release'
assert receipt['native_build']['pgo'] is False
with wheel.open('rb') as stream:
assert hashlib.file_digest(stream, 'sha256').hexdigest() == receipt['wheel_sha256']
PYTHON
- name: Verify an isolated PyPy installation with the existing public fixture
run: |
consumer="$RUNNER_TEMP/pypy-wheel-consumer"
uv venv --python "$PYPY_EXECUTABLE" "$consumer"
# PyPy needs the source distribution for rpds-py. The consumer uses
# wheel metadata requirements and records its independently resolved dependencies.
uv pip install --python "$consumer/bin/python" dist/*.whl
mkdir -p qualification
uv pip freeze --python "$consumer/bin/python" > qualification/installed-requirements.txt
"$consumer/bin/python" -I - <<'PYTHON'
import sys
assert sys.implementation.name == 'pypy'
assert sys.version_info[:3] == (3, 11, 17)
PYTHON
cd "$RUNNER_TEMP"
env -u PYTHONPATH -u OPENAI_AGENTS_NATIVE_WHEEL -u OPENAI_API_KEY \
-u ALL_PROXY -u HTTP_PROXY -u HTTPS_PROXY -u all_proxy -u http_proxy -u https_proxy \
"$consumer/bin/python" -I "$GITHUB_WORKSPACE/packages/codex/scripts/verify_installed.py" \
--output "$GITHUB_WORKSPACE/qualification/installed-pypy311.json"
- name: Retain separate qualification artifacts
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
with:
name: qualification-PyPy311-Linux-X64
path: |
dist/*.whl
dist/*.pristine.json
qualification/installed-pypy311.json
qualification/installed-requirements.txt
if-no-files-found: error
retention-days: 7
42 changes: 42 additions & 0 deletions packages/codex/src/_agents_codex/_model_provider_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,48 @@ def _capture_frame(encoded: str, event: Any) -> str:
del encoded, event, captured


def _anyllm_reasoning_text(value: Any, depth: int = 0) -> str:
text = part = parts = None
try:
if isinstance(value, str):
return value
if depth >= 32:
raise ValueError("AnyLLM reasoning exceeds the supported nesting depth")
if isinstance(value, dict):
for key in ("content", "text", "thinking"):
text = _anyllm_reasoning_text(value.get(key), depth + 1)
if text:
return text
if isinstance(value, (list, tuple)):
parts = []
for part in value:
parts.append(_anyllm_reasoning_text(part, depth + 1))
return "".join(parts)
return ""
finally:
del value, text, part, parts


def _normalize_anyllm_reasoning(message: dict[str, Any]) -> dict[str, Any]:
"""Normalize AnyLLM's plaintext wrappers before retaining private replay metadata."""
try:
reasoning = message.get("reasoning")
if isinstance(reasoning, str):
return message
if reasoning is None and (
message.get("reasoning_content") or message.get("thinking_blocks")
):
return message
if reasoning is None:
reasoning = message.get("thinking")
if reasoning is None:
return message
_encoded(reasoning)
return {**message, "reasoning": _anyllm_reasoning_text(reasoning)}
finally:
del message, reasoning


def _chat_reasoning(message: dict[str, Any]) -> dict[str, Any]:
value = blocks = block = None
try:
Expand Down
44 changes: 23 additions & 21 deletions packages/codex/src/_agents_codex/_trace_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ def _span_id(value: str | None) -> str | None:
return None if value is None else "span_" + value.rjust(24, "0")


def _span_data(event: Mapping[str, Any]) -> dict[str, Any]:
attributes = event["attributes"]
match attributes.get("sdk.span.kind"):
case "model":
response_id = attributes.get("sdk.response.id")
return {
"type": "response",
"response_id": response_id if isinstance(response_id, str) else None,
"usage": None,
}
case "guardrail":
return {
"type": "guardrail",
"name": event["name"],
"triggered": attributes.get("sdk.outcome.category") == "guardrail_triggered",
}
case _:
return {"type": "custom", "name": event["name"], "data": _plain(attributes)}


@_sdk_dataclass
class _TraceState:
descriptor: dict[str, Any]
Expand Down Expand Up @@ -69,8 +89,8 @@ class OpenAITraceExporter:
"""Export native lifecycle records to the OpenAI traces-ingest endpoint.

Pass an instance in configure(processors=[...]). Native flush barriers also
wait for these deliveries. Each completed native span becomes a custom
dashboard span with its native attributes, IDs and exact timestamps.
wait for these deliveries. Model response and guardrail spans use their dashboard types.
Other spans use the custom type. All records preserve native IDs and timestamps.
Install ``openai-agents[tracing]`` to use this HTTP exporter. Each delivery
awaits one client and its transport cleanup within the existing processor
worker loop. No client is shared across loops and no background queue or
Expand Down Expand Up @@ -318,25 +338,7 @@ async def on_trace_events(self, events: Sequence[Mapping[str, Any]]) -> None:
"parent_id": _span_id(event["parent_span_id"]),
"started_at": _timestamp(event["start_time_unix_nanos"]),
"ended_at": _timestamp(event["end_time_unix_nanos"]),
"span_data": (
{
"type": "response",
"response_id": event["attributes"].get(
"sdk.response.id"
)
if isinstance(
event["attributes"].get("sdk.response.id"), str
)
else None,
"usage": None,
}
if event["attributes"].get("sdk.span.kind") == "model"
else {
"type": "custom",
"name": event["name"],
"data": _plain(event["attributes"]),
}
),
"span_data": _span_data(event),
"error": {
"message": "Native span failed",
"data": {"outcome": event["outcome"]},
Expand Down
Loading
Loading