-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: #636 Add human-in-the-loop (HITL) support to the SDK #2230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Michael James Schock <[email protected]>
|
I've finished the basic pattern testing, but there may still be some uncovered cases. If anyone is interested in trying this feature early using this git branch, your feedback would be greatly appreciated. |
There was a problem hiding this 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.
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review the whole changes |
There was a problem hiding this 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.
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This pull request resolves #636 by adding a Human-in-the-Loop (HITL) feature to the Python SDK, following a design similar to the TS SDK: https://openai.github.io/openai-agents-js/guides/human-in-the-loop/
Huge thanks to #2021, which served as the foundation for this PR.
Key changes include:
RunStateserialization and resume pipeline (RunResult.to_state/RunState.from_json), along with approval and rejection helpers, enablingRunner.runto pause for HITL decisions and resume interrupted runs.RunContextwhile preserving usage and turn metadata.previous_response_idandconversation_idtracking in sync for server-backed sessions.Examples
Handling interruptions
Streaming mode:
Enable HITL for function tools
Simplest example:
Passing function:
Enable HITL for hosted/local MCP server tools
Agents as tools
When you turn an agent into a tool for a different agent, you can set HITL to the sub agent run. Not only that, the HITL settings for the sub agent's tools are merged into the result.interruptions as well.
Shell tools
Realtime agents
When an approval is asked, your app will receive "tool_approval_required" events. Your app can display a confirmation popup etc. to the user.