Skip to content

feat(realtime): expose current_agent and context_wrapper on RealtimeSession#3720

Closed
Skyline-9 wants to merge 2 commits into
openai:mainfrom
Skyline-9:feat/realtime-current-agent-accessor
Closed

feat(realtime): expose current_agent and context_wrapper on RealtimeSession#3720
Skyline-9 wants to merge 2 commits into
openai:mainfrom
Skyline-9:feat/realtime-current-agent-accessor

Conversation

@Skyline-9

Copy link
Copy Markdown

Summary

Adds two read-only public properties to RealtimeSession: current_agent and context_wrapper.

RealtimeSession already exposes a public update_agent() setter and a public model property, but there is no public way to read which agent is currently active or to reach the run-context wrapper. Application code that runs outside the session's event loop (telemetry, per-agent metrics, routing decisions, background timers) currently has to read the private session._current_agent and session._context_wrapper, which couples user code to SDK internals.

This change makes those two reads first-class and additive:

  • RealtimeSession.current_agent -> RealtimeAgent: the agent currently handling the session (the value set at construction and updated by update_agent() and by handoffs).
  • RealtimeSession.context_wrapper -> RunContextWrapper[Any]: the run-context wrapper backing the session.

Both are read-only (no setters), typed consistently with existing internal usage, and documented as live, unsynchronized snapshots (a background reader can observe the value mid-handoff), matching the style of the existing model property.

Test plan

  • Added tests/realtime/test_session.py::TestSessionAccessors covering: current_agent returns the initial agent, reflects the value after update_agent(...), and context_wrapper returns the same object the session was constructed with.
  • Ran the standard verification stack from the repo root:
    • make format — pass
    • make lint — pass
    • make typecheck — pass (pyright + mypy)
    • uv run pytest -k realtime — pass (303 passed, 1 skipped)

Issue number

N/A (small additive ergonomics improvement). Happy to link a tracking issue if preferred.

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass (ran make format, make lint, make typecheck, and the realtime test suite)
  • If using Codex, I've run /review before submitting this PR

Compatibility notes

Purely additive. No new exported top-level symbols (properties on an existing class), no changes to constructor signatures or field order, and no behavior change to existing methods.

@seratch

seratch commented Jul 2, 2026

Copy link
Copy Markdown
Member

Thanks for sharing this. The proposed properties are technically straightforward, but the PR does not demonstrate a concrete supported use case that cannot already be handled through the realtime event stream or callbacks. Handoff, tool, and agent lifecycle events already carry the relevant agent, and session events expose the run context via RealtimeEventInfo.

I am going to close this for now rather than add a new public contract for live, unsynchronized session state and direct RunContextWrapper access.

@seratch seratch closed this Jul 2, 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