Skip to content

Add OpenAI Agents SDK examples with CodexProvider - #24

Merged
ScriptedAlchemy merged 27 commits into
mainfrom
chore-ci-rust-pin-G9rgS
Nov 10, 2025
Merged

ScriptedAlchemy merged 27 commits into
mainfrom
chore-ci-rust-pin-G9rgS

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

This PR adds comprehensive examples demonstrating how to use CodexProvider with the OpenAI Agents framework.

New Examples Added

  • agents-handoffs.ts: Demonstrates agent handoffs and delegation between specialized agents
  • agents-guardrails.ts: Shows input/output guardrails and validation patterns
  • agents-structured-output.ts: JSON schema validation examples with Zod integration
  • agents-streaming.ts: Real-time streaming response examples
  • agents-multi-agent-workflow.ts: Complex multi-agent workflows (sequential, parallel, iterative)
  • agents-tracing.ts: Tracing and debugging examples with performance monitoring

Key Features

  • All examples use CodexProvider instead of API keys (as requested)
  • Examples follow OpenAI Agents SDK documentation patterns
  • Comprehensive documentation in each example file
  • Updated examples README.md with new examples

Testing

All examples have been tested and verified to work:

  • ✅ Handoffs example runs successfully
  • ✅ Streaming example works with model.getStreamedResponse()
  • ✅ Structured output configured via Agent outputType
  • ✅ Tracing example works with withTrace()
  • ✅ Multi-agent workflow demonstrates various patterns
  • ⚠️ Guardrails example runs but may need API refinement (output guardrails vs input)

Based on OpenAI Agents SDK documentation: https://openai.github.io/openai-agents-js/

@changeset-bot

changeset-bot Bot commented Nov 7, 2025 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f1efaf2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

ScriptedAlchemy added a commit that referenced this pull request Nov 8, 2025
- Remove duplicate [profile.test-cache] section in Cargo.toml
- Add assert_cmd to cargo-shear ignored list (legitimately used in test support crates)
- Apply formatting fixes to user_notification.rs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ScriptedAlchemy
ScriptedAlchemy force-pushed the chore-ci-rust-pin-G9rgS branch from e53c0de to c8b6f90 Compare November 9, 2025 07:16
0xRaduan and others added 2 commits November 9, 2025 08:37
…ations' (#6425)

The TypeScript SDK's README incorrectly claimed that runStreamed() emits
"file diffs". However, the FileChangeItem type only contains metadata
(path, kind, status) without actual diff content.

Updated line 36 to accurately describe the SDK as providing "file change
notifications" instead of "file diffs" to match the actual
implementation in items.ts.

Fixes #5850
Allow reading `hw.physicalcpu` so numpy can be imported when running in
the sandbox.
 
resolves #6420
@ScriptedAlchemy
ScriptedAlchemy force-pushed the chore-ci-rust-pin-G9rgS branch 3 times, most recently from 61d7f8a to fc25d8b Compare November 9, 2025 19:20
…ive build+tests; fix TUI ANSI test env\n\n- Expose minimal core APIs for native tools/interceptors\n- Integrate pending tool registrations into specs\n- Add exec callback runner for ThreadEvent streaming\n- Include sdk/native in pnpm workspace and CI\n- Re-enable TUI vt100 color checks in tests
@ScriptedAlchemy
ScriptedAlchemy force-pushed the chore-ci-rust-pin-G9rgS branch from df40a57 to f19d76c Compare November 9, 2025 21:31
codex-bot and others added 19 commits November 9, 2025 16:55
… stream event mapping

- Pretest runs  to ensure .node is present
- Jest config: TS-first via babel-jest; ESM-friendly
- CodexProvider: emit response_started first; forward raw_event correctly; include Responses-style deltas/completion
- Native loader: prefer env override; ensure local-first
- Add approval callback surface; tool interceptors
- Remove duplicate .mjs tests; keep TS tests only
- Update tests to use responses proxy helpers; stabilize assertions
Fixes session_id handling for completed exec commands by checking both
exit_code and has_exited() status before deciding whether to persist
session. Resolves test failure in exec_command_reports_chunk_and_exit_metadata.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Resolved conflicts by accepting ours for all codex-rs files and most
other files to preserve current branch changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…persist live sessions

core(registry): add upsert_spec_with_parallel_support for external tool overrides
core(tools/spec): remove duplicate create_function_tool_spec_from_schema and unify implementation
Add comprehensive NAPI concepts documentation including:
- Async functions and tasks
- Classes and enums
- Environment and exports
- External references
- Functions and objects
- Promises and threadsafe functions
- Typed arrays and values
- WebAssembly integration
- Naming conventions and lifetime management

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Remove sccache wrapper and related configuration to simplify CI builds
and improve reproducibility. The overhead of managing sccache cache
invalidation outweighs the benefits for this repository structure.

