Skip to content

feat: Add comprehensive Python SDK examples (M4)#2644

Closed
localai-bot wants to merge 1 commit intoopenai:mainfrom
localai-bot:m4-sdk-examples-python-js
Closed

feat: Add comprehensive Python SDK examples (M4)#2644
localai-bot wants to merge 1 commit intoopenai:mainfrom
localai-bot:m4-sdk-examples-python-js

Conversation

@localai-bot
Copy link

See detailed description in commit message.

… 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.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@seratch
Copy link
Member

seratch commented Mar 10, 2026

Thanks for sharing this. Please feel free to have these examples in your own repo.

@seratch seratch closed this Mar 10, 2026
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.

2 participants