Skip to content

Share typed Decisions across agents, callbacks and specialist handoffs - #6132

Merged
markstuart-oai merged 12 commits into
feat/simple-codexfrom
feat/decisions-handoff
Nov 24, 2026
Merged

markstuart-oai merged 12 commits into
feat/simple-codexfrom
feat/decisions-handoff

Conversation

@markstuart-oai

@markstuart-oai markstuart-oai commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An agent can ask Decisions a typed question before a run, from a callback or when choosing a specialist. Configure the provider once. Each question sends only its explicit input and answer schema.

from agents import Agent, OpenAIDecisions

async def needs_reply(text: str) -> bool:
    async with OpenAIDecisions() as provider:
        agent = Agent(name="Support", decisions=provider)
        return await agent.decide("Does this need a reply?", input=text)

The default answer is a boolean. Pass choices=[...] for a label or output_type=Ticket for a bounded, typed record. The same decide(...) method works on a function tool's context, a model input filter's data and a final output policy's proposal. Callback access ends when the callback returns. Both Agent and SandboxAgent accept the optional keyword-only decisions=. To use an existing client, pass OpenAIDecisions(client=client) and keep ownership of it.

For a specialist handoff, the primary model chooses when to transfer. Decisions chooses which eligible specialist receives the conversation.

from agents.decisions import decision_handoff

source.handoffs.append(decision_handoff(
    source,
    question="Which team can help?",
    targets={"billing": billing, "account": account},
))
  • Permissions. Each label needs its own specialist. Use is_available(ctx, label) to restrict access. The SDK checks permissions before selection, before transfer and on approval resume. Restore trusted state with fresh permissions through context_override. Resume rechecks every selected label still on the active path, including after an ordinary handoff or a history filter. It never repeats the decision.
  • Privacy. The model supplies up to 8,192 UTF-8 bytes of routing input, which can contain sensitive text. Decisions sees that input and 2–255 eligible labels. Use the handoff's input_filter to limit the history passed to the specialist.
  • Failures. Refusals and invalid answers raise DecisionError. The handoff has a 30-second default deadline and no automatic fallback. Cancellation waits for provider cleanup.
  • Usage. Decision requests and tokens are outside Runner usage and budgets. When tracing is enabled, a separate decision.usage span records available metadata without the question, input or answer. Missing usage stays unknown.

See the Decisions examples for a complete typed callback, an offline handoff comparison and approval resume.

Test plan

  • Ran the repository checks and the prospective release contract against the frozen baseline. All 159 Decisions tests passed on Linux with Python 3.10 and 3.12. Mypy and Pyright accepted the same provider for both agent types and rejected an incompatible value.
  • Ran both Runner modes with interrupted approvals, multiple handoffs, filtered history, revoked grants, a rebuilt agent graph, a return to the original agent and a same-name sibling. Checked 36 authorization cases with and without filtering. Retained permissions allowed exactly one effect. Revocation stopped the run before the effect.
  • Tested refusal, malformed probabilities, cancellation, cleanup and callback expiry. Ran both complete README examples offline, and checked imports with an older client. No live service calls.

Checks

  • Regression tests
  • Formatting, lint, mypy, Pyright and repository tests
  • Independent design and implementation review

@markstuart-oai
markstuart-oai requested review from a team, rm-openai and seratch as code owners November 21, 2026 06:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T19:26:54.928169Z 7a69e73 New commits
🔒 Security Review ✅ Completed 2026-11-24T19:28:28.111834Z 7a69e73 New commits

Security findings

Advisory findings (2)

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved at 5b20dab1473c40a88ad4cc4209cb6d1c66f84d3d after coordinator and independent static reviews.

Reviewed explicit-input snapshots, finite JSON/schema and typed result validation, refusal metadata, callback ownership and cancellation joins, route revocation, stable specialist identities, and fresh-permission checks during nested approval restoration. Reviewed the client adapter, examples, and failure/no-replay regression coverage; no actionable findings. The one-label OpenAI adapter limitation and serialized-state-only restore checks are explicitly documented.

Hosted CI is complete: 33 passed and 4 skipped; no failures. Static review only; no candidate code or local tests executed.

Hosted CI complete at c7fd0c1bbe42cc94e7ea3d86995fe095c2a29607: {"success": 33}. No pending or failed checks. Static review only; no local tests executed.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed current commit c35b8c4c46859c9bee387a33334cf5b88619a7a7, including changes since the prior approval and refreshed base. The OpenAIDecisions handoff now consistently requires 2–255 admitted labels at catalog construction and invocation. Checked boundary counts, revocation before provider invocation, post-await selected-route authority, custom-provider single-choice support, and serialized restore admission; no actionable regression found.