Changes:
- Remove RUSTC_WRAPPER=sccache from rust-ci.yml workflows
- Remove sccache npm scripts from root package.json
- Keep CARGO_INCREMENTAL=0 for reproducible builds

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The codespell GitHub Action expects a .codespellignore file to exist
when ignore_words_file is specified in the workflow. Add an empty file
to satisfy this requirement. Actual ignore configuration is handled
via .codespellrc.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Remove rustc-wrapper = "sccache" from cargo config to fix CI builds.
The SDK workflow was failing because cargo was trying to use sccache
as a compiler wrapper even though it wasn't installed.

This completes the sccache removal started in previous commits.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add rustfmt and clippy components to Rust toolchain installation in
SDK workflow. The native SDK build requires cargo fmt and cargo clippy
to be available.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add new event types to TypeScript SDK:
- RawEvent: Unstructured raw events for diagnostics
- TokenCountEvent: Token usage snapshots during turns
- TokenUsageEvent: Token usage at shutdown

These events are filtered out in Thread class to maintain
backward compatibility while allowing for future diagnostics.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Restore RUSTC_WRAPPER and SCCACHE_CACHE_SIZE environment variables
to match upstream (openai/codex) configuration for optimal CI
performance. This enables the existing sccache infrastructure.

Changes:
- Add RUSTC_WRAPPER=sccache to rust-ci.yml (lint_build + tests jobs)
- Add SCCACHE_CACHE_SIZE=10G to rust-ci.yml
- Add Rust dependency caching to sdk.yml workflow

This will provide ~30-50% faster CI builds on cache hits by caching
compiled objects, not just dependencies.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add full sccache configuration to SDK workflow to match rust-ci.yml:
- Set RUSTC_WRAPPER=sccache environment variable
- Install sccache@0.7.5 via taiki-e/install-action
- Configure sccache backend (GitHub Actions cache or local fallback)
- Add sccache cache restore/save steps
- Add sccache stats reporting

This provides compilation object caching for the cargo build steps
in addition to the existing Rust dependency caching, significantly
speeding up CI runs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
codex-bot and others added 5 commits November 10, 2025 00:16
Increase SDK workflow timeout from 10 to 30 minutes to accommodate
native SDK builds which require more time for Rust compilation.
Also restore missing RUSTC_WRAPPER and SCCACHE_CACHE_SIZE environment
variables that were accidentally removed.

The previous run timed out after 10m02s while still compiling.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove sdk- prefix from cache keys (sccache, cargo-home, cargo-target)
- Add rust-toolchain.toml hash to cargo-home cache keys
- Add cache-hit conditions to save steps to prevent redundant saves
- Add continue-on-error to cargo save operations
- Use runner.os for flexibility across runners

This enables cache sharing between sdk and rust-ci workflows when
they run on the same platform, reducing build times and cache storage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ScriptedAlchemy
ScriptedAlchemy merged commit 770ec2f into main Nov 10, 2025
24 checks passed
@ScriptedAlchemy
ScriptedAlchemy deleted the chore-ci-rust-pin-G9rgS branch November 10, 2025 09:06
ScriptedAlchemy added a commit that referenced this pull request Nov 10, 2025
* Fix SDK documentation: replace 'file diffs' with 'file change notifications' (#6425)

The TypeScript SDK's README incorrectly claimed that runStreamed() emits
"file diffs". However, the FileChangeItem type only contains metadata
(path, kind, status) without actual diff content.

Updated line 36 to accurately describe the SDK as providing "file change
notifications" instead of "file diffs" to match the actual
implementation in items.ts.

Fixes #5850

* fix(seatbelt): Allow reading hw.physicalcpu (#6421)

Allow reading `hw.physicalcpu` so numpy can be imported when running in
the sandbox.
 
resolves #6420

* feat(native): add sdk/native and minimal core/exec shims; CI runs native build+tests; fix TUI ANSI test env\n\n- Expose minimal core APIs for native tools/interceptors\n- Integrate pending tool registrations into specs\n- Add exec callback runner for ThreadEvent streaming\n- Include sdk/native in pnpm workspace and CI\n- Re-enable TUI vt100 color checks in tests

* sdk/native: always build N-API before Jest; unify TS test runner; fix stream event mapping

- Pretest runs  to ensure .node is present
- Jest config: TS-first via babel-jest; ESM-friendly
- CodexProvider: emit response_started first; forward raw_event correctly; include Responses-style deltas/completion
- Native loader: prefer env override; ensure local-first
- Add approval callback surface; tool interceptors
- Remove duplicate .mjs tests; keep TS tests only
- Update tests to use responses proxy helpers; stabilize assertions

* fix(core): clear session_id when exec command completes

Fixes session_id handling for completed exec commands by checking both
exit_code and has_exited() status before deciding whether to persist
session. Resolves test failure in exec_command_reports_chunk_and_exit_metadata.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* core(unified_exec): omit session_id for completed exec_command; only persist live sessions

core(registry): add upsert_spec_with_parallel_support for external tool overrides
core(tools/spec): remove duplicate create_function_tool_spec_from_schema and unify implementation

* chore: sync core tool registry and native sdk

* Restore native tool bridge and approvals

* docs: add NAPI concepts documentation

Add comprehensive NAPI concepts documentation including:
- Async functions and tasks
- Classes and enums
- Environment and exports
- External references
- Functions and objects
- Promises and threadsafe functions
- Typed arrays and values
- WebAssembly integration
- Naming conventions and lifetime management

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Prune generated artifacts and streamline CI

* Tighten native build flags

* chore: remove sccache configuration from CI and package scripts

Remove sccache wrapper and related configuration to simplify CI builds
and improve reproducibility. The overhead of managing sccache cache
invalidation outweighs the benefits for this repository structure.

Changes:
- Remove RUSTC_WRAPPER=sccache from rust-ci.yml workflows
- Remove sccache npm scripts from root package.json
- Keep CARGO_INCREMENTAL=0 for reproducible builds

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Remove sccache-specific tuning

* fix: add empty .codespellignore file for CI

The codespell GitHub Action expects a .codespellignore file to exist
when ignore_words_file is specified in the workflow. Add an empty file
to satisfy this requirement. Actual ignore configuration is handled
via .codespellrc.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: remove sccache from cargo config

Remove rustc-wrapper = "sccache" from cargo config to fix CI builds.
The SDK workflow was failing because cargo was trying to use sccache
as a compiler wrapper even though it wasn't installed.

This completes the sccache removal started in previous commits.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(ci): install rustfmt and clippy for SDK workflow

Add rustfmt and clippy components to Rust toolchain installation in
SDK workflow. The native SDK build requires cargo fmt and cargo clippy
to be available.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: recreate .codespellignore for CI

* feat(sdk): add token count and raw event types

Add new event types to TypeScript SDK:
- RawEvent: Unstructured raw events for diagnostics
- TokenCountEvent: Token usage snapshots during turns
- TokenUsageEvent: Token usage at shutdown

These events are filtered out in Thread class to maintain
backward compatibility while allowing for future diagnostics.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* chore(ci): restore sccache configuration to match upstream

Restore RUSTC_WRAPPER and SCCACHE_CACHE_SIZE environment variables
to match upstream (openai/codex) configuration for optimal CI
performance. This enables the existing sccache infrastructure.

Changes:
- Add RUSTC_WRAPPER=sccache to rust-ci.yml (lint_build + tests jobs)
- Add SCCACHE_CACHE_SIZE=10G to rust-ci.yml
- Add Rust dependency caching to sdk.yml workflow

This will provide ~30-50% faster CI builds on cache hits by caching
compiled objects, not just dependencies.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat(ci): add sccache to SDK workflow

Add full sccache configuration to SDK workflow to match rust-ci.yml:
- Set RUSTC_WRAPPER=sccache environment variable
- Install sccache@0.7.5 via taiki-e/install-action
- Configure sccache backend (GitHub Actions cache or local fallback)
- Add sccache cache restore/save steps
- Add sccache stats reporting

This provides compilation object caching for the cargo build steps
in addition to the existing Rust dependency caching, significantly
speeding up CI runs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* ci(sdk): remove sccache usage and increase timeout to 20m

* ci(sdk): align cargo cache with rust-ci (split home/target, restore/save)

* ci(sdk): increase timeout to 30 minutes

* fix(ci): increase SDK workflow timeout and restore sccache env vars

Increase SDK workflow timeout from 10 to 30 minutes to accommodate
native SDK builds which require more time for Rust compilation.
Also restore missing RUSTC_WRAPPER and SCCACHE_CACHE_SIZE environment
variables that were accidentally removed.

The previous run timed out after 10m02s while still compiling.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* ci(sdk): install and configure sccache like rust-ci; add restore/save + stats

* ci(sdk): align cache keys with rust-ci pattern for better cache sharing

- Remove sdk- prefix from cache keys (sccache, cargo-home, cargo-target)
- Add rust-toolchain.toml hash to cargo-home cache keys
- Add cache-hit conditions to save steps to prevent redundant saves
- Add continue-on-error to cargo save operations
- Use runner.os for flexibility across runners

This enables cache sharing between sdk and rust-ci workflows when
they run on the same platform, reducing build times and cache storage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Raduan A. <36044389+0xRaduan@users.noreply.github.com>
Co-authored-by: Oliver Mannion <125105+tekumara@users.noreply.github.com>
Co-authored-by: codex-bot <devnull@example.com>
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants