Skip to content

feat(sdk): Add comprehensive OpenAI Agents SDK examples - #25

Merged
ScriptedAlchemy merged 23 commits into
mainfrom
feat/add-openai-agents-examples
Nov 8, 2025
Merged

ScriptedAlchemy merged 23 commits into
mainfrom
feat/add-openai-agents-examples

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Overview

This PR adds 6 comprehensive example files demonstrating integration of the OpenAI Agents SDK with CodexProvider, along with extensive documentation.

New Examples

1. Multi-Agent Handoffs ()

  • Specialized agents for different tasks (CodeReviewer, TestWriter, DocumentationWriter)
  • Triage agent for intelligent request routing
  • Agent-to-agent handoffs and delegation
  • Collaborative multi-step workflows
  • Context preservation across handoffs

2. Structured Output ()

  • JSON schema validation with Zod
  • Type-safe responses with full TypeScript support
  • Code analysis with structured metrics
  • Test plan generation
  • API documentation generation
  • Performance analysis with complexity metrics

3. Streaming Responses ()

  • Real-time text streaming with incremental updates
  • Progress tracking during generation
  • Reasoning output streams
  • Multi-stage workflows
  • Parallel agent streaming

4. Context & Sessions ()

  • Multi-turn conversations with memory
  • Managing multiple concurrent sessions
  • Long-running conversation context
  • Context-aware agent collaboration
  • Session resumption and continuity

5. Guardrails & Validation ()

  • Input validation and filtering
  • Output validation for sensitive data
  • Rate limiting and abuse prevention
  • Content policy enforcement
  • Layered security guardrails

6. Real-World Code Refactor ()

  • Production-ready refactoring pipeline
  • Multi-agent workflow coordination
  • Code analysis → refactoring → testing → documentation
  • Batch file processing
  • Complete error handling

Documentation

  • EXAMPLES_GUIDE.md (450+ lines): Comprehensive guide with learning paths, common patterns, best practices, and troubleshooting
  • Updated examples/README.md: Full descriptions and running instructions for all examples

Features Demonstrated

✅ CodexProvider integration with OpenAI Agents SDK
✅ Multi-agent orchestration and handoffs
✅ Structured output with JSON schemas
✅ Real-time streaming responses
✅ Context management and sessions
✅ Security guardrails and validation
✅ Production-ready patterns

Based On

All examples demonstrate features from the OpenAI Agents SDK documentation, adapted to use CodexProvider as the model backend instead of API key-based solutions.

Testing

  • ✅ All examples tested with pnpm install && pnpm build
  • ✅ Zero linter errors
  • ✅ All examples run without crashes
  • ✅ TypeScript compilation successful

Stats

  • 2,768 lines added across 8 files
  • 6 new example files
  • 1 comprehensive guide
  • Updated documentation

Known Limitations

The examples use temporary empty directories for isolation, which causes Codex to sometimes give generic responses or refuse code-related work. This is expected behavior when working without actual project files. Future improvements could adapt examples to work with the SDK's own codebase or add sample files to temp directories.

Learning Path

  1. Beginners: Start with agents-integration.ts → structured-output.ts
  2. Multi-Agent Systems: context-sessions.ts → multi-agent-handoffs.ts → real-world-code-refactor.ts
  3. Production Systems: guardrails-validation.ts → real-world-code-refactor.ts

See EXAMPLES_GUIDE.md for detailed learning paths and best practices.

Add 6 new example files demonstrating OpenAI Agents SDK integration with CodexProvider:

- multi-agent-handoffs.ts: Multi-agent workflows with specialized agents, triage routing, and collaborative workflows
- structured-output.ts: JSON schema validation with Zod for type-safe responses, code analysis, test planning, and API documentation
- streaming-responses.ts: Real-time streaming with progress tracking, reasoning output, and parallel agent streaming
- context-sessions.ts: Multi-turn conversations, session management, and context preservation
- guardrails-validation.ts: Safety guardrails including input/output validation, rate limiting, and content policies
- real-world-code-refactor.ts: Production-ready refactoring pipeline with multi-agent coordination

Also includes:
- EXAMPLES_GUIDE.md: Comprehensive 450+ line guide covering all examples, learning paths, and best practices
- Updated examples/README.md with detailed descriptions of all new examples

All examples demonstrate:
- CodexProvider integration with OpenAI Agents SDK
- Production-ready patterns and error handling
- Features from https://openai.github.io/openai-agents-js/
- Type-safe structured output with Zod schemas
- Multi-agent orchestration and handoffs
- Security and validation patterns

Tested with pnpm install && pnpm build - all examples run successfully.
@changeset-bot

changeset-bot Bot commented Nov 7, 2025 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2aa4f71

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 and others added 22 commits November 6, 2025 18:19
Switch reqwest to use rustls-tls explicitly, improve error handling in HTTP client initialization, and remove package-lock.json files for regeneration.

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

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Resolved conflicts by taking main versions.

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove unused mut from build_client closure
- Replace .expect() with explicit panic for better error handling
- Simplify is_visible logic to satisfy needless_bool lint

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

Co-Authored-By: Claude <noreply@anthropic.com>
Fixed formatting issues in:
- login/tests/suite/login_server_e2e.rs
- rmcp-client/src/rmcp_client.rs
- tui/src/slash_command.rs

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

Co-Authored-By: Claude <noreply@anthropic.com>
Windows tests were failing because reqwest was using both default TLS and rustls-tls.
Disabling default features ensures only rustls-tls is used.

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Add direct handling for input_file and input_audio types to throw errors as expected
- Add direct handling for input_image type at top level
- Change output_text_done event to be emitted directly instead of wrapped in model type
- Use type assertions to work around TypeScript union type limitations

This fixes test failures where:
1. Tests expect input_file/input_audio to throw errors
2. Tests expect output_text_done event type, not model wrapper

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

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ScriptedAlchemy
ScriptedAlchemy merged commit 87f431c into main Nov 8, 2025
3 checks passed
@ScriptedAlchemy
ScriptedAlchemy deleted the feat/add-openai-agents-examples branch November 8, 2025 06:11
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.

1 participant