Hosted CI: {'SUCCESS': 10, 'IN_PROGRESS': 14}. Unfinished checks remain pending follow-up. Static review only; no candidate code or local tests executed.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: c35b8c4c46

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread src/agents/decisions.py Resolved

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request changes; this supersedes my earlier approval of c35b8c4c46859c9bee387a33334cf5b88619a7a7. I independently confirmed the malformed-routing-input case in the existing security finding, so I am not adding a duplicate inline comment.

With default model/tool-data redaction enabled, an invalid routing payload (for example a valid input plus a forbidden extra field) reaches _routing_input, which raises an unmarked ValueError while retaining raw arguments in its traceback frame. The directly registered invoke callback retains them too. The default handoff failure path rethrows, and the Runner only detaches errors marked as data-redacted. Exception reporters capturing frame locals can therefore retain the model-supplied routing evidence. The ordinary handoff parser instead uses the shared redaction-aware JSON validator and a payload-clearing boundary.

Apply that redaction contract to this SDK-owned routing validation path: honor the model/tool-data redaction settings, clear payload-bearing references and exception chains, and propagate a marked safe error through the handoff boundary. Add regression coverage inspecting traceback locals/chains for malformed input in both Runner modes. This decision is based on the concrete validation path; it does not assume that every arbitrary application/provider exception must be sanitized.

Hosted CI: {'SKIPPED': 4, 'SUCCESS': 19, 'IN_PROGRESS': 5}. Unfinished checks remain pending follow-up. Static review only; no candidate code or local tests executed.

Hosted CI follow-up (2026-11-22 22:15 UTC): current commit c35b8c4c46859c9bee387a33334cf5b88619a7a7 completed with 33 successful checks and 6 skipped checks. The redaction finding remains unresolved; request-changes stands. Static review only; no local tests executed.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed 5b058ba42a7c80ebab1704f9bbdf7def9ae3d28b after the native re-review request. The reported routing traceback gap is fixed. The invoke boundary now marks failures when either model/tool data logging is disabled and uses the shared boundary to detach traceback, cause and context while dropping payload-bearing argument references. The recovery path detaches marked traces before passing errors to the callback. Checked malformed-input, refusal and invalid-response paths, cancellation, selector identity, and the added matrix covering both Runner modes and logging/recovery combinations. No actionable findings remain from this review.

This approval supersedes my earlier request-changes decision. Provider exception messages and metadata remain application-controlled as documented; this fix addresses routing frames and exception chains. Hosted CI: {'SKIPPED': 2, 'SUCCESS': 14, 'IN_PROGRESS': 10}. Unfinished checks remain pending follow-up. Static review only; no candidate code or local tests executed.

Hosted CI follow-up (2026-11-22 22:55 UTC): 31 checks passed, 5 skipped, and the Python 3.10 ARM64 preview-wheel verification failed. The installed-wheel verifier’s --pause subprocess aborted with PyGILState_Release during interpreter finalization. Static inspection and independent review found the verifier and native shutdown path unchanged from the base; this scenario uses a plain agent without the new routing selector. There is no evidence attributing this crash to this PR, so the code approval remains. The exact cause and reproducibility are unconfirmed; this is not a claim that the failure is a flake. Failed CI remains tracked for follow-up. No candidate code or local tests executed.

Hosted CI follow-up (2026-11-22 23:05 UTC): the ARM64 Python 3.10 preview-wheel retry passed on the same commit. Current CI is terminal: 33 checks passed and 6 skipped, with no remaining failures or pending checks. The earlier shutdown crash did not recur in this retry; its root cause remains unconfirmed. No candidate code or local tests executed.

Update feat/decisions-handoff against feat/simple-codex.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved after static re-review of 786d56ba835e558e6422dac383c7efed7fe32227. Delegating decision providers can now await decide without inheriting an implicit owner-only scope. The private decision scope still owns and joins provider work, and the handoff rechecks authorization after the await. Explicit caller scopes retain their ownership requirement. Reviewed the changed behavior and base integration; independent review found no actionable issue.

Hosted CI at publication: {'SUCCESS': 9, 'IN_PROGRESS': 15}. Pending checks are tracked. No candidate code or tests were executed locally.

CI follow-up (November 23): all hosted checks at this reviewed commit have completed: 33 passed and 2 skipped, including all eight wheel verifiers. The pending CI follow-up above is resolved. No candidate code or local tests executed.

Update feat/decisions-handoff against feat/simple-codex.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved after static re-review of the refreshed commit and independent review. DecisionResult now rejects implicit truth testing with a clear TypeError directing callers to .value, preventing a False answer from being treated as a truthy wrapper. Checked current provider, validation and handoff consumers: they use explicit type/value/usage access, so the guard does not disrupt internal routing. Documentation and the false-predicate, scalar-choice and typed-result regression match the behavior.

Reviewed the refreshed feature integration, including specialist identity/admission restoration and the retained redaction boundary before recovery callbacks; no actionable regression found.

Hosted CI: 15 checks passed and nine remain running. No candidate code or local tests executed.

Hosted CI update (2026-11-23 22:41 UTC): all 33 executed checks passed and 2 were skipped at this reviewed commit. No local tests were run.

Update feat/decisions-handoff against feat/simple-codex.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed 4f0a50f against the previously reviewed revision, with an independent static review. The clone example isolates the handoff list and binds a new route to the clone. The expanded tests cover both Runner modes and preserve the source's route. No new actionable findings.

Hosted CI at the latest check: 17 successful, 7 in progress; completion remains pending. Static review only; no candidate code or local tests were executed.

Hosted CI follow-up (2026-11-24 03:32 UTC): all checks at this reviewed commit are complete: 33 passed and 2 skipped, with no failures. The pending CI follow-up is resolved. Static review only; no candidate code or local tests executed.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved after static re-review and an independent second review. The optional input_filter uses the standard Handoff field and Runner filtering path after authorized selection, including streaming and async filter handling. Routing evidence is correctly documented as already sent to the provider. Rejecting an OpenAIDecisions singleton at construction makes an unusable configuration explicit while preserving custom singleton providers and dynamic admission checks. Existing target identity/revocation checks remain intact. No actionable findings.

Hosted CI at review: 22 passed and 2 running, with no failures. Remaining checks require follow-up. Static review only; no candidate code or local tests executed.

Hosted CI follow-up (2026-11-24 06:07 UTC): 31 checks passed, 3 skipped, and the macOS ARM64 Python 3.14 wheel verifier failed (https://github.com/openai/openai-agents-python/actions/runs/45334803927/job/138253549230). Its parity suite reports 22 passed and one failure: test_worker_exit_joins_native_close observes an empty worker list. The test, native close implementation, and Python Codex provider are identical to the base. Static source/log review and an independent review indicate the known fast-completion observation race: a completed executor future can bypass the call_soon_threadsafe observer. This is an inference, not a reproduced run; no handoff regression was found. Approval remains, but CI is not green and follow-up stays open. No candidate code or local tests executed.

Hosted CI follow-up (2026-11-24 06:27 UTC): all checks at this reviewed commit are complete: 33 passed and 4 skipped, with no failures. The pending CI follow-up is resolved. Static review only; no candidate code or local tests executed.

…esume

Update feat/decisions-handoff against feat/simple-codex.
@markstuart-oai markstuart-oai changed the title feat: add typed Decisions and specialist handoffs Route specialist handoffs with the Decisions client Nov 24, 2026

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved after comprehensive static re-review and an independent review of the narrowed, still-unreleased Decisions handoff API and resume authorization changes. Reviewed caller-owned client lifetime, disabled transport retries, bounded explicit input, answer/usage validation, cancellation cleanup, post-request access checks, input filtering, and failure receipt preservation. Unique specialist routing identities and fresh-context checks cover in-memory, serialized, durable, and nested resumes before session claims or effects; new roots clear runtime bindings. Reviewed regression coverage for revoked grants and disabled/replaced/ambiguous agent tools. No actionable findings.

Hosted CI at review: {"SUCCESS":17,"IN_PROGRESS":7}. Pending checks remain under follow-up. Static review only; no candidate code or local tests executed.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CI follow-up changes my earlier approval to request changes for the feature-owned timeout tests. The Windows Python 3.10 hosted job reports 5 failed, 12,623 passed and 357 skipped: https://github.com/openai/openai-agents-python/actions/runs/45350653576/job/138295943686 . Static source/log inspection and an independent review agree that the tests assume the transport starts within a 10 ms total request deadline. These failures do not demonstrate a production cancellation or receipt regression, but the new tests need deterministic synchronization. At the latest check, 20 checks passed, 2 were skipped, 3 were running and this job failed. Remaining CI stays under follow-up. No candidate code or local tests were executed.

Hosted CI follow-up (2026-11-24 08:12 UTC): all checks at this reviewed commit are complete: 32 passed, 4 skipped and 1 failed. The Windows Python 3.10 failure is the timeout-test synchronization defect described above; the request for changes remains. No candidate code or local tests executed.

Comment thread tests/test_decisions.py Resolved

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved after static re-review and an independent review of the timeout-test fix. Tests now deterministically distinguish timeout before dispatch from timeout after mock transport entry. Real task cancellation and cleanup remain exercised, including a late answer after suppressed cancellation; completed tool receipts and no-specialist-transfer assertions remain intact in both Runner modes and approval-resume cases. Production code is unchanged. The prior timeout-test finding is addressed.

Hosted CI at review: {"SKIPPED":2,"SUCCESS":10,"IN_PROGRESS":14}. Pending checks remain under follow-up. No candidate code or local tests executed.

Hosted CI follow-up (2026-11-24 08:47 UTC): all checks at this reviewed commit are complete: 33 passed and 4 skipped, with no failures, including the Windows Python 3.10 check. The pending CI follow-up is resolved. No candidate code or local tests executed.

Update feat/decisions-handoff against feat/simple-codex.
@markstuart-oai markstuart-oai changed the title Route specialist handoffs with the Decisions client Share typed Decisions across agents, callbacks and specialist handoffs Nov 24, 2026

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request changes after comprehensive static review with independent schema/provider and lifecycle/resume reviews. The typed validation, explicit-input isolation, cancellation cleanup, provider inheritance and specialist authorization paths look consistent, but the new inherited Agent field needs two compatibility fixes below.

Hosted CI currently reports 6 passed, 3 skipped, 14 running and 1 failed. The prospective-release-contract failure is directly attributable to this field addition: https://github.com/openai/openai-agents-python/actions/runs/45456723931/job/138668058182 . Remaining checks stay under follow-up. No candidate code or local tests were executed.

Additional P2 authorization finding confirmed by coordinator and independent static review: preserve specialist grants across descendant handoffs. This corrects the earlier assessment of specialist authorization above. If gated specialist S ordinarily hands off to D and D pauses on a tool approval, _check_specialist sees saved target S != current D and no direct binding for D, then returns False without checking the original grant. Serialization gives D an ordinary identity and does not persist the originating grant; restore likewise computes binding=None. Revoking S therefore does not prevent D's already-approved effect on either in-memory or serialized resume. Preserve and revalidate the originating route/label across descendant checkpoints, or reject unsupported descendant checkpoints, before effects; cover both resume paths. I am referencing the existing finding rather than duplicating its inline comment. Request changes remains. No candidate code or local tests executed.

18:35 UTC hosted CI follow-up: all reported checks at this commit are terminal: 29 passed, 11 skipped and 1 failed. The remaining failure is the prospective-release-contract mismatch already covered by the first finding. Request changes remains for the compatibility, typing and descendant-grant issues above. No candidate code or local tests executed.

Comment thread src/agents/agent.py Resolved
Comment thread src/agents/agent.py Resolved

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

Copy link
Copy Markdown

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

ℹ️ 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".

Comment thread examples/decisions/README.md Resolved

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: f8e2f377fe

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread src/agents/run_state.py Resolved
Update feat/decisions-handoff against feat/simple-codex.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed the refreshed commit with an independent static review. The three blockers in my previous request-changes review are addressed: SandboxAgent preserves its released dataclass field prefix, its typed constructor accepts the keyword-only DecisionProvider, and accepted handoff paths retain and revalidate every active specialist grant before restore/resume effects, including ordinary descendants and pending agent tools. Checked identity reconstruction, filtered history, return-to-root/earlier-agent behavior, nested grant revocation, cancellation ownership, and integration with the updated model-selection base. Regression coverage exercises both Runner modes and serialized/in-memory resumes. No actionable findings remain from this review; this approval supersedes my previous request-changes decision.

Hosted CI currently has 10 successful checks, 8 skipped and 14 running, with no failures; the prospective release contract now passes. Remaining CI stays under follow-up. Static review only; no candidate code or local tests executed.

@markstuart-oai
markstuart-oai merged commit c132e75 into feat/simple-codex Nov 24, 2026
34 checks passed
@markstuart-oai
markstuart-oai deleted the feat/decisions-handoff branch November 24, 2026 19:40
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