feat: Add comprehensive Python SDK examples (M4)#2644
feat: Add comprehensive Python SDK examples (M4)#2644localai-bot wants to merge 1 commit intoopenai:mainfrom
Conversation
… Python SDK examples covering:\n- Basic agent creation and usage\n- Agent handoffs and delegation\n- Custom tool creation\n- Input/output guards\n- Structured output with Pydantic\n- Streaming responses\n- Async/await patterns\n- Error handling patterns\n- Real-world integration example\n\nThese examples provide copy-paste ready code for developers getting started with the openai-agents-python SDK.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 24c3c05b31
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| async def example_handoff_callback() -> None: | ||
| """Execute a callback function when a handoff occurs.""" | ||
|
|
||
| async def on_billing_handoff(ctx: object, input_data: None) -> None: |
There was a problem hiding this comment.
Use valid on_handoff callback signature
This callback is declared with two positional parameters, but handoff(..., on_handoff=...) without an input_type requires a single-argument function (context) and validates arity at construction time. As written, creating main_agent will raise a UserError before any run starts, so Example 5 cannot execute.
Useful? React with 👍 / 👎.
| timeout=30.0, | ||
| ) | ||
| print(f"[Timeout] Completed: {result.final_output}") | ||
| except TimeoutError: |
There was a problem hiding this comment.
Catch asyncio timeout exception type
asyncio.wait_for raises asyncio.TimeoutError, but this handler catches built-in TimeoutError. In the repo’s supported Python 3.10 runtime, those are different exception types, so a real timeout will bypass this except block and terminate the example instead of printing the intended timeout message.
Useful? React with 👍 / 👎.
|
Thanks for sharing this. Please feel free to have these examples in your own repo. |
See detailed description in commit message.