agent_session: add SessionClosed event - #1705
Closed
u9g wants to merge 2 commits into
Closed
Conversation
The agent side of the session protocol can only emit observations and answer requests; it has no way to report that the call is over. A driver reading a closed session sees the agent go quiet, which is indistinguishable from it stalling or crashing, and on the room transport there is no EOF to fall back on - the byte-stream channel only closes locally. This matters for an agent that hangs up on its own, which is ordinary in telephony and increasingly common in voice agents that end a call after a farewell.
🦋 Changeset detectedLatest commit: 3ca621f The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Problem
The agent side of the session protocol can only emit observations (
AgentSessionEvent) and answer requests. It has no way to say the call is over.That leaves a driver unable to distinguish three states that look identical from outside:
There is no transport-level fallback for the room case either.
RoomSessionTransportiterates a channel that only closes when the local side closes it, so when the agent leaves the room the driver's channel simply goes quiet — no EOF. (TCP does surface EOF.) Detecting the hang-up means watching RTC participant events out of band, separately from the session protocol.The gap shows up concretely in text-driven simulations.
RunInputResponsecarries items or an error and nothing else, so a turn arriving after the agent hung up is reported as a failed request rather than as a call that ended.Change
Adds
AgentSessionEvent.SessionClosed, carrying aSessionCloseReasonthat mirrors theCloseReasonboth SDKs already have (livekit/agentsvoice/events.py,livekit/agents-jsvoice/events.ts), plus an optional error string for the error close.Additive: new enum, new nested message, new oneof field
24. No existing field changes.Note:
SC_TASK_COMPLETEDexists in the PythonCloseReasonbut not in the agents-js one — encoding the union here, but flagging it as an existing parity gap rather than something this PR resolves.Follow-ups
livekit/agentsandlivekit/agents-js: emit it from the session close path.