feat(realtime): expose current_agent and context_wrapper on RealtimeSession#3720
Open
Skyline-9 wants to merge 2 commits into
Open
feat(realtime): expose current_agent and context_wrapper on RealtimeSession#3720Skyline-9 wants to merge 2 commits into
Skyline-9 wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two read-only public properties to
RealtimeSession:current_agentandcontext_wrapper.RealtimeSessionalready exposes a publicupdate_agent()setter and a publicmodelproperty, 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 privatesession._current_agentandsession._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 byupdate_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
modelproperty.Test plan
tests/realtime/test_session.py::TestSessionAccessorscovering:current_agentreturns the initial agent, reflects the value afterupdate_agent(...), andcontext_wrapperreturns the same object the session was constructed with.make format— passmake lint— passmake 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
.agents/skills/code-change-verification/scripts/run.shmake format,make lint,make typecheck, and the realtime test suite)/reviewbefore submitting this PRCompatibility 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